locate and find
May I know the exact difference between locate and find command
|
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. |
LQ wiki can be useful
|
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 |
In simple words, locate searches for file within the system database, not personal ones, as:
Code:
~$ locate .profile Code:
~$ find . -name ".profile" -print |
Quote:
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.:scratch: |
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? |
Quote:
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. |
Quote:
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. |
All times are GMT -5. The time now is 06:25 AM. |