![](/img/trans.png)
[英]grep a keyword in all .h and .c files under current directory but exclude two directories
[英]grep exclude-dir in current directory or subdirectories
我正在嘗試將我的GREP_OPTIONS
設置為始終排除某些目錄(例如target/classes
)。 我專門試圖使它適用於遞歸gr。 當當前目錄包含target/classes
,使用--exclude-dir=target/classes
效果很好,但是當我位於父目錄中時,情況並非如此。 我當前的解決方案要求我同時設置--exclude-dir=target/classes
和--exclude-dir=*/target/classes
。 我正在尋找一個更直接的解決方案,我認為它將涉及一個正則表達式。 我已經嘗試了--exclude-dir=(*/)?target/classes
和其他排列方式,但是我無法使其正常工作。
是的,我相信可以使用其他工具(例如,find,awk等)來完成此操作,但是我真的很想將其限制在GREP_OPTIONS
解決方案中(如果可能)。
這是一個經過測試的工作示例,請謹慎使用語法,不要輸入錯誤:
root/dspace# grep -r --exclude-dir={log,assetstore} "creativecommons.org"
在上面的grep中,當前目錄“ dspace”中的文本“ creativecommons.org”不包括目錄{log,assetstore}。
完成。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.