Filenames and linenumbers for the matches of cat and grep Filenames and linenumbers for the matches of cat and grep unix unix

Filenames and linenumbers for the matches of cat and grep


grep google *.php

if you want to span many directories:

find . -name \*.php -print0 | xargs -0 grep -n -H google

(as explained in comments, -H is useful if xargs comes up with only one remaining file)


You shouldn't be doing

$ *.php | grep

That means "run the first PHP program, with the name of the rest wildcarded as parameters, and then run grep on the output".

It should be:

$ grep -n -H "google" *.php

The -n flag tells it to do line numbers, and the -H flag tells it to display the filename even if there's only file. Grep will default to showing the filenames if there are multiple files being searched, but you probably want to make sure the output is consistent regardless of how many matching files there are.


grep -RH "google" *.php