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?

dukevin
  • 1,630
  • 3
  • 18
  • 25

1 Answers1

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 
Abhijeet Kasurde
  • 983
  • 9
  • 20