Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-07-2004, 11:23 AM   #1
LQ Newbie
Registered: Jun 2004
Posts: 5

Rep: Reputation: 0
How to use locate command

How do I search for a file with locate (slocate actually)? My problem is if I want to search for a file with a small name like ld, I get every file that has 'ld' somewhere in the name. How can I say 'I want the file that is named *exactly* ld'? Does locate not handle this? I know about the find command, but locate seems much simpler if I could just get it to work. Thanks.
Old 06-07-2004, 11:36 AM   #2
jim mcnamara
Registered: May 2002
Posts: 964

Rep: Reputation: 36
You will have to use regular expressions that return fewer hits.
will find all files that start with ld for example.

locate and slocate are really meant to find files based on parts of the name,
find is a better choice when you know the whole name.

unix tools usually do one thing very well. So, if you are using a tool that doesn't do the job, you are probably using the wrong tool.
Old 06-07-2004, 02:19 PM   #3
LQ Newbie
Registered: Jun 2004
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks Jim. Actually, I couldn't get locate [^ld] to work (or locate -r [^ld]). But I guess I'll stick to find, although I wonder if find will be as fast...let me, find / -name test123 -print is a lot slower than locate test123. Wait a minute... now locate test123 doesn't even work...

How does locate work exactly? I've read the man page, and there's something about creating the database. Am I supposed to create a database before using it? But it was working before..maybe I corrupted it? I created a new file, test123, then did locate test123 and it didn't find it, then did ls test123 and its there.

Anyone know what I'm doing wrong here? I could just stick to using find, but when locate was working for me it seemed to be pretty fast so I'd like to use locate. Thanks.
Old 06-07-2004, 02:59 PM   #4
Registered: Oct 2003
Location: Iowa
Distribution: LFS 5.0, building 6.3, win98se, multiboot
Posts: 288

Rep: Reputation: 30
Every so often you have to run (as root) updatedb. Some systems do this automatically sceduling via cron or anacron. This creates the locate database, essentially an index of all the files on the mounted filesystems. locate searches this database, not the actual filesystem for a match. This is much faster than searching the filesystem but may be inaccurate since there may changes since the last updatedb. Also, updatedb takes a while. IIRC find searches the actual filesystem and is slower than locate.


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
locate command missing arnott SUSE / openSUSE 2 02-19-2005 10:29 AM
Locate command matt1982 Linux - General 3 01-09-2005 12:22 AM
using locate command stabu Linux - Newbie 6 03-26-2004 05:13 AM
What command will locate a particular.. cbjhawks Linux - General 1 03-21-2004 09:07 AM
Locate command does not work waffe Linux - General 2 09-26-2003 10:54 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:37 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration