LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-04-2004, 05:38 AM   #1
vous
Member
 
Registered: Mar 2003
Location: Macondo
Distribution: Mandrake 9.1, 10.1, SuSE 8.1 pro, 10.1, Red Hat 8.0/9.0
Posts: 380

Rep: Reputation: 30
How to search for a string throughout the whole system?


I want to search for a string throughout my whole system, but I tried it with:

grep "XXXXXX" /*

and

grep "XXXXXX" /*.*

Anybody that can help me out with the command format?
 
Old 02-04-2004, 06:02 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
One way:
Code:
find / -name \* -exec grep "XXXXXX" {} \;
 
Old 02-04-2004, 07:50 AM   #3
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
Code:
grep -R "XXXXXX" /*
Should work. You have to specify that it needs to recurse through all directories. But if you want to avoid some nastiness that may happen with devices, then using an extension of jim's find command would help:

Code:
find / -type f -exec grep "XXXXXX" {} \;
At least, I think that'll avoid trying to grep devices...
 
Old 02-04-2004, 07:59 AM   #4
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
and that'll keep it from searching /proc too, which is good, unless you're cracking.

grepping a FIFO (like /dev/mouse) can take a while. as long as you're willing to wait actually. that's why you don't want to grep devices. if you want to search empty file space for text, you may actually want to grep a device, like the hard drive, or a floppy.
 
Old 02-04-2004, 09:34 AM   #5
vous
Member
 
Registered: Mar 2003
Location: Macondo
Distribution: Mandrake 9.1, 10.1, SuSE 8.1 pro, 10.1, Red Hat 8.0/9.0
Posts: 380

Original Poster
Rep: Reputation: 30
Well...it actually didn't keep it from /proc or other binary files. I let it run for a while, and then all of a sudden my DNS got screwed up?!?!! I couldn't resolve any names anymore?!??! I don't know what happend, I just know the last message I saw on screen was something like...

.
.
.
Binary file /proc/XXX
.
.
.

and that was the end of my system. I rebooted and everything worked again, but it was scary!

Anyways, I ran it again, but not from / but to /usr/local/joe and it found the string and it returned it on screen, but it didn't say in which file? So it basically spat back what I put in the search string.

Any other ideas?
 
Old 02-04-2004, 09:49 AM   #6
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
add a --with-filename after grep and before the pattern, and it'll print:
Code:
filename:line that matches the pattern
 
Old 02-04-2004, 09:57 AM   #7
vous
Member
 
Registered: Mar 2003
Location: Macondo
Distribution: Mandrake 9.1, 10.1, SuSE 8.1 pro, 10.1, Red Hat 8.0/9.0
Posts: 380

Original Poster
Rep: Reputation: 30
Right on!

Thank you guys!
 
Old 02-04-2004, 12:03 PM   #8
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
me big dum dum.
the -mount option would keep find in the same filesystem.

find / -type f -mount -exec grep -H -n pooperscooper {} \;

the -H is the same as the --with-filename and
the -n prints the line number to make it easier to find the match.
 
Old 02-04-2004, 12:38 PM   #9
vous
Member
 
Registered: Mar 2003
Location: Macondo
Distribution: Mandrake 9.1, 10.1, SuSE 8.1 pro, 10.1, Red Hat 8.0/9.0
Posts: 380

Original Poster
Rep: Reputation: 30
whansard, I have to ask it....

What you have here on your side profile:

"Distribution: RH 6.2, Gen2, Knoppix, Pnut, Mand 8, Suse 8.1, Win3.1,95,98,2000,NT4,+ on 1 drive"

Are you really running all those O.S.s in ONE drive?!?!
 
Old 02-04-2004, 11:11 PM   #10
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
i had more than that on here, but i recently archived and repartitioned a bunch of stuff to make some free space. i just dumped netbsd, freebsd, and openbsd. i used to have more than 50 OS's spread over 2 drives, but after a bunch of other people started doing it, so it wasn't a big deal anymore, i cut back.
i had to keep stuff written down on a pad to keep track of what was where.
even back in 1992 i had 2 versions of dos and linux on a 40 meg hard drive.
all i could do in linux was ls, cat, and textris, and i couldn't get out of vi if started it, if i remember correctly.

there is a multiple linux for development howto that shows how to put many copies
of linux on 1 partition, and after i started doing that, i didn't need all the partitions.
The multiple bsd's was the hardest thing. and solaris screwed up my partition table, but i fixed it, and solaris would still boot.

i really only use redhat 6.2. well, it used to be redhat 6.2. the only thing it has in common with redhat 6.2 is that the login screen says it is. anyway, it was just a little bragging.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
search for a string in c alaios Programming 1 07-07-2005 04:50 PM
C....Search a string for a string Scrag Programming 4 06-14-2004 04:15 PM
[c++] Search in a string hylke Programming 5 06-14-2004 11:20 AM
string search in C h/w Programming 17 10-13-2003 06:26 PM
Search for a string TheOriginalH Linux - General 5 09-24-2003 10:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:34 AM.

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
Open Source Consulting | Domain Registration