How do I find files and directories not owned by a given user?
I have a set of files within a directory owned by 'alfred'. From a quick inspection, most of the files within are also owned by 'alfred'.
I'd like to change ownership of the folder and everything owned by 'alfred' to be owned by 'betty'. However, it might be possible that 'alfred' has files within this directory that he's determined should be owned by a different user. For example, there might be a script that won't execute unless it's owned by 'root', or a directory that's symlinked to an area owned by 'chris', so that things inside need to be owned by 'chris'.
How can I find all files and folders with the top directory that are owned by a user other than 'alfred'?
This question is similar, but the answers given only cover the case of things not owned by the current user. I want to find things not owned by any specified user.
Solution 1:
To find files owned by other accounts, find . \! -user alfred
. The exclamation mark means "not", and it has to be escaped by a backslash or singe quotes to avoid interpretation by the shell.
Or, to change ownership of alfred's files, find . -user alfred -exec chown betty '{}' +
.