-1

I know that locate has to have a database generated and is much faster, and that find does not need a database generated and is not as fast. So in what situations is find and locate more efficient/affective/give a better end result?

  • A duplicate of unix.stackexchange.com/q/60205/117549 – Jeff Schaller Dec 16 '17 at 3:23
  • @JeffSchaller I don’t think my question is exactly a duplicate, though there are similarities... While my question is asking the pros and cons, I am asking in what situations would either of the two command be more efficient and affective and give better results. – StrangeRanger Dec 16 '17 at 4:45
1

As you said, locate has a database and is therefore much faster, while find has to traverse the filesystem. But locate's database only contains filenames (with their paths), while find can select files based on other meta data like mtime or size. So it is my resume versatile. Also the database has to be updated in a batch effort, usually nightly, so files which have been created modified recently do not appear correctly. Also you can expect every modern Unix system to have find available, while not all systems have locate's database enabled.

So, locate is faster, use it to find the location of a file, find is more versatile. There is no universal better.

| improve this answer | |
  • I'm not an expert with either command by any means so take this with a grain of salt. However I believe another caveat of the locate database is that it will only include paths that the user who created it has read access. To me this means that even if run with sudo it may not find files that would be otherwise located with find. – jesse_b Dec 15 '17 at 23:15
0

Typically the locate database is updated once per day. So if you need to search for anything that is newer than one day, you may need find for that.

On the other hand, the larger the filesystem you need to search, the faster locate will be over find. Especially so if the filesystem is on a network share.

| improve this answer | |

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