![在 Linux 中尋找目錄中除“test”目錄之外的所有“.c”和“.h”文件](https://rvso.com/image/1457436/%E5%9C%A8%20Linux%20%E4%B8%AD%E5%B0%8B%E6%89%BE%E7%9B%AE%E9%8C%84%E4%B8%AD%E9%99%A4%E2%80%9Ctest%E2%80%9D%E7%9B%AE%E9%8C%84%E4%B9%8B%E5%A4%96%E7%9A%84%E6%89%80%E6%9C%89%E2%80%9C.c%E2%80%9D%E5%92%8C%E2%80%9C.h%E2%80%9D%E6%96%87%E4%BB%B6.png)
我想找到目錄中的所有 .c 和 .h 文件,不包括“test”資料夾中的文件(有多個)。
我正在搜尋的目錄有測試目錄,例如:
myDirectory/abc/def/test
myDirectory/abc/def/ghi/test
ETC。
到目前為止,我已經嘗試過:
find /myDirectory/* -type d -name test -prune -o -name '*.c' -print
這似乎適用於 .c 文件,但是當我運行時:
find /myDirectory/* -type d -name test -prune -o -name '*.c' -o -name '*.h' -print
根本沒有回任何內容。
如何包含多種文件類型?
答案1
您必須將兩個-name
謂詞分組:
find /myDirectory/* -type d -name test -prune -o \( -name '*.c' -o -name '*.h' \) -print
需要反斜線來轉義括號。