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
-r
means search recursively, so grep
will exhaustively search through all subdirectories in /home/alice
.-n
means provide the line numbers of matches.-w
means 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:
/home/alice/helloworld.py:3:print("hello world")
To learn more about grep
, open its manual page by entering man grep
.