Need help finding file contents in Linux

I'm having trouble with the find/grep syntax to find files that contain a certain string.

I've got a CentOS Linux server and when I do the first command command, I get a list of a whole bunch of files as expected. But when I do the second command, I get nothing.
find ./home/mark/domains/ -name *.php -print0
find ./home/mark/domains/ -name *.php -print0 | xargs grep '<head>'

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Search many files for a string. This example finds the string "searchthis." This is useful when I want to find, say, a CSS class name that has changed, and update it in all of my .js, .jsp and .jspf files.

The -niP argument to grep is optional. -n prints line numbers, -i makes search case-insensitive, and -P toggles Perl regular expression syntax.

find \ ( -name "*js" -o -name "*jsp" -o -name "*jspf" \) | xargs grep -niP 'searchthis'
madunix (Fadi SODAH)Commented:
i use the following with my php files, i search first the text take back of files before the replace the old with new ...

cd directory
find . -type f -exec grep -rH <pattern> {} \;
find . -name "*.php" -exec sed -i".bck" -e 's/oldpattern/newpattern/g' {} \;
If you're just searching a directory tree for .html or .php files (for instance) then I have to say give jEdit a try. It's "search in directory" feature is superb.

You can search and replace using regular expressions, which makes finding complex string groups a cinch, and replacing blocks of old code with new code very easy.

Not exactly what you were after, but definitely worth a look if this is about finding text in your text and config files.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

 use "-print" instead of -print0 and "xargs -n1" instead of "xargs"  alone.
... alternatively, with "-print0" use "xargs -0"

-print0 outputs null-separated strings, xargs needs "-0" to recognize this.
markgoodallAuthor Commented:
Okay, so far this works... almost..... it shows me the line contents, but not the name of the file it was in.

find ./home/mark/domains/ -name *.php -print | xargs -n1 grep '<head>'

Open in new window

find ./home/mark/domains/ -name *.php -print | xargs -n1 grep -H '<head>'

"-H" will print the filename for each match.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.