Ubuntu – ‘locate’ command in terminal. Why is it so fast

command linelocate

Searching a keyword in linux terminal using the locate command gives answer in a short time.
What is the search algorithm used?

Best Answer

The system creates a data base of all the files in the computer. So when you search trough locate the command doesn't really checks the whole file-system but only the database, it does a binary search algorithm which is fast like looking up a word in a dictionary. That's why it's so fast (and handy).

Such database is updated regularly; you may have seen it work sometimes when you install a new package: updating mlocate.... You can find more information about how it works by executing in a terminal:

man locate

man updatedb
Related Question