Operating System - HP-UX
1832978 Members
2662 Online
110048 Solutions
New Discussion

find a word in the system

 
SOLVED
Go to solution
juno2
Super Advisor

find a word in the system

I want to find a word "hello" in my whole system , if i just use
# grep -i "hello" , it will only find the files in the specific system but not to each subdirectories , can suggest what can i do ? thx.
6 REPLIES 6
juno2
Super Advisor

Re: find a word in the system

may be my question is not very clear,
I want to find the files that contains the word "hello" in my whole system ( include all sub-directories) , can suggest what can i do ? thx.
twang
Honored Contributor
Solution

Re: find a word in the system

To grep in all files in subdirs:
grep */
or using find:
find . -type f -exec grep -i pattern {} \;
Rajeev  Shukla
Honored Contributor

Re: find a word in the system

Hi Juno2,

Use the find option with..
find / -type f -exec grep -i hello {} \;

the left hand will list the files that have word hello.
Or redirect this to a fine and grep the first word like
awk -F ":" '{print &1}'

cheers
Rajeev
Bruno Ganino
Honored Contributor

Re: find a word in the system

john korterman
Honored Contributor

Re: find a word in the system

Hi,
find / -type f | xargs grep -i hello

regards,
John K.
it would be nice if you always got a second chance
Bhuvaneswari Selvaraj
Valued Contributor

Re: find a word in the system

cd /
find . -type f -exec grep -i "hello" {} \; -print 2>/dev/null

-print option is needed so that the file name in which the character is found is also printed.

In grep, include the -i option if you want to ignore case... Hello, hEllo and so on will also be searched for. If you want only hello then just give
cd /
find . -type f -exec grep "hello" {} \; -print 2>/dev/null

if your are not the root user, you will not have search permission on many dirs and hence will see lots of permission denied errors and so redirect the error 2>/dev/null will give you a clean output