Filter files by ownership | Use ls -l to show only files with a certain user ownership

Well one way is not to use the "ls" command, use "find" with "-maxdepth 1" so that it performs like ls instead:

user@server the_directory> find -maxdepth 1 -user the_user_name -ls 2>/dev/null

user@server the_directory> find -maxdepth 1 -group the_group_name -ls 2>/dev/null

or if you want it to be exactly the same output as with "ls -l" just pipe the output to "ls -l"

user@server the_directory> find -maxdepth 1 -group the_group_name 2>/dev/nul | ls -l

Lets explain how this works.

find - the find command that will recurs through directories below the current working directory
-maxdepth 1 - tells the command to look at only the current working directory
-user - tells the find command that we are looking for files that have the user name (in this case the dummy value the_user_name)
-ls - output results in the format of ls -l
2>/dev/null - remove any permission errors from the output

comments powered by Disqus