I'm trying to locate the files which contain certain pattern, so I use grep -ir 'pattern' .
to search all files under current directory. But I don't want to see the content of each file, I only need the path/filename. How can I do that?
Ps: Because some JSON file contains very long text in one line, then it will occupy the whole screen. I don't want to filter out those JSON files, because that's what I'm trying to locate
In order to get only filenames, we can enable the -l or the --files-with-matches flag.
If you want to find in all files of a directory, you can use grep -r /path/to/directory .
You can make grep search in all the files and all the subdirectories of the current directory using the -r recursive search option: grep -r search_term .
To search all files in the current directory, use an asterisk instead of a filename at the end of a grep command. The output shows the name of the file with nix and returns the entire line.
grep -l
will output JUST the names of files which matched, without showing the actual match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With