根据这个问题:How to except dirs in find,命令应该是这样的:
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print
Run Code Online (Sandbox Code Playgroud)
但如果我这样做
find . -type d \( -path "./.cpan" -o -path "./.mozilla" -o "./.cache" \) -prune -o -print
Run Code Online (Sandbox Code Playgroud)
这给出:
find: paths must precede expression: ./.cache'
find: possible unquoted pattern after predicate -o'?
但我做了报价。
另外,-path选项后,路径应该是绝对路径还是相对路径?因为我已经包含了当前目录./[somefile],但是需要它吗-path?
您错过了-path最后一个选项值前面的谓词"./.cache"
所使用的路径-path必须以 所使用的顶级搜索路径开头find。例如
find . -path './something/here'find /etc -path '/etc/init.d'*如果要匹配目录名称而不指定其在文件系统树中的位置,则可能需要使用通配符。此示例将匹配-type f目录下某处的所有文件 ( )wizard
find . -path '*/wizard/* -type f -print