-   Linux - General (
-   -   grep search... (

tobiasw 10-28-2006 11:17 AM

grep search...
is it possible to search with grep for a text pattern, the whole root /?

something like:
grep -i 'test' * or /



druuna 10-28-2006 11:32 AM


I'm not sure which of the 2 you want:

If you only want to check all the files in /:

grep -i 'test' /*

If you need to do this recursive (/ and all the subdirs):

find / -type f -exec grep -i 'test' {} \;

The last command is very (!!) resource unfriendly and will probably run for a while. It would be better to narrow down the field it needs to search.

tobiasw 10-28-2006 11:47 AM

thanks druuna...

can I narrow it down with : find /home/test -type f -exec grep ... ?

druuna 10-28-2006 11:57 AM


Yes you can. There are 2 possibilities:

cd /home/test
find . <whatever>

The . (dot) means: from the current directory.


find /home/test <whatever>

The second one can be executed from any point.

matthewg42 10-28-2006 02:36 PM

GNU grep supports the -r option, which means "recursive". It's a little less cumbersome than using find. e.g. you can grep files in sub-directories specified on the command line, e.g.


grep -r 'mypattern' /home/matthew
Will search all files in sub-directories of /home/matthew for "mypattern". You can search all files on the whole system using / instead of /home/matthew. Note that searching your whole filesystem probably won't be possible unless you run the command as root since many files are not readable by regular users.

Also note that it might be a good idea to run the command with nice since it'll take an age anyway, and you will probably want to minimize impact on other programs as it runs.

All times are GMT -5. The time now is 03:51 PM.