How can we find all the files under a directory whose contents contain any of several strings? [duplicate]
Clash 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.
awk files grep find
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.
add a comment |Â
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.
awk files grep find
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
add a comment |Â
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.
awk files grep find
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
awk files grep find
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
add a comment |Â
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
add a comment |Â
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.
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
, orgrep -rEl "pattern1|pattern2|pattern3"
?
â Tim
Jun 6 at 3:02
-F
tellsgrep
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), thegrep -rFl -e ...
variant is 10Ã faster than thegrep -rEl ...
variant.
â Stephen Kitt
Jun 6 at 9:14
add a comment |Â
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.
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
, orgrep -rEl "pattern1|pattern2|pattern3"
?
â Tim
Jun 6 at 3:02
-F
tellsgrep
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), thegrep -rFl -e ...
variant is 10Ã faster than thegrep -rEl ...
variant.
â Stephen Kitt
Jun 6 at 9:14
add a comment |Â
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.
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
, orgrep -rEl "pattern1|pattern2|pattern3"
?
â Tim
Jun 6 at 3:02
-F
tellsgrep
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), thegrep -rFl -e ...
variant is 10Ã faster than thegrep -rEl ...
variant.
â Stephen Kitt
Jun 6 at 9:14
add a comment |Â
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.
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.
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
, orgrep -rEl "pattern1|pattern2|pattern3"
?
â Tim
Jun 6 at 3:02
-F
tellsgrep
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), thegrep -rFl -e ...
variant is 10Ã faster than thegrep -rEl ...
variant.
â Stephen Kitt
Jun 6 at 9:14
add a comment |Â
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
, orgrep -rEl "pattern1|pattern2|pattern3"
?
â Tim
Jun 6 at 3:02
-F
tellsgrep
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), thegrep -rFl -e ...
variant is 10Ã faster than thegrep -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
add a comment |Â
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