Use the -r
and -R
flag to recursively search through directories.
The only difference between the two is -R
will follow symlinks in subdirectories.
Let’s suppose we have a subdirectory called alpha
with a file
named alpha.txt
that contained the following:
// Located in ./alpha/alpha.txt
Hello alpha!
Use an asterisk to search through all files in the current directory.
$ grep "Hello" *
grep: alpha: Is a directory
Since alpha
is a directory, use the -R
flag to recursively search through it.
$ grep -R "Hello" *
alpha/alpha.txt:Hello alpha!