3

I have text I want to recursively search in mydir/. I would normally type grep -r "text to find" mydir/" but what would I type if I wanted to search all the files except a specific one?

For example, I do not want to search the file "myfile.txt" but it is contained in the directory.

What would I type?

9

You can achieve this by --exclude and --exclude-dir options of grep

For example:

grep -r --exclude-dir='<dirs_to_exclude>' PATTERN data

or

grep -r --exclude='<pattern_of_file>' PATTERN data 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.