Koozali.org: home of the SME Server

grepping entire disk stalls??

Offline steve288

  • *
  • 336
  • +0/-0
grepping entire disk stalls??
« on: June 15, 2011, 05:01:30 PM »
I have a system with about 80 Gigs. However considerably less actually has data on it. It just has the sme software on it and a few add on's.

Sometimes I want to find a text string so that I can figure out where a certain program is on the system.

I try to run grep -l -r "string" / >$HOME/out.txt

and it works for a while but then seems to stop. I ran it all night long and then looked at the out.txt and it had the same file that I saw in it last night. Now thats ok, maybe there is only one file with the string. But the program doesnt finish, eg it does not give me the command prompt back on the terminal window.

I have tried to use top to see the program but cant figure out how to just have my command show up. So it must be somewhere near the bottom of the listing. I have also use ps -ef |grep grep   but the numbers never seem to change for the grep command.

I thought well how about trying  grep -L -r "string" /var   so I can see if its working. This prints out the files that DONT contain the string.
It now seems to be sitting at the last file which is /var/service/ulogd/log/supervise/pid
and it has been here for 1/2 an hour. This is a XEON processor.

I recognize that grepping is long process and doing the whole disk may not be the best Idea but sometimes you have to search the whole disk to find what you want.

Can anyone provide any help on how to search the whole disk. I think in my case it "seems" to be giving up along the way. (I have also tryed mc but I think ? the same thing happens). Maybe it is working and IM just not patient. But I dont think it is ??

Thanks.

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: grepping entire disk stalls??
« Reply #1 on: June 15, 2011, 05:22:24 PM »
I recognize that grepping is long process and doing the whole disk may not be the best Idea but sometimes you have to search the whole disk to find what you want.

I don't believe you.

Your grep has probably stalled trying to read from .../supervise/control, which is a fifo, not a regular file.

Quote
Sometimes I want to find a text string so that I can figure out where a certain program is on the system.

If you know the name of the program, then you can do one of:

find / -xdev -print | grep xxx

or

updatedb
locate xxx

If you want to find the program containing a particular string, then I suggest you just search where programs are actually found - usually in the directories identified by $PATH.

If you really want to do an exhaustive search, you can use:

find / -xdev -type f -executable -print | xargs grep xxxx

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: grepping entire disk stalls??
« Reply #2 on: June 15, 2011, 05:52:00 PM »
If you know the name of the program, then you can do one of:

find / -xdev -print | grep xxx
Why bother grepping where you can use text based or regex matching?

For example:

Code: [Select]
[root@smetest ~]# find / -xdev -iname *templates-user-custom*
/etc/e-smith/templates-user-custom
[root@smetest ~]

or

Code: [Select]
[root@smetest ~]# find / -xdev -iregex .*custom$
/etc/e-smith/templates-user-custom
/etc/e-smith/templates-custom
[root@smetest ~]#

@steve288: There are a lot more very helpfull switches for the find command, you can get help using the following command:

Code: [Select]
man find(You can quit with q after your are done reading)
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline steve288

  • *
  • 336
  • +0/-0
Re: grepping entire disk stalls??
« Reply #3 on: June 15, 2011, 06:06:56 PM »
Thanks CB.
I'm not sure which part you dont believe.
That it takes a long time,
That its not the best Idea
Or that I need to search the whole disk sometimes :>

Thanks for the commands.
I use the locate all the time. Wonderfull command. The updatedb, I have either set up to run every day or its done automatically cant remember now.

Normally what IM looking for is either data in users files or where some script or some aspect of the web manager is administered. So yes I want to look into the file. Binary files are normally not my interest as far as snooping into them.

I will try your command. However your command ...
find / -xdev -type f -executable -print | xargs grep xxxx

Is the -executable right? I cant see any documentation on this and indeed when I run it, it fails. Perhaps you ment -exec but Im not quite sure what it would do since I think (If I understand it ) you are piping it to xargs grep so dont need to -exec anything?

I'm just asking. Your the guru IM the grasshopper.

Thanks.

Offline steve288

  • *
  • 336
  • +0/-0
Re: grepping entire disk stalls??
« Reply #4 on: June 15, 2011, 06:17:51 PM »
Thanks cactus,

I suppose there is more than one way to skin a cat or um cat a file.

For what ever reason, I think we learn commands long ago (Xenix and Unix) and keep using them. I have never learned the find command very well and always stick to good old grep or egrep. (perhaps to my detriment) I think frankly I always got confused between the find command in dos and unix and steered clear to reduce the confusion. The -regex looks like something that I should learn... if I can. It sure can do a lot.

Thanks.

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: grepping entire disk stalls??
« Reply #5 on: June 15, 2011, 07:36:37 PM »
I'm not sure which part you dont believe.
...
Or that I need to search the whole disk sometimes :>

This.
 
Quote
Normally what IM looking for is either data in users files

... so only search in users files - all contained within /home/e-smith/files/.

Quote
or where some script or some aspect of the web manager is administered

... all contained within /etc/e-smith/web and /usr/lib/perl5/site_perl/esmith.

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: grepping entire disk stalls??
« Reply #6 on: June 15, 2011, 07:37:47 PM »
Is the -executable right? I cant see any documentation on this and indeed when I run it, it fails.

Sorry, that is only available in a later version of find.

Offline steve288

  • *
  • 336
  • +0/-0
Re: grepping entire disk stalls??
« Reply #7 on: June 15, 2011, 07:51:33 PM »
Thanks.