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 03-22-2013, 01:31 AM   #1
thirstonlinux
Member
 
Registered: Jul 2011
Posts: 62

Rep: Reputation: Disabled
locate and find


May I know the exact difference between locate and find command
 
Old 03-22-2013, 02:26 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Locate looks up the location of a file in a database. The database is normally updated nightly in a cron job. Newer files won't be listed. Often, locate is configured to scan system directories and not your personal files.

The find command scans directories looking for files that match the criterions you gave.
You can find files by type, size, date or name pattern. You can execute commands on the results, or print the results in different formats. You can even generate a bash script using -printf. I've done this to add " around the file names.

The info manual for find "finding files" is pretty good. I'd recommend reading through it.

Last edited by jschiwal; 03-22-2013 at 02:27 AM.
 
1 members found this post helpful.
Old 03-22-2013, 03:23 AM   #3
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 275Reputation: 275Reputation: 275
LQ wiki can be useful
 
Old 03-22-2013, 03:38 AM   #4
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
Aonther difference between locate and find is, locate matches the pattern even if it is in its absolute path, which find does not do. this will greatly shortlist the results.

for ex:

# locate *abcd*
/root/abcd.text
/var/ftp/pub/abcd
/var/ftp/pub/abcd/configs
/var/ftp/pub/abcd/others
/var/ftp/pub/abcd/configs/base.config
/var/ftp/pub/abcd/configs/named.config
/var/ftp/pub/abcd/configs/repo.config


# find -iname "*abcd*" 2> /dev/null
./root/abcd.text
./var/ftp/pub/abcd


to update database manually you can issue
# updatedb
 
Old 03-22-2013, 04:56 AM   #5
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
In simple words, locate searches for file within the system database, not personal ones, as:
Code:
~$ locate .profile
/etc/news/.profile
/usr/share/apps/profiles/klauncher.profile.xml
/usr/share/apps/profiles/konqueror.profile.xml
/usr/share/apps/profiles/noatun.profile.xml
(Truncated)
Whereas find cmd can look for any file either personal or system's configuration file. Find is more versatile and options rich than locate.
Code:
~$ find . -name ".profile" -print
./.profile
 
Old 03-22-2013, 06:07 AM   #6
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
Quote:
In simple words, locate searches for file within the system database, not personal ones
No. it will search for all files including personal ones. when you create a new file (personal) and if it is not shown in locate, then that file has not been updated in database yet. it will get updated in next boot, or you can update manually by 'updatedb' command.

What i understand is, linux uses that database to locate for files for internal use. you use 'locate' just to see files -- say, what its like through the eyes of linux. whereas 'find' is for users to search according to their convenience and needs.

Hope i'm correct.
 
1 members found this post helpful.
Old 03-22-2013, 09:53 AM   #7
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
There have been threads before on this subject, eg,
http://www.linuxquestions.org/questi...s-find-877774/
http://www.linuxquestions.org/questi...ommand-879604/
http://www.linuxquestions.org/questi...-files-937265/

I am unclear whether you looked at these threads before asking this question. In general, as well as previous threads, the man pages contain many of the answers to this type of question, although sometimes they are not the easiest of reading.

So, do you still have specific questions?
 
1 members found this post helpful.
Old 03-22-2013, 05:13 PM   #8
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by mddesai View Post
What i understand is, linux uses that database to locate for files for internal use. you use 'locate' just to see files -- say, what its like through the eyes of linux. whereas 'find' is for users to search according to their convenience and needs.

Hope i'm correct.
Sorry to say, you are not correct. Both tools are for users to locate specific or non-specific things in the filesystem. The locate/updatedb combination composes a database that can be quickly accessed to locate files and directories that match some specified pattern. It only searches a database, which makes it faster. In contrast, find does a live search of the filesystem, reporting files and directories that match a fairly complex set of possible constraints. Since it searches a live filesystem, it will not ever be out-of-date. It can also be faster, if the directory tree that it searches is small, or if the '-maxdepth' option is specified.
Neither system is used 'internally' in any rigorous sense (although there may be some use of find in system scripting). The kernel and other critical systems will be quite happy without locate.
find is very much optimized to work as the engine of a filesystem traversal script. It's rich set of filtering parameters makes it well suited to composing lists of files, and its output integrates well with standard scripting idiom.

--- rod.
 
2 members found this post helpful.
Old 03-24-2013, 12:55 AM   #9
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Quote:
Originally Posted by mddesai View Post
No. it will search for all files including personal ones. when you create a new file (personal) and if it is not shown in locate, then that file has not been updated in database yet. it will get updated in next boot, or you can update manually by 'updatedb' command.

What i understand is, linux uses that database to locate for files for internal use. you use 'locate' just to see files -- say, what its like through the eyes of linux. whereas 'find' is for users to search according to their convenience and needs.

Hope i'm correct.
Most often the user nobody is used to scan the filesystem. The nobody user won't have access to your home directory. You can configure locate to include your personal files where another instance of updatedb runs as your user, keeping a private database. Or you could configure updatedb to be run as root. The latter option is usually configured in an /etc/sysconfig/ file.

There are hardly any similarities between locate and find. Find is much more flexible and scans the file system. Locate simply looks up values in its database.
 
2 members found this post helpful.
  


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
[SOLVED] How to use find command to locate files linuxandtsm Linux - Newbie 4 03-30-2012 10:00 AM
[SOLVED] Searching in Linux: locate vs. find kienlarsen Linux - Newbie 19 08-03-2011 04:13 PM
difference between find and locate command sandeep002gupta Linux - Desktop 1 05-09-2011 04:16 AM
'locate' utility can't find db imputerate Linux - Newbie 9 05-26-2008 05:52 AM
cannot find a kernel, please locate one bobotoes Linux - Newbie 2 10-07-2004 06:15 PM

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

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