
我正在嘗試使用 grep 在資料夾中搜尋字串。
grep -r "word" .
但它包括對 .git 檔案的搜索,我想避免這種情況。
謝謝
答案1
如果您想排除.git
目錄:
grep --exclude-dir=".git" -r "word" .
這適用於 GNU grep
,不適用於其他版本,但由於您似乎使用的是 Linux,所以這應該沒問題。
答案2
嘗試“確認”(http://beyondgrep.com/),它本身會忽略 .git、.hg、.csv 等:
預設搜尋整個樹,同時忽略 Subversion、Git 和其他 VCS 目錄以及其他不是原始碼的檔案。
答案3
grep
如果您不支援排除目錄,那麼這是一個更靈活的解決方案:
尋找 。 -type d -path */.git -prune -o -type f -print0 | xargs -0 -e grep 單字