I need to find all instances of 'filename.ext' on a linux system and see which ones contain the text 'lookingfor'.
Is there a set of linux command line operations that would work?
I need to find all instances of 'filename.ext' on a linux system and see which ones contain the text 'lookingfor'.
Is there a set of linux command line operations that would work?
A more simple one would be,
-print0 to find & 0 to xargs would mitigate the issue of large number of files in a single directory.
Try:
find
searches recursively starting from the root/
for files namedfilename.ext
and for every found occurrence it runs grep on the file name searching forlookingfor
and if found prints the line number (-n
) and the file name (-H
).Go to respective directory and type the following command.
Using a
+
to terminate the command is more efficient than\;
becausefind
sends a whole batch of files togrep
instead of sending them one by one. This avoids a fork/exec for each single file which is found.A while ago I did some testing to compare the performance of
xargs
vs{} +
vs{} \;
and I found that{} +
was faster. Here are some of my results:I find the following command the simplest way:
or add
-i
to search case insensitive: