原始问题 - 仅限 777 许可
如果您正在查找具有 777 权限的文件,请使用find以下方法:
find /example/dir -type f -perm 777
如果您不想在输出中包含file1、或file2,请也使用:file3file4grep
find /example/dir -type f -perm 777 | grep -Ev 'file[1234]'
如果您想要stat这些文件的输出,则:
find /example/dir -type f -perm 777 | grep -Ev 'file[1234]' | xargs stat --format %a
或者:
stat --format %a $(find /example/dir -type f -perm 777 | grep -Ev 'file[1234]')
如果文件列表很大,这更有可能遇到问题。您可以根据需要恢复-prune任何find命令的选项。但是,运行find example/dir -type f并find example/dir -type f -prune没有改变我看到的结果。
修改后的问题——777 和 775 许可
如果您正在寻找 777 或 775 许可,那么您需要:
find /example/dir -type f -perm +775
这恰好起作用,因为 777 和 775 权限之间只有一点不同。更通用和可扩展的解决方案将使用-or操作:
find /example/dir -type f \( -perm 777 -or -perm 775 \)
随着数字的变化,这可以在不拾取可执行文件的情况下寻找 664 或 646 权限,这-perm +622将拾取。
问题代码中的问题
至于问题中的代码出了什么问题——我不完全确定。
$ find example/dir -type f
example/dir/a/filea
example/dir/a/fileb
example/dir/b/filea
example/dir/b/fileb
example/dir/c/filea
example/dir/c/fileb
example/dir/filea
example/dir/fileb
$ find example/dir -type f -not \( -name filea -o -name fileb \)
$ find example/dir -type f -not \( -name filea -or -name fileb \)
$ find example/dir -type f \( -name filea -or -name fileb \)
example/dir/a/filea
example/dir/a/fileb
example/dir/b/filea
example/dir/b/fileb
example/dir/c/filea
example/dir/c/fileb
example/dir/filea
example/dir/fileb
$ find example/dir -type f ! \( -name filea -or -name fileb \)
$ find example/dir -type f \( -not -name filea -and -not -name fileb \)
$
-notor运算符似乎完全把!事情搞砸了,这是我没想到的。find从表面上看,这看起来像一个错误,但在我声称“错误”之前,我必须有更多的证据并且必须对规范进行大量非常仔细的审查。
此测试是find在 Mac OS X 10.8.3 (BSD) 上完成的,没有 GNU find。
(您在问题中使用“八位字节”一词令人费解;它通常用于表示网络通信中的一个字节,更严格的含义是一个字节不需要是 8 位。权限在八进制,基于 inode 中的 16 位、2 个八位字节。)