HowTo: Use Grep Command In Unix / Linux To Search Subdirectories

https:‮ww//‬w.lautturi.com
HowTo: Use Grep Command In Unix / Linux To Search Subdirectories

To use the grep command to search for a pattern in subdirectories in Unix or Linux, you can use the -r or --recursive option.

For example, to search for the pattern "test" in all files in the current directory and its subdirectories, you can use the following command:

grep -r "test" .

This will search for the pattern "test" in all files in the current directory and its subdirectories, and print the name of each file that contains the pattern along with the matching lines.

You can also use the -H or --with-filename option to print the name of the file before each matching line. For example:

grep -rH "test" .

You can also use the -n or --line-number option to print the line number before each matching line. For example:

grep -rHn "test" .

You can also use the -l or --files-with-matches option to print only the names of the files that contain the pattern, without printing the matching lines. For example:

grep -rl "test" .
Created Time:2017-10-29 22:08:46  Author:lautturi