使用查找时是否可以跳过找到的文件夹中找到的文件?

使用查找时是否可以跳过找到的文件夹中找到的文件?

我正在寻找一个仅输出以下两个文件夹并跳过找到的文件夹中找到的文件的命令。

/Users/sunknudsen/Library/Application Scripts/com.brothersroloff.SyncBuddy
/Users/sunknudsen/Library/Containers/com.brothersroloff.SyncBuddy
$ find ~/Library -iname "*syncbuddy*" 2>&1 | grep -v "Permission denied"
/Users/sunknudsen/Library/Application Scripts/com.brothersroloff.SyncBuddy
/Users/sunknudsen/Library/Containers/com.brothersroloff.SyncBuddy
/Users/sunknudsen/Library/Containers/com.brothersroloff.SyncBuddy/Data/Library/Application Support/com.brothersroloff.SyncBuddy
/Users/sunknudsen/Library/Containers/com.brothersroloff.SyncBuddy/Data/Library/Application Support/com.brothersroloff.SyncBuddy/SyncBuddy.storedata
/Users/sunknudsen/Library/Containers/com.brothersroloff.SyncBuddy/Data/Library/Preferences/com.brothersroloff.SyncBuddy.plist
/Users/sunknudsen/Library/Containers/com.brothersroloff.SyncBuddy/Data/Library/Application Scripts/com.brothersroloff.SyncBuddy

答案1

如果您只想要最顶层的匹配项,则可以在打印后删除匹配的目录:

find ~/Library -iname "*syncbuddy*" -print -prune

相关内容