How Do I Grep a Filename in Linux?
Contents Grep -N ‘String’ Filename: Force Grep to Add Prefix Each Line of Output with the Line Number Within Its Input File. Grep –With-Filename ‘Word’ File or...
Contents
grep -n ‘string’ filename : Force grep to add prefix each line of output with the line number within its input file. grep –with-filename ‘word’ file OR grep -H ‘bar’ file1 file2 file3 : Print the file name for each match.
How do I grep only filenames?
The standard option grep -l (that is a lowercase L) could do this. From the Unix standard: -l (The letter ell.) Write only the names of files containing selected lines to standard output.
Must Read
How do I search for a specific word in a file in Linux?
How to Find a Specific Word in a File on Linux
- grep -Rw ‘/path/to/search/’ -e ‘pattern’
- grep –exclude=*.csv -Rw ‘/path/to/search’ -e ‘pattern’
- grep –exclude-dir={dir1,dir2,*_old} -Rw ‘/path/to/search’ -e ‘pattern’
- find . – name “*.php” -exec grep “pattern” {} ;