How can we find all the files under a directory whose contents contain any of several strings? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-3
down vote

favorite













This question already has an answer here:



  • How to find files containing two strings in different lines

    3 answers



  • Search among the content of a large number of plain text files?

    5 answers



I was wondering how to find all the files under a directory whose contents contain any of several strings word1, word2, word3, ...?
Thanks.







share|improve this question











marked as duplicate by Stephen Kitt, Jeff Schaller, Patrick, G-Man, meuh Jun 6 at 15:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • you can do cd directory ; grep -rEl "pattern1|pattern2|pattern3" depending on your needs it can just do the job. works fine with gnugrep
    – francois P
    Jun 5 at 21:06











  • There are many duplicates of that question here.
    – Stéphane Chazelas
    Jun 5 at 21:07











  • @Stéphane I was looking for them too; funnily enough your own answer to one of Tim’s questions fits the bill ;-).
    – Stephen Kitt
    Jun 5 at 21:15














up vote
-3
down vote

favorite













This question already has an answer here:



  • How to find files containing two strings in different lines

    3 answers



  • Search among the content of a large number of plain text files?

    5 answers



I was wondering how to find all the files under a directory whose contents contain any of several strings word1, word2, word3, ...?
Thanks.







share|improve this question











marked as duplicate by Stephen Kitt, Jeff Schaller, Patrick, G-Man, meuh Jun 6 at 15:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • you can do cd directory ; grep -rEl "pattern1|pattern2|pattern3" depending on your needs it can just do the job. works fine with gnugrep
    – francois P
    Jun 5 at 21:06











  • There are many duplicates of that question here.
    – Stéphane Chazelas
    Jun 5 at 21:07











  • @Stéphane I was looking for them too; funnily enough your own answer to one of Tim’s questions fits the bill ;-).
    – Stephen Kitt
    Jun 5 at 21:15












up vote
-3
down vote

favorite









up vote
-3
down vote

favorite












This question already has an answer here:



  • How to find files containing two strings in different lines

    3 answers



  • Search among the content of a large number of plain text files?

    5 answers



I was wondering how to find all the files under a directory whose contents contain any of several strings word1, word2, word3, ...?
Thanks.







share|improve this question












This question already has an answer here:



  • How to find files containing two strings in different lines

    3 answers



  • Search among the content of a large number of plain text files?

    5 answers



I was wondering how to find all the files under a directory whose contents contain any of several strings word1, word2, word3, ...?
Thanks.





This question already has an answer here:



  • How to find files containing two strings in different lines

    3 answers



  • Search among the content of a large number of plain text files?

    5 answers









share|improve this question










share|improve this question




share|improve this question









asked Jun 5 at 21:03









Tim

22.5k61222401




22.5k61222401




marked as duplicate by Stephen Kitt, Jeff Schaller, Patrick, G-Man, meuh Jun 6 at 15:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Stephen Kitt, Jeff Schaller, Patrick, G-Man, meuh Jun 6 at 15:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • you can do cd directory ; grep -rEl "pattern1|pattern2|pattern3" depending on your needs it can just do the job. works fine with gnugrep
    – francois P
    Jun 5 at 21:06











  • There are many duplicates of that question here.
    – Stéphane Chazelas
    Jun 5 at 21:07











  • @Stéphane I was looking for them too; funnily enough your own answer to one of Tim’s questions fits the bill ;-).
    – Stephen Kitt
    Jun 5 at 21:15
















  • you can do cd directory ; grep -rEl "pattern1|pattern2|pattern3" depending on your needs it can just do the job. works fine with gnugrep
    – francois P
    Jun 5 at 21:06











  • There are many duplicates of that question here.
    – Stéphane Chazelas
    Jun 5 at 21:07











  • @Stéphane I was looking for them too; funnily enough your own answer to one of Tim’s questions fits the bill ;-).
    – Stephen Kitt
    Jun 5 at 21:15















you can do cd directory ; grep -rEl "pattern1|pattern2|pattern3" depending on your needs it can just do the job. works fine with gnugrep
– francois P
Jun 5 at 21:06





you can do cd directory ; grep -rEl "pattern1|pattern2|pattern3" depending on your needs it can just do the job. works fine with gnugrep
– francois P
Jun 5 at 21:06













There are many duplicates of that question here.
– Stéphane Chazelas
Jun 5 at 21:07





There are many duplicates of that question here.
– Stéphane Chazelas
Jun 5 at 21:07













