Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grep listing filenames without content

Tags:

grep

search

How can we list only filenames after searching using grep?

When I use

grep -i -R "search keyword" folder

it'll list all the inline lines of code also.


2 Answers

From grep man page:

-L, --files-without-match Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.

-l, --files-with-matches Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. (-l is specified by POSIX.)

For you, -l option would be helpful.

like image 96
Rakholiya Jenish Avatar answered Oct 29 '25 08:10

Rakholiya Jenish


Use

grep -i -R -l "search keyword" location

to get the list of files which contain the keyword.

like image 35
Aswathy Avatar answered Oct 29 '25 09:10

Aswathy