LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Searching in Linux: locate vs. find (http://www.linuxquestions.org/questions/linux-newbie-8/searching-in-linux-locate-vs-find-877774/)

kienlarsen 04-29-2011 04:17 AM

Searching in Linux: locate vs. find
 
Hi, it's late night, and I'm on disk searching commands with my unixacademy DVD training. It primarily discusses two search tools: locate and find.
I understand the difference between two. What I'm asking is, I don't see "locate" to be much used as "find". I read few books and most of them discuss "find", but not "locate". I also searched on forums, most questions about "find".
What I'm asking: is "locate" a general mainstream or some kind of "exotic" command?

Thor_2.0 04-29-2011 04:28 AM

Quote:

What I'm asking: is "locate" a general mainstream or some kind of "exotic" command?
No, Find and Locate are two different things, the one (locate) uses a database to find stuff, after indexing the system, find just does an old search on the disk...

Quote:

Hi, it's late night, and I'm on disk searching commands with my unixacademy DVD training
Good luck with the training, and ... get some sleep too, will ya... ;)

Thor

grail 04-29-2011 06:06 AM

Well I am not so sure about locate, but find has a lot strength due to not only all the things it can do but also the exec options make it extremely powerful.
Also, locate is not generally considered standard fare on all distros.

vickyk 04-29-2011 06:23 AM

locate is useful when the database in which it has indexed all the files are up-to-date.

To update the database, use the command
updatedb

If the database is updated then locate will work faster than find command.

Note:
If you are running a "updatedb" after very long time then it will take some time to complete.

find on other hand is much more powerful and can be combined to search for very specific needs.

j1alu 04-29-2011 07:43 AM

I usually use "locate" (one reason is that "find" is above me). For me it works very well.
But it is from the same "family" of tools:
http://www.gnu.org/software/findutil...mono/find.html
So no, it is not exotic, but most people seem to prefer find.

kienlarsen 04-29-2011 12:37 PM

Hi guys, what I'been asking, is "locate" is generally accepted tool? I mean, I'm learning and IT IS ALL NEW TO ME. From my past Windows trainings I remember that various brands tend to present their own, proprietary solutions and push them for you to use. That is my only concern.

jthill 04-29-2011 02:29 PM

locate is one of the fundamental tools, beyond just 'accepted'.

So far as people pushing "brand" software regardless of quality, stop worrying. Shed a tear of relief, even: FOSS exists as a standing rebuke to that whole business model.

kienlarsen 04-30-2011 08:41 AM

Thanks to everyone!

Thor_2.0 04-30-2011 01:45 PM

Quote:

Thanks to everyone!
You're welcome!

kienlarsen 05-02-2011 12:14 PM

I've been experimenting a lot with "find" and I've got one question. It appears that find is really heavy on resources, at least on my laptop. I created a huge fake data and directory structure, with many thousands files just for sake of experimentation, and I run "find" against it. I also watch my system utilization with "top" is another terminal and there's clear "spike" in utilization when "find" runs.
My question is, is is always like that? Isn't it possible to index its known paths?

chrism01 05-02-2011 09:39 PM

Quote:

Isn't it possible to index its known paths?
that's what the updatedb/locate combo is for. NB: AFAIK, it's Linux thing; ie not avail on eg Solaris, HP-UX etc.
'find' OTOH is a basic Unix cmd from way back when. When updatedb is run, it does essentially the same thing as find, but stores the results. You cannot do that with find, unless you want to write your own version of 'updatedb/locate' :)

kienlarsen 05-03-2011 08:28 AM

I understand that, but "find" allows for setting conditional searches, by file size, date and many other. I don't see how it may be possible with "locate".

rizzy 05-03-2011 08:59 AM

Helpful thread, i didn't know the difference between the two commands.

How does whereis command differ from find and locate? Does it use updatedb? i read man page, but still don't get it 100%.

Code:


DESCRIPTION
      whereis locates source/binary and manuals sections for specified files.
      The  supplied  names  are first stripped of leading pathname components
      and any (single) trailing extension of the form .ext, for example,  .c.
      Prefixes  of  s.  resulting  from  use of source code control are also
      dealt with.  whereis then attempts to locate the desired program  in  a
      list of standard Linux places.


salasi 05-03-2011 09:35 AM

Quote:

Originally Posted by chrism01 (Post 4344550)
'find' OTOH is a basic Unix cmd from way back when. When updatedb is run, it does essentially the same thing as find, but stores the results.

What updatedb stores is just the paths to the files....no file sizes, modification times, etc, etc. So, there is a lot of stuff that you can do with find (as an example, finding files with a modification date that falls inside a particular date range) that you just can't do with locate.

On the other hand, locate is fast. Find, particularly if you are searching over a whole file system isn't, but it is, or can be, clever.

Even if locate doesn't directly do what you want, provided that you only need the file name to do whatever it is, you can often do it by feeding the output of locate through, eg, grep to filter the output more, and still be finished before find has really got going.

kienlarsen 05-03-2011 02:57 PM

Is there another omnipresent tool for conditional file search, one that offers as many options as "find", but as fast as "locate"? My Unix Academy training DVD teaches these two, or there's always a trade-off speed vs. flexibility?


All times are GMT -5. The time now is 04:46 PM.