LinuxQuestions.org
Review your favorite Linux distribution.
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 06-07-2004, 10:23 AM   #1
MartinOG
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, 10:36 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
You will have to use regular expressions that return fewer hits.
Code:
 [^ld]
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, 01:19 PM   #3
MartinOG
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 check...no, 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, 01:59 PM   #4
kevinalm
Member
 
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.
 
  


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

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

All times are GMT -5. The time now is 03:55 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