Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for files NOT owned by a specific user

People also ask

What is the command to search for files with no user?

You can use find command to find out all files that do not have any owners or do not belong to any user under Linux/UNIX/BSD operating systems.

How do I find out what files a user group owns?

If you want to find a file owned by a particular user and a particular group then you need to use both -user and -group option with find command as shown below. In this example, we are searching for all the files owned by user root and group centos using find / -user root -group centos -type f command.

How do I find out what files a user owns in Linux?

You need to use the find command to search for files in a directory hierarchy. It has options that allow you to search files owned by a specific user or groups under a Unix, Linux, *BSD, Apple macOS/OS X operating systems.

How do I find a file with specific permissions?

The -perm parameter of the find command can be used to find the files with specific permissions. The 2 ways to specify the permissions with the -perm parameter are : -perm -mode --- All of the permission bits mode are set for the file. -perm /mode --- Any of the permission bits mode are set for the file.


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

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

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


You can use this:

find <dir> ! -user <username> 

Using z-shell (zsh) you can use

ls -laR *(^U)

or

ls -la **/*(^U)

to search for all files recursively not owned by you.