[英]Excluding directories with grep
我只是試過:
michael@Pascal:~/noisynet$ sudo grep -rio --exclude-dir={/ece,/home/michael/pytorch,/sys,/proc} 'hello' /
第一個匹配項是:
/home/michael/pytorch/.git/logs/HEAD:hello
為什么在/home/michael/pytorch
?
這樣會很好用
grep -rio --exclude-dir={ece,pytorch,sys,proc} 'hello' /
注意:這還將排除具有相同名稱的其他目錄。
說明:
grep手冊頁給出了以下片段
--exclude-dir=GLOB Skip any command-line directory with a name suffix that matches the pattern GLOB. When searching recursively, skip any subdirectory whose base name matches GLOB. Ignore any redundant trailing slashes in GLOB.
這意味着給定模式(GLOB)
將僅應用於目錄的實際名稱,並且由於目錄名中不包含/,因此/ proc之類的模式將永遠不匹配。
因此,我們只需要使用--exclude-dir=proc or --exclude-dir=sys (or --exclude-dir={proc,sys})
名稱來排除不帶'/'的目錄。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.