I am trying to find out which files contains this text ' roads
' on the server, so I use this command: grep -rl 'roads'
. But it shows lots of such files:
./res/js/.svn/entries
./res/js/.svn/all-wcprops
./res/styles/.svn/entries
./res/styles/.svn/all-wcprops
./res/images/.svn/entries
I do not want this folder .svn
show in the search result because this is just for version control, it means nothing for me, so is there a way that I can do this: if the result contains .svn
, then it does not show up in the final result. eg below three files contain the text ' roads
':
check.php
./res/js/.svn/entries
./res/js/.svn/all-wcprops
Then the result only shows:
check.php
One simple way is to simply grep away your false positives:
grep -rl roads . | grep -v '/\.svn/'
If you want to be more efficient and not spend time searching through the SVN files, you can filter them away before grepping through them:
find -type f | grep -v '/\.svn/' | xargs grep -l roads
grep具有排除特定目录的功能,称为“--exclude-dir”,因此您只需将.svn作为“--exclude-dir”param传递,如下所示:
"grep -rl --exclude-dir=.svn ./ -e roads"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.