LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 04-29-2011, 03:17 AM   #1
kienlarsen
Member
 
Registered: Apr 2011
Posts: 76

Rep: Reputation: 0
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?

Last edited by kienlarsen; 04-29-2011 at 03:18 AM.
 
Old 04-29-2011, 03:28 AM   #2
Thor_2.0
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,203
Blog Entries: 23

Rep: Reputation: 279Reputation: 279Reputation: 279
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
 
1 members found this post helpful.
Old 04-29-2011, 05:06 AM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,471

Rep: Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888
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.
 
1 members found this post helpful.
Old 04-29-2011, 05:23 AM   #4
vickyk
Member
 
Registered: Dec 2009
Posts: 38

Rep: Reputation: 6
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.
 
1 members found this post helpful.
Old 04-29-2011, 06:43 AM   #5
j1alu
Member
 
Registered: Apr 2009
Distribution: debian gnu/linux
Posts: 798

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 04-29-2011, 11:37 AM   #6
kienlarsen
Member
 
Registered: Apr 2011
Posts: 76

Original Poster
Rep: Reputation: 0
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.
 
Old 04-29-2011, 01:29 PM   #7
jthill
Member
 
Registered: Mar 2010
Distribution: Arch
Posts: 209

Rep: Reputation: 65
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.
 
1 members found this post helpful.
Old 04-30-2011, 07:41 AM   #8
kienlarsen
Member
 
Registered: Apr 2011
Posts: 76

Original Poster
Rep: Reputation: 0
Thanks to everyone!
 
Old 04-30-2011, 12:45 PM   #9
Thor_2.0
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,203
Blog Entries: 23

Rep: Reputation: 279Reputation: 279Reputation: 279
Quote:
Thanks to everyone!
You're welcome!
 
Old 05-02-2011, 11:14 AM   #10
kienlarsen
Member
 
Registered: Apr 2011
Posts: 76

Original Poster
Rep: Reputation: 0
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?
 
Old 05-02-2011, 08:39 PM   #11
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
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'
 
Old 05-03-2011, 07:28 AM   #12
kienlarsen
Member
 
Registered: Apr 2011
Posts: 76

Original Poster
Rep: Reputation: 0
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".
 
Old 05-03-2011, 07:59 AM   #13
rizzy
Member
 
Registered: Mar 2004
Distribution: Debian
Posts: 283

Rep: Reputation: 65
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.
 
Old 05-03-2011, 08:35 AM   #14
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 3,894

Rep: Reputation: 774Reputation: 774Reputation: 774Reputation: 774Reputation: 774Reputation: 774Reputation: 774
Quote:
Originally Posted by chrism01 View Post
'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.
 
Old 05-03-2011, 01:57 PM   #15
kienlarsen
Member
 
Registered: Apr 2011
Posts: 76

Original Poster
Rep: Reputation: 0
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?
 
  


Reply

Tags
find, locate, updatedb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Find not searching subdirectories JosephS Linux - Software 6 07-12-2010 10:16 PM
Searching for JDK using find mconstant Linux - Newbie 5 11-20-2008 10:08 AM
'locate' utility can't find db imputerate Linux - Newbie 9 05-26-2008 05:52 AM
Find/locate an exact file stefaandk Linux - General 2 12-27-2005 07:56 AM
cannot find a kernel, please locate one bobotoes Linux - Newbie 2 10-07-2004 06:15 PM


All times are GMT -5. The time now is 01:58 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration