linux - 从搜索整个系统中排除目录

标签 linux find rhel

我需要搜索具有特定权限的所有文件,同时排除 / 下的两个目录。这些目录包含太多信息,系统会因它们而窒息。

我尝试过 -type 的各种组合-path -wholename-prune并且似乎无法让它排除这两个目录。

目前这就是我正在尝试的。

find . -path './dir1/' -prune -o -path './dir2/' -prune -o -type d -perm -002 ! -perm -1000 > wwlist

任何帮助将不胜感激。

最佳答案

您可以添加排除目录的条件:

find . '!' -path './dir1/*' '!' -path './dir2/*' ...

更准确地说,还排除目录本身:

find . '!' -path './dir1' '!' -path './dir2' '!' -path './dir1/*' '!' -path './dir2/*' ...

您还可以使用正则表达式:

find . -regextype posix-extended -not -regex '[.]/dir(1|2)(/.*)?' ...
  • 您还可以使用 -not 代替 !,但它不符合 POSIX 标准。
  • -wholename-path 同义,但不符合 POSIX 标准。

关于linux - 从搜索整个系统中排除目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25081785/

相关文章:

C程序求字符串中子串出现的次数

python - How to grab string(ip) from netstat pipe the string(ip) to whois command, grab a string(country) 从 whois 输出。并使用 iptables 禁止 ip

linux - 如何将 Linux Shell 中的 delete 和 find 命令重写为 Window 命令提示符?

linux - 无效命令名称 "Agent/rtProto/OSPF"

javascript - 从 coffeescript 编译后使用 makefile 合并 javascript 文件

linux - 在受限环境中运行外部代码(linux)

shell - xargs - 多个命令和最后的 rm

file - 找不到另一个类文件的符号

python - 在 RHEL 上安装 Python 3

bash - 为所有用户删除 BASH 历史记录