@Stéphane I was looking for them too; funnily enough your own answer to one of Tim’s questions fits the bill ;-).
– Stephen Kitt
Jun 5 at 21:15




@Stéphane I was looking for them too; funnily enough your own answer to one of Tim’s questions fits the bill ;-).
– Stephen Kitt
Jun 5 at 21:15










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










Use grep’s recursive search with multiple patterns:



grep -r -F -e word1 -e word2 -e word3


If you have many words to search for, store them in a file, one per line, and give that to grep:



grep -r -F -f patternfile


Add -l in both cases if you’re only interested in the files’ names, -R (instead of -r) if you want to dereference symlinks as you go down directory tree.



How to grep thousands of files in a directory for hundreds of strings in a file has tips for doing this over large numbers of files with large numbers of patterns.






share|improve this answer























  • doing this way can make huge output when many patterns appear in many files on many lines each ... add -l option will only display the filenames to avoid that :)
    – francois P
    Jun 5 at 21:10







  • 1




    Indeed, thanks @francoisP!
    – Stephen Kitt
    Jun 5 at 21:13










  • Thanks. What does -F mean here?
    – Tim
    Jun 6 at 0:01











  • Which one is better, your command using -e, or grep -rEl "pattern1|pattern2|pattern3" ?
    – Tim
    Jun 6 at 3:02











  • -F tells grep to treat the patterns as fixed strings rather than regular expressions. It is often significantly faster to use this; in my tests, searching for two patterns in 36,088 files occupying 6.3GiB (all in cache), the grep -rFl -e ... variant is 10× faster than the grep -rEl ... variant.
    – Stephen Kitt
    Jun 6 at 9:14


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










Use grep’s recursive search with multiple patterns:



grep -r -F -e word1 -e word2 -e word3


If you have many words to search for, store them in a file, one per line, and give that to grep:



grep -r -F -f patternfile


Add -l in both cases if you’re only interested in the files’ names, -R (instead of -r) if you want to dereference symlinks as you go down directory tree.



How to grep thousands of files in a directory for hundreds of strings in a file has tips for doing this over large numbers of files with large numbers of patterns.






share|improve this answer























  • doing this way can make huge output when many patterns appear in many files on many lines each ... add -l option will only display the filenames to avoid that :)
    – francois P
    Jun 5 at 21:10







  • 1




    Indeed, thanks @francoisP!
    – Stephen Kitt
    Jun 5 at 21:13










  • Thanks. What does -F mean here?
    – Tim
    Jun 6 at 0:01











  • Which one is better, your command using -e, or grep -rEl "pattern1|pattern2|pattern3" ?
    – Tim
    Jun 6 at 3:02











  • -F tells grep to treat the patterns as fixed strings rather than regular expressions. It is often significantly faster to use this; in my tests, searching for two patterns in 36,088 files occupying 6.3GiB (all in cache), the grep -rFl -e ... variant is 10× faster than the grep -rEl ... variant.
    – Stephen Kitt
    Jun 6 at 9:14















up vote
3
down vote



accepted










Use grep’s recursive search with multiple patterns:



grep -r -F -e word1 -e word2 -e word3


If you have many words to search for, store them in a file, one per line, and give that to grep:



grep -r -F -f patternfile


Add -l in both cases if you’re only interested in the files’ names, -R (instead of -r) if you want to dereference symlinks as you go down directory tree.



How to grep thousands of files in a directory for hundreds of strings in a file has tips for doing this over large numbers of files with large numbers of patterns.






share|improve this answer























  • doing this way can make huge output when many patterns appear in many files on many lines each ... add -l option will only display the filenames to avoid that :)
    – francois P
    Jun 5 at 21:10







  • 1




    Indeed, thanks @francoisP!
    – Stephen Kitt
    Jun 5 at 21:13










  • Thanks. What does -F mean here?
    – Tim
    Jun 6 at 0:01











  • Which one is better, your command using -e, or grep -rEl "pattern1|pattern2|pattern3" ?
    – Tim
    Jun 6 at 3:02











  • -F tells grep to treat the patterns as fixed strings rather than regular expressions. It is often significantly faster to use this; in my tests, searching for two patterns in 36,088 files occupying 6.3GiB (all in cache), the grep -rFl -e ... variant is 10× faster than the grep -rEl ... variant.
    – Stephen Kitt
    Jun 6 at 9:14













up vote
3
down vote



accepted







up vote
3
down vote



accepted






Use grep’s recursive search with multiple patterns:



