Linux: Using grep to display filenames

0 votes

Is there any way I can use grep just to show the filenames and not anything else. I'm trying this:

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

Do I have to use xargs cause I cannot find anything related to grep to do this?

May 24 in Linux Administration by Damon Salvatore
• 5,510 points
28 views

1 answer to this question.

0 votes

You need t use -l flag with grep(lowercase L). From Unix Docs:

-l
    (The letter ell.) Write only the names of files containing selected
    lines to standard output. Pathnames are written once per file searched.
    If the standard input is searched, a pathname of (standard input) will
    be written, in the POSIX locale. In other locales, standard input may be
    replaced by something more appropriate in those locales.
answered May 24 by ajs3033
• 7,280 points

Related Questions In Linux Administration

0 votes
1 answer

To attach a file using mail command on Linux

$ echo | mutt -a syslogs.tar.gz admin@domain.org READ MORE

answered Jun 28 in Linux Administration by Upasana
• 8,530 points
44 views
0 votes
1 answer

How to display a simple list of all disks, like this /dev/sda /dev/sdb ?

You can list all the disk in ...READ MORE

answered Jul 12, 2018 in Linux Administration by DearestOne
• 200 points
100 views
0 votes
1 answer

How to get octal file permission in linux?

You can use this: stat -c "%a %n" ...READ MORE

answered Jan 3 in Linux Administration by Omkar
• 67,290 points
80 views
0 votes
1 answer

How to create a symlink in Linux?

To create a symbolic link, you can ...READ MORE

answered Jan 31 in Linux Administration by Omkar
• 67,290 points
57 views
0 votes
1 answer

Unable to access Jenkins. I newly installed Jenkins but for some reason I cannot access it.

Try changing the port, Change JENKINS_AJP_PORT="xyz" to JENKINS_AJP_PORT="abc" If changing the ...READ MORE

answered Jul 4, 2018 in Jenkins by Sophie may
• 9,530 points
235 views
0 votes
2 answers

How do I find all files containing specific text on Linux?

grep -rnw 'text to find recursively inside ...READ MORE

answered May 20 in Linux Administration by Ritesh Singh
3,843 views
0 votes
1 answer
0 votes
1 answer

Grep across multiple files in Hadoop

You are looking to applying to grep ...READ MORE

answered Jan 7 by Frankie
• 9,810 points
844 views
0 votes
1 answer

How to send mail using linux shell script?

If you've already configured the server, with ...READ MORE

answered Jun 11 in Linux Administration by ajs3033
• 7,280 points
27 views
0 votes
1 answer

how to loop through the content of a file using bash

One of the ways to do it ...READ MORE

answered Feb 15 in Linux Administration by ajs3033
• 7,280 points
66 views