Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Why there are two so similar command in Linux? and normally what are the circumstances to use each of them?

share|improve this question

migrated from stackoverflow.com Oct 14 '10 at 15:44

This question came from our site for professional and enthusiast programmers.

1  
For better answers in both depth and completeness, see this answer at Unix & Linux. –  That Brazilian Guy Nov 10 '13 at 12:41

4 Answers 4

up vote 23 down vote accepted

find searches in the real system. Is slower but always up-to-date and has more options (size, modification time,...)

locate uses a previously built database (command updatedb). Is much faster, but uses an 'older' database and searches only names or parts of them.

In any case, man find and man locate will help you further.

share|improve this answer
    
...and updatedb do roughly someting like find / -type f | gzip > locate.gz. –  F. Hauri Jan 5 '13 at 14:40
3  
unix.stackexchange.com/questions/60205/… answers this question in more detail. –  nutty about natty Mar 15 '13 at 16:59

Check this link, you have both Find and Locate -

http://www.westwind.com/reference/OS-X/commandline/misc.html#locate

share|improve this answer

locate and find both commands will find file. But each of them work in a quite different way.

'locate' will work in a off line mode: For a simple explanation, a file indexing database in Unix system called 'slocate'. This database will have all your file location lists which ships with Unix system. When you execute locate then it will go to that database and search for a particular file.

Now the problem with locate command is that if you just create a file/files form where you want to search a file then locate will not work because the slocate database is not updated yet.

In order to overcome this problem you can use updatedb which will eventually update the slocate database. Now executing the command again will find the newly created file/files that you just have created before.

That's why many Linux system administrator use the corn job to update the slocate database on a regular basis.

'find' will work in a on line/ real time mode. It will actually go and search all the directories to find the particular file specified and it examine each file one by one. Therefore, it requires a lot of I/O calls.

So based on the nature, it is clear that locate is faster than find but find is real time.

Hope this will help to clear the idea. All the best. :)

share|improve this answer

locate simply looks its database and reports the file location.

find does not use a database, it traverses all the directories and their sub directories and looks for files matching the given criterion.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.