grep -r -F -e word1 -e word2 -e word3


If you have many words to search for, store them in a file, one per line, and give that to grep:



grep -r -F -f patternfile


Add -l in both cases if you’re only interested in the files’ names, -R (instead of -r) if you want to dereference symlinks as you go down directory tree.



How to grep thousands of files in a directory for hundreds of strings in a file has tips for doing this over large numbers of files with large numbers of patterns.






share|improve this answer















Use grep’s recursive search with multiple patterns:



grep -r -F -e word1 -e word2 -e word3


If you have many words to search for, store them in a file, one per line, and give that to grep:



grep -r -F -f patternfile


Add -l in both cases if you’re only interested in the files’ names, -R (instead of -r) if you want to dereference symlinks as you go down directory tree.



How to grep thousands of files in a directory for hundreds of strings in a file has tips for doing this over large numbers of files with large numbers of patterns.







share|improve this answer















share|improve this answer



share|improve this answer








edited Jun 5 at 21:19


























answered Jun 5 at 21:07









Stephen Kitt

140k22302363




140k22302363











  • doing this way can make huge output when many patterns appear in many files on many lines each ... add -l option will only display the filenames to avoid that :)
    – francois P
    Jun 5 at 21:10







  • 1




    Indeed, thanks @francoisP!
    – Stephen Kitt
    Jun 5 at 21:13










  • Thanks. What does -F mean here?
    – Tim
    Jun 6 at 0:01











  • Which one is better, your command using -e, or grep -rEl "pattern1|pattern2|pattern3" ?
    – Tim
    Jun 6 at 3:02











  • -F tells grep to treat the patterns as fixed strings rather than regular expressions. It is often significantly faster to use this; in my tests, searching for two patterns in 36,088 files occupying 6.3GiB (all in cache), the grep -rFl -e ... variant is 10× faster than the grep -rEl ... variant.
    – Stephen Kitt
    Jun 6 at 9:14

















  • doing this way can make huge output when many patterns appear in many files on many lines each ... add -l option will only display the filenames to avoid that :)
    – francois P
    Jun 5 at 21:10







  • 1




    Indeed, thanks @francoisP!
    – Stephen Kitt
    Jun 5 at 21:13










  • Thanks. What does -F mean here?
    – Tim
    Jun 6 at 0:01











  • Which one is better, your command using -e, or grep -rEl "pattern1|pattern2|pattern3" ?
    – Tim
    Jun 6 at 3:02











  • -F tells grep to treat the patterns as fixed strings rather than regular expressions. It is often significantly faster to use this; in my tests, searching for two patterns in 36,088 files occupying 6.3GiB (all in cache), the grep -rFl -e ... variant is 10× faster than the grep -rEl ... variant.
    – Stephen Kitt
    Jun 6 at 9:14
















doing this way can make huge output when many patterns appear in many files on many lines each ... add -l option will only display the filenames to avoid that :)
– francois P
Jun 5 at 21:10





doing this way can make huge output when many patterns appear in many files on many lines each ... add -l option will only display the filenames to avoid that :)
– francois P
Jun 5 at 21:10





1




1




Indeed, thanks @francoisP!
– Stephen Kitt
Jun 5 at 21:13




Indeed, thanks @francoisP!
– Stephen Kitt
Jun 5 at 21:13












Thanks. What does -F mean here?
– Tim
Jun 6 at 0:01





Thanks. What does -F mean here?
– Tim
Jun 6 at 0:01













Which one is better, your command using -e, or grep -rEl "pattern1|pattern2|pattern3" ?
– Tim
Jun 6 at 3:02





Which one is better, your command using -e, or grep -rEl "pattern1|pattern2|pattern3" ?
– Tim
Jun 6 at 3:02













-F tells grep to treat the patterns as fixed strings rather than regular expressions. It is often significantly faster to use this; in my tests, searching for two patterns in 36,088 files occupying 6.3GiB (all in cache), the grep -rFl -e ... variant is 10× faster than the grep -rEl ... variant.
– Stephen Kitt
Jun 6 at 9:14





-F tells grep to treat the patterns as fixed strings rather than regular expressions. It is often significantly faster to use this; in my tests, searching for two patterns in 36,088 files occupying 6.3GiB (all in cache), the grep -rFl -e ... variant is 10× faster than the grep -rEl ... variant.
– Stephen Kitt
Jun 6 at 9:14



Popular posts from this blog

How to check contact read email or not when send email to Individual?

Christian Cage

How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?