Home How can I use grep to show just filenames (no in-line matches) on Linux?

# How can I use grep to show just filenames (no in-line matches) on Linux?

user8140
1#
user8140 Published in September 19, 2018, 6:46 pm

How can I use grep to show just file-names (no in-line matches) on Linux?

I am usually using something like:

find . -iname "*php" -exec grep -H myString {} \;


How can I just get the file-names (with paths), but without the matches? Do I have to use xargs? I didn't see a way to do this on my grep man page.

• You mean, you want the filenames that have at least one match? – leonbloy Jul 9 '11 at 22:27
• Great question. I actually started using this to open a list of files returned by grep in Vim. vim \$(grep -rl Something app/) – David Tuite Mar 20 '13 at 10:49
• You cannot list files using grep command, it is basically used to fetch desired text from a file or a list. For instance, ps aux | grep 'apt-get' or grep 'text-to-find' /path/to/file/ – iamjayp Mar 17 '17 at 8:09