Which is the fastest search method in linux to search (only) for a text inside whole linux file system (NOT JUST A SINGLE FILE) the search needs to be performed on all the files including the root binaries.
Asked
Active
Viewed 4,056 times
2
-
1Check out this StackOverflow thread: https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on-linux – Maximillian Laumeister Sep 20 '18 at 20:47
-
Do you need to print the content that matches from each file or just list the files that contain at least one match ? – don_crissti Sep 20 '18 at 21:18
1 Answers
1
I don't think you can find a faster way than a recursive grep
:
grep -r foo /
That will search through each and every file on your file system for the word foo
. You can speed it up a little by telling it to match only once per file with -m
:
grep -rm 1 foo /
That way, if it finds a match in a file, it will print the matched line and move on to the next file, so it doesn't need to process the entire file each time, but it will always be slow unless you can somehow limit the number of files you want to search.

terdon
- 242,166
-
I would recommend limiting that to directories where there is a higher likelihood of finding anything, never-mind what you're looking for. Specifically, depending on the flavor of Linux you're using, you're likely to waste some considerable time searching the "/dev" directory (devices) and the "/proc" directory (processes) among other places unlikely to match what you're looking for. – UncaAlby Sep 21 '18 at 03:15