MyBB Community Forums

Full Version: grep -r and exclude certain directories?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Any idea how to do this? I've never used GREP before and I find some commands via Google but I had no luck getting them to work. Sad Thanks.
there is --exclude=foobar which would skip a file named foobar. not sure if it would skip a directory of that name too.

for recursing directories the 'find' command offers much more options that let you specify conditions, and you can use 'find -print0 | xargs -0 grep' to pass the list of files found by find on to grep.

some people also do it with grep ... | grep -v ... but that is not a reliable method.
So if I wanted to find all of the .html and .php files in my /home/ directory except for 2 directories and then have grep search those files how would I could about that?
find "/home/" -path "/home/dir1" -prune -path "/home/dir2" -prune -name "*.html" -or -name "*.php" -print0 | xargs -0 grep foobar