Looking for files NOT owned by a specific user

LinuxFileShellSearch

Linux Problem Overview


I'm looking to recursively look through directories to find files NOT owned by a particular user and I am not sure how to write this.

Linux Solutions


Solution 1 - Linux

The find(1) utility has primaries that can be negated ("reversed") using the "!" operator. On the prompt one must however escape the negation with a backslash as it is a shell metacharacter. Result:

find . \! -user foo -print

Solution 2 - Linux

> Looking for files NOT owned by someone

Others have answered the question "NOT owned by a particular user" in the body. Here's one that answers the titular question but has not been provided:

$ find / -nouser

You can use it like so:

$ sudo find /var/www -nouser -exec chown root:apache {} \;

And a related one:

$ find / -nogroup

Solution 3 - Linux

-user finds by user or user ID, and ! inverts the predicate. So, ! -user ....

Solution 4 - Linux

You can use this:

find <dir> ! -user <username> 

Solution 5 - Linux

Using z-shell (zsh) you can use

ls -laR *(^U)

or

ls -la **/*(^U)

to search for all files recursively not owned by you.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmike628View Question on Stackoverflow
Solution 1 - LinuxMelView Answer on Stackoverflow
Solution 2 - LinuxjwwView Answer on Stackoverflow
Solution 3 - LinuxIgnacio Vazquez-AbramsView Answer on Stackoverflow
Solution 4 - LinuxCrayon ViolentView Answer on Stackoverflow
Solution 5 - LinuxA.B.View Answer on Stackoverflow