HowTo: grep All Sub-directory For Files

https://w‮l.ww‬autturi.com
HowTo: grep All Sub-directory For Files

To search for a pattern in all files in a subdirectory and its subdirectories using the grep command 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