Using Linux, how can I find all files containing a specific string of text?
You can do this using
grep, a search utility built into most distributions of Linux. For example, to search for the string “hello world” in the files stored under
/home/alice, you can use this command:
grep -rnw "hello world" /home/alice
-rmeans search recursively, so
grepwill exhaustively search through all subdirectories in
-nmeans provide the line numbers of matches.
-wmeans match whole words. This means that the search will not match constructions like “ghello worldy”.
This command should provide output like the following, specifying the file, the line number, and the matched line:
To learn more about
grep, open its manual page by entering