Looking for files NOT owned by someone

2020-05-11 20:52发布

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.

5条回答
家丑人穷心不美
2楼-- · 2020-05-11 21:31

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

查看更多
别忘想泡老子
3楼-- · 2020-05-11 21:37

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
查看更多
够拽才男人
4楼-- · 2020-05-11 21:48

You can use this:

find <dir> ! -user <username> 
查看更多
Evening l夕情丶
5楼-- · 2020-05-11 21:52

Using z-shell (zsh) you can use

ls -laR *(^U)

or

ls -la **/*(^U)

to search for all files recursively not owned by you.

查看更多
ら.Afraid
6楼-- · 2020-05-11 21:53

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
查看更多
登录 后发表回答