Operating System - HP-UX
1827444 Members
6224 Online
109965 Solutions
New Discussion

Re: Searching for text in a file

 
Susan W Roden
Contributor

Searching for text in a file

How do I search from root login for a specific word located in a file. I don't have any idea what file or what directory. I think it has something to do with the STRINGS command but I'm not sure.
3 REPLIES 3
Rick Garland
Honored Contributor

Re: Searching for text in a file

If this is a text file, you can use grep. Various options are available in using grep, check the man page.

grep -l filename

Here it will output the names of the file that contain the pattern you are looking for. Again, check the man pages for the options you might want to use.
Daniel Correa
Advisor

Re: Searching for text in a file

You coud use the find command to a directory or the whole system depending on where you start. You could use;

find / -type f -exec grep -il {search_string} {} \;

This will give you the file names where the string appears. You can then use grep if a textfile, or strings if a binary, to look at each file
David Rodman
Frequent Advisor

Re: Searching for text in a file

If it is a binary file then strings can help.
You may want to combine the methods discussed try:
strings /etc/uname | grep license
it gets every occurance of the string "license"
Add in find and you can search the disk.