使用 find 命令排除文件夹

smo*_*uns 6 unix find

我在findMac 上使用该命令搜索名为test1. 现在test1文件夹也可以存在于.Trash文件夹中。如何排除.Trash搜索结果中报告的文件夹或基本上我希望排除的任何文件夹?

$ find $HOME  -name test1 -type d
/Users/theuser/.Trash/test1
/Users/theuser/test1 
/Users/theuser/Downloads/test1 
Run Code Online (Sandbox Code Playgroud)

我希望结果只是

/Users/theuser/test1
/Users/theuser/Downloads/test1 
Run Code Online (Sandbox Code Playgroud)

我用过grep

find $HOME  -name test1 -type d | grep -v '.Trash' 
Run Code Online (Sandbox Code Playgroud)

过滤掉.Trash结果,但我很想知道find单独使用是否能达到相同的结果。

her*_*odd 10

find $HOME -path  $HOME/.Trash -prune -o -name test1 -type d -print
Run Code Online (Sandbox Code Playgroud)

通过明确使用,-print您可以避免虚假打印.Trash.