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
bash Copy code 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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-04-26 15:34:23 +0000
Seen: 19 times
Last updated: Apr 26
I want to grep for "```*" in a File, in other Words: "```" followed by any Word
How can I fix error: Security violation, ping RPC from uid 1001 in Slurm log?
How can I show all files that do not contain a pattern?
How can I print all but the first 1000 Lines from a File in Bash?
Bash Script that checks if a Host is available or not?
How can I check the expiry of a SSL certificate in the Command Line?
How can I only get the Column with the Filename from a ls -all output with Awk?
What is the Difference of "source script.sh" and "./script.sh" in Bash?