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?

1 Answer 1


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

For example:

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


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .