To find all the files that contain “foo” in current folder, I use:
grep -r "foo" .
To find all the files that contain “bar” in current folder, I use:
grep -r "bar" .
But how to find all files that does not contain ‘foo’ and ‘bar’?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To print lines that do not contain some string, you use the
-vflag:This gives you all lines that do not contain
fooorbar.To print files that do not contain some string, you use the
-Lflag. To non-match several strings, you can use regular expressions with the-Pflag (there are several regex flags you can use):This prints a list of files that don’t contain
fooorbar.Thanks to Anton Kovalenko for pointing this out.