Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, What is the syntax to search f

Status
Not open for further replies.

dshaw21369

Programmer
Jul 8, 2002
64
Hi,
What is the syntax to search for a phrase inside of a file?
for example if I want to search for First name in several files in on the server under root?
 
man grep.

grep "First name" file1 file2 file3

or

grep -i "first name" file1 file2 file3

The -i tells grep to ignore case.

you also can use * for the filenames.
 
what if I want to return all the files that contain the phrase?

 
You mean, like you don't know the filenames?

grep -i "first name" *

from the directory where the files are.

If you don't know which directory they are in, you could do

find / -print | xargs grep -i "first name"

Be aware that a find like that will eat resources.
 
From 'man grep'

-l Only the names of files with matching lines
are listed (once), separated by newlines.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top