LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   the command 'grep' is so slow (https://www.linuxquestions.org/questions/linux-newbie-8/the-command-grep-is-so-slow-108692/)

domeili 10-26-2003 10:43 AM

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 ?:confused:

tgflynn 10-26-2003 10:59 AM

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

jrdioko 10-26-2003 11:50 AM

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"

domeili 10-26-2003 09:18 PM

I use the command:
'grep -r switchdesk.png *'

tgflynn 10-26-2003 09:31 PM

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

domeili 10-26-2003 09:44 PM

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

tgflynn 10-26-2003 09:49 PM

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

domeili 10-26-2003 10:07 PM

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!

tgflynn 10-26-2003 10:30 PM

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

emetib 10-26-2003 11:09 PM

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.

jrdioko 10-27-2003 03:24 PM

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?

slakmagik 10-28-2003 03:49 AM

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.

Nimoy 10-28-2003 04:15 AM

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.

iainr 10-28-2003 08:16 AM

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.


All times are GMT -5. The time now is 02:57 PM.