1826331 Members
3952 Online
109692 Solutions
New Discussion

Re: find a string

 
SOLVED
Go to solution
Cheung_2
Frequent Advisor

find a string

I would like to find a file that contains a particular word (string) in the system ? Thx.

eg. I would like to know which file(s) in the system contains the word ???Full??? , what can i do?
Andy
7 REPLIES 7
Steven E. Protter
Exalted Contributor

Re: find a string

find / -exec grep -l 'string to fine' {} \;


This command will search the contents of every file in the system for the word in the single quotes.

the / can be a subdirectory to save time.

find command is very CPU/load intensive. Use with care.

Steve
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Systeemingenieurs Infoc
Valued Contributor
Solution

Re: find a string

find / -exec grep 'string' /dev/null {}\;
A Life ? Cool ! Where can I download one of those from ?
Jason Tan
Advisor

Re: find a string

what is the /dev/null do here on the find command?
smtan
Systeemingenieurs Infoc
Valued Contributor

Re: find a string

it forces grep to display the filename. You could try it out on the /tmp to see the difference.

if you do a 'find /', i might be wise to include a '-xdev', so it only searches your '/'. In this way you can search each fs at a time, and avoid overkill.
A Life ? Cool ! Where can I download one of those from ?
H.Merijn Brand (procura
Honored Contributor

Re: find a string

A few things to add.

1. Never do this over NFS (unless you've got loads of spare time for `active waiting')

2. find / -exec grep 'string' /dev/null {}\;
is good, but
find / -type f -exec grep 'string' /dev/null {}\;
is better (think pipes)

3. GNU grep (available on https://www.beepz.com/personal/merijn/ or http://www.cmve.net/~merijn/) can do recursive greps
grep -r 'pattern' /
which is much faster and uses less system resources

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Robin Wakefield
Honored Contributor

Re: find a string

Hi,

You may want to exclude binary files, so you could do something like this:

find / -type f | xargs file | grep -v " shared " | cut -d: -f 1|xargs grep "string to find" /dev/null

Rgds, Robin
q tang
Occasional Contributor

Re: find a string

Hi Cheunq:

I think u can find out each file(even each row in the file) in the system which contains the word(string) u specified by following command:

find / -type f | xargs grep "Full"

Good lucky!

Tang qiang

08/01/03