使用 find 或 fd 錨定排除

使用 find 或 fd 錨定排除

假設我想(遞歸地)查找目錄中的所有文件,但忽略這些文件,例如.gitnode_modules子目錄。我可以:

$ fd -uut f -E .git -E node_modules

但這將例如排除./some/dir/node_modules/*或某些類似的內容。

在這種情況下,這可能沒問題,但我不想每次需要查找某些內容時都考慮非錨定搜尋是否可行。更不用說在某些情況下它不會。

我如何排除./dir,但不排除./**/dir

答案1

要區分這兩種情況,請使用謂詞-path

$ find . -path ./a -prune -o -type f -print

相關內容