在查找中,如果与“-prune”一起使用,“-type d”不仅会获取目录,还会获取文件
in find, `-type d` get files an not only directories if used with `-prune`
我用这个:
$ find . -type d \( -path './2018*' -o -path "./S*" \) -prune\
-o -print
获取除 2018
、S1
和 S2
之外的所有目录 (-type d
)
目录排除有效,但我得到了大量文件:
...
./git_wc
./budget
./budget/mail_0625
./budget/mail_0625/prez.pptx
./budget/budget_v2.xlsx
./budget/achats
./budget/achats/106-1396140_V1_20190731.pdf
./rh
./rh/file.docx
顺便说一句,我正在寻找一个纯粹的 find
答案,我知道如何使用 tree
:
$ tree -d -L 2 -I 'S1|2018' -fi
...
./git_wc
./budget
./budget/mail_0625
./budget/achats
./rh
...
您的命令逻辑是 "prune all directories that have names matching the glob ./2018* or ./S*; print everything else"。你想要:
find . \( -path './2018*' -o -path "./S*" \) -prune\
-o -type d -print
我用这个:
$ find . -type d \( -path './2018*' -o -path "./S*" \) -prune\
-o -print
获取除 2018
、S1
和 S2
-type d
)
目录排除有效,但我得到了大量文件:
...
./git_wc
./budget
./budget/mail_0625
./budget/mail_0625/prez.pptx
./budget/budget_v2.xlsx
./budget/achats
./budget/achats/106-1396140_V1_20190731.pdf
./rh
./rh/file.docx
顺便说一句,我正在寻找一个纯粹的 find
答案,我知道如何使用 tree
:
$ tree -d -L 2 -I 'S1|2018' -fi
...
./git_wc
./budget
./budget/mail_0625
./budget/achats
./rh
...
您的命令逻辑是 "prune all directories that have names matching the glob ./2018* or ./S*; print everything else"。你想要:
find . \( -path './2018*' -o -path "./S*" \) -prune\
-o -type d -print