[英]Find specific folders then search specific files inside them for a word
我正在嘗試將find和grep結合起來,以查找以k0開頭的文件夾名稱,並在特定文件“ test.log”中搜索錯誤字。
就像是:
find . -type d -name "k0*" -print | xargs grep ERROR test.log
不幸的是,此命令無法按預期運行。
嘗試此操作,我假設您在名稱以k0
開頭的文件夾中有多個名為test.log
的文件:
for file in $(find ./k0* -name 'test.log'); do
grep -w 'ERROR' $file
done
您可以將其變成單線命令,如下所示:
for file in $(find ./k0* -name 'test.log'); do grep -w 'ERROR' $file; done
如果您將其發布,則可以在終端上執行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.