喜文件夾後後,我找到文件,並用雙引號用下面的命令附上自己的名字:的grep無法讀取文件名找到空間
FILES=$(find . -type f -not -path "./.git/*" -exec echo -n '"{}" ' \; | tr '\n' ' ')
我的for循環裏面用grep某個詞做每個匹配的文件中找到:
for f in $FILES; do grep -Eq '(GNU)' $f; done
但grep的抱怨每個條目,它無法找到文件或目錄:
grep: "./test/test.c": No such file or directory
見圖片:
而echo $FILES
生產:
"./.DS_Store" "./.gitignore" "./add_license.sh" "./ads.add_lcs.log" "./lcs_gplv2" "./lcs_mit" "./LICENSE" "./new test/test.js" "./README.md" "./sxs.add_lcs.log" "./test/test.c" "./test/test.h" "./test/test.js" "./test/test.m" "./test/test.py" "./test/test.pyc"
編輯 找到了答案here。完美的作品!
如果我確實想要一個與正則表達式不匹配的文件列表,那麼**又**? – Sanandrea
'-L'選項列出文件不匹配。 –
最後一個問題,第二個選項列出文件中的(非)匹配文件,是否可以用結果構建一個數組?所以我不需要閱讀文件的內容,然後刪除它。 – Sanandrea