Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 9 down vote accepted

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 
share|improve this answer
2  
You can also look for ack for code searching. –  Abhijeet Kasurde Jul 13 '12 at 6:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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