Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Grep: How can I only show file names that contain a pattern?

To use grep to only show file names that contain a specific pattern, you can use the -l (lowercase "L") option. This option tells grep to only print the names of the files that contain the pattern, rather than printing the matching lines themselves.

Here's an example:

grep -l "pattern" *.txt

This will search for the pattern "pattern" in all files with the ".txt" extension in the current directory, and will only print the names of the files that contain the pattern.

Note that if you want to search recursively through all files in a directory and its subdirectories, you can use the -r option:

grep -rl "pattern" /path/to/directory

This will search for the pattern "pattern" in all files in the specified directory and its subdirectories, and will only print the names of the files that contain the pattern.

Regenerate response

Grep: How can I only show file names that contain a pattern?

To use grep to only show file names that contain a specific pattern, you can use the -l (lowercase "L") option. This option tells grep to only print the names of the files that contain the pattern, rather than printing the matching lines themselves.

Here's an example:

grep -l "pattern" *.txt

This will search for the pattern "pattern" in all files with the ".txt" extension in the current directory, and will only print the names of the files that contain the pattern.

Note that if you want to search recursively through all files in a directory and its subdirectories, you can use the -r option:

grep -rl "pattern" /path/to/directory

This will search for the pattern "pattern" in all files in the specified directory and its subdirectories, and will only print the names of the files that contain the pattern.

Regenerate response