我正在寻找递归地通过目录查找文件不属于一个特定的用户,我不知道如何写这个。


当前回答

寻找不属于某人的文件

其他人回答了身体中“不属于特定用户”的问题。这里有一个答案,但没有提供:

$ find / -nouser

你可以这样使用它:

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

还有一个相关的:

$ find / -nogroup

其他回答

寻找不属于某人的文件

其他人回答了身体中“不属于特定用户”的问题。这里有一个答案,但没有提供:

$ find / -nouser

你可以这样使用它:

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

还有一个相关的:

$ find / -nogroup

-user根据用户或用户ID查找,并且!反转谓词。所以,!用户……

你可以用这个:

find <dir> ! -user <username> 

find(1)实用程序具有可以使用“!”操作符求反(“反转”)的主要元素。但是在提示符上,必须用反斜杠转义否定,因为它是shell元字符。结果:

find . \! -user foo -print

使用z-shell (zsh)即可使用

ls -laR *(^U)

or

ls -la **/*(^U)

以递归方式搜索不属于您的所有文件。