【发布时间】:2011-08-21 02:43:22
【问题描述】:
我希望递归地查看目录以查找不属于特定用户的文件,但我不知道如何编写。
【问题讨论】:
我希望递归地查看目录以查找不属于特定用户的文件,但我不知道如何编写。
【问题讨论】:
寻找不属于某人的文件
其他人已在正文中回答了问题“不属于特定用户”。这是一个回答了名义问题但尚未提供的问题:
$ find / -nouser
你可以这样使用它:
$ sudo find /var/www -nouser -exec chown root:apache {} \;
还有一个相关的:
$ find / -nogroup
【讨论】:
使用z-shell(zsh)可以使用
ls -laR *(^U)
或
ls -la **/*(^U)
递归搜索所有不属于您的文件。
【讨论】:
-a 标志,因为通配符扩展。要捕获点文件,请使用 zsh dotglob 选项:setopt dotglob。在一行中:(setopt dotglob; ls **/*(^U) )。括号将在子shell中运行,这样您就不必在完成后运行setopt nodotglob。
D:ls **/*(D^U)。
find(1) 实用程序具有可以使用“!”取反(“反转”)的初选。操作员。然而,在提示符处必须用反斜杠转义否定,因为它是一个 shell 元字符。结果:
find . \! -user foo -print
【讨论】:
! 似乎是可选的
xargs -I{} -P3 -- ${cmdhere} {} 可以让 ${cmdhere} 对每个文件进行并行操作。 cmdhere ::= 标准 unix utils;标准 unix utils ::= chmod, chown, stat, ls, ...
find . ... 还是管道到xargs 是第一种还是第二种方式?
find . ! -user foo -exec chown <owner>:<group> {} \;
set -H),则感叹号必须转义,通常默认情况下处于启用状态。
你可以用这个:
find <dir> ! -user <username>
【讨论】:
-user 按用户或用户 ID 查找,! 反转谓词。所以,! -user ...。
【讨论】: