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 03-22-2012, 09:12 AM   #1
technocp
LQ Newbie
 
Registered: Oct 2008
Posts: 18

Rep: Reputation: 0
want to use Locate instead of find as it gives some faster results


I used locate command to find files and it was all going well. Then came the need of using some more parameters for finding like finding by size, finding by time & date, etc.

So I used the locate command and its database as follows
sudo find $(locate somefile) -<findoption>
it gave me good results. BUT

everything was messed up when it was about finding files that have spaces in its name.

if filenames have spaces then find command divides the output provided by locate command
 
Old 03-22-2012, 09:14 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
just put "'s around the locate command.
 
Old 03-22-2012, 12:52 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
Quotes won't work if locate spits out more than a single filename.

Not only that, but the find command is not really correct. The first arguments are really supposed to be a list of top-level directories that find starts the search from, not a list of filenames. It is after all, designed to find files, not evaluate files you already know the location of.


AFAICT, there's really no simple, single command way to take care of this. One solution that would work is to store the output of locate in an array first and use that:

Code:
while IFS="" read -d "" -r f; do array+=( "$f" ) ; done < <( locate -0 <pattern> )
find "${array[@]}" -options
This could perhaps be set up as a script or function for ease of use, but the writing of it would be non-trivial, as you'd have to design it to accept the options of two separate programs at once.


But really, if you need to find files by complex criteria, then you should just use find directly, the way it was intended.
 
  


Reply

Tags
find, 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
[SOLVED] Neither grep nor locate find khelper. What does it do? stf92 Slackware 3 06-22-2011 05:29 AM
'locate' utility can't find db imputerate Linux - Newbie 9 05-26-2008 06:52 AM
LXer: Locate, Find, and Whereis LXer Syndicated Linux News 0 03-28-2006 04:06 PM
cannot find a kernel, please locate one bobotoes Linux - Newbie 2 10-07-2004 07:15 PM
Using the results of locate for grep skibud2 Linux - Newbie 1 12-16-2003 02:58 PM


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

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