LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 10-28-2006, 11:17 AM   #1
tobiasw
Member
 
Registered: Oct 2006
Distribution: Fedora Core
Posts: 58

Rep: Reputation: 15
grep search...


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

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

thanks


Tobias
 
Old 10-28-2006, 11:32 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

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.
 
Old 10-28-2006, 11:47 AM   #3
tobiasw
Member
 
Registered: Oct 2006
Distribution: Fedora Core
Posts: 58

Original Poster
Rep: Reputation: 15
thanks druuna...

can I narrow it down with : find /home/test -type f -exec grep ... ?
 
Old 10-28-2006, 11:57 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Yes you can. There are 2 possibilities:

cd /home/test
find . <whatever>


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

or

find /home/test <whatever>

The second one can be executed from any point.
 
Old 10-28-2006, 02:36 PM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
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.

Code:
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To recursively search with grep grautu Slackware 5 11-21-2005 03:53 AM
can you specify which files to grep search? sneakyimp Linux - Software 4 10-12-2005 09:28 PM
How to search and replace a text using grep DediPlace Linux - General 2 05-29-2005 07:47 PM
Using Grep to search all sub-directories yrraja Solaris / OpenSolaris 2 08-28-2004 04:29 AM
Grep for search, but what for replace? TheSpecial Linux - Software 18 04-28-2003 10:01 AM


All times are GMT -5. The time now is 12:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration