LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-26-2003, 10:43 AM   #1
domeili
LQ Newbie
 
Registered: Oct 2003
Location: china
Distribution: Red Hat Linux 9
Posts: 22

Rep: Reputation: 15
Unhappy the command 'grep' is so slow


I use the command 'grep' to search files that contains 'switchdesk.png' from the starting point '/', but it's too slow and have no messages like windows which shows where the searching process is.So I press Ctrl+c to stop the searching process.But where is the files I want to find ?

Last edited by domeili; 10-26-2003 at 10:53 AM.
 
Old 10-26-2003, 10:59 AM   #2
tgflynn
Member
 
Registered: Oct 2003
Location: Rochester, New York (USA)
Distribution: Debian
Posts: 119

Rep: Reputation: 15
If you're running grep over a very large number of files it will be slow because it needs to open them all and read through them. If you have some idea of where the file you're looking for might be try to limit the number of files that have to be searched through that way.

On the other hand you may be using it wrong and it may be sitting there doing nothing. Please post the exact grep command you used and what you expect it to do.

Tim
 
Old 10-26-2003, 11:50 AM   #3
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Or if you are just trying to find switchdesk.png (e.g. it is a file not a line within a file) try: "locate switchdesk.png"
 
Old 10-26-2003, 09:18 PM   #4
domeili
LQ Newbie
 
Registered: Oct 2003
Location: china
Distribution: Red Hat Linux 9
Posts: 22

Original Poster
Rep: Reputation: 15
I use the command:
'grep -r switchdesk.png *'

Last edited by domeili; 10-26-2003 at 09:19 PM.
 
Old 10-26-2003, 09:31 PM   #5
tgflynn
Member
 
Registered: Oct 2003
Location: Rochester, New York (USA)
Distribution: Debian
Posts: 119

Rep: Reputation: 15
Quote:
Originally posted by domeili
I use the command:
'grep -r switchdesk.png *'
OK this command will for search for the string "switchdesk.png" within all of the files in the directory you are in and all of its subdirectories and sub-subdirectories etc. If the directory hierarchy contains a lot of data, expect it to take a while.

Note that this is not the same as searching for a file whose name is "switchdesk.png". That you can do with this command :

find . -name 'switchdesk.png'

This will be much faster, but its not doing the same thing.

Tim
 
Old 10-26-2003, 09:44 PM   #6
domeili
LQ Newbie
 
Registered: Oct 2003
Location: china
Distribution: Red Hat Linux 9
Posts: 22

Original Poster
Rep: Reputation: 15
I made a experiment .I create a file called 123.txt that contains 'switchdesk.png',and I use the command 'grep -r switchdesk.png / *' .
And now I am waiting for the result ,but I can see nothing on the screen except the flashing cursor.
 
Old 10-26-2003, 09:49 PM   #7
tgflynn
Member
 
Registered: Oct 2003
Location: Rochester, New York (USA)
Distribution: Debian
Posts: 119

Rep: Reputation: 15
You don't want the / before *, that's telling it to search through the whole filesystem !

The command you want is :

grep -r switchdesk.png *

Tim
 
Old 10-26-2003, 10:07 PM   #8
domeili
LQ Newbie
 
Registered: Oct 2003
Location: china
Distribution: Red Hat Linux 9
Posts: 22

Original Poster
Rep: Reputation: 15
I know it ,but I wonder if there is an option the command 'grep' can use to search the whole filesystem quickly and effectively(like windows) or not!

Last edited by domeili; 10-26-2003 at 10:09 PM.
 
Old 10-26-2003, 10:30 PM   #9
tgflynn
Member
 
Registered: Oct 2003
Location: Rochester, New York (USA)
Distribution: Debian
Posts: 119

Rep: Reputation: 15
How exactly would you search through the whole filesystem quickly and effectively in Windows ?

Remember we are talking about searching in the contents of files, not just for filenames.

Tim
 
Old 10-26-2003, 11:09 PM   #10
emetib
Member
 
Registered: Feb 2003
Posts: 484

Rep: Reputation: 33
why don't you just rebuild your locate or slocate db and then locate that file.

as su
slocate -uc
that will rebuild the db from the /

then as user
slocate whateverfile

you'll get what your looking for.
 
Old 10-27-2003, 03:24 PM   #11
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
What is the actual difference between locate and slocate? Every help file and piece of documentation on them seems to be the same. Are they just aliases for the same thing?
 
Old 10-28-2003, 03:49 AM   #12
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
I think locate showed everything on the system and slocate just shows what a user has access to. Maybe some other changes. 'S'ecure 'locate'. Locate was insecure, basically. And locate is a symlink to slocate now, anyway.
 
Old 10-28-2003, 04:15 AM   #13
Nimoy
Member
 
Registered: Jun 2003
Location: Currently Denmark
Distribution: Ubuntu 15.04
Posts: 336

Rep: Reputation: 30
I have to comment on the Windows issue you mention - Searching for specific info within a file through the entire filesystem on Windows is not faster than using the grep command to perform the similar operation - at least not mentionable... haven't tried to perform regular benchmarks though... and don't think you fairly could. But I tried it in regular use and found no difference as such.
 
Old 10-28-2003, 08:16 AM   #14
iainr
Member
 
Registered: Nov 2002
Location: England
Distribution: Ubuntu 9.04
Posts: 631

Rep: Reputation: 30
Quote:
Originally posted by domeili
I know it ,but I wonder if there is an option the command 'grep' can use to search the whole filesystem quickly and effectively(like windows) or not!
I don't know about quick and effective (its all relative) but you could try

find / -exec grep -l 'switchdesk.png' {} \;

Might be quicker.
 
  


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
how to use grep command sharonyiisl Linux - Newbie 7 05-28-2006 03:46 PM
grep command itz2000 Linux - Newbie 2 09-21-2005 07:06 PM
grep command in c????? alnreddy Linux - Software 1 12-30-2004 01:01 AM
Help With GREP Command juliettree Linux - Newbie 3 04-08-2004 08:44 AM
grep command cuss Linux - General 7 02-14-2003 09:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:19 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
Open Source Consulting | Domain Registration