locate command searches an index that the system builds periodically.

How to make sure, any new file you're looking is part of index? Is there any explicit command to index?

1 Answer 1


From the manual (man locate):

locate reads one or more databases prepared by updatedb(8) and writes file names matching at least one of the PATTERNs to standard output, one per line.

So, updatedb writes the database. It is typically already set up to run periodically from cron in many systems. It should not be possible to update the system locate database as a regular user. So, perhaps sudo updatedb works best in many systems.

  • The schedule is typically nightly because the indexing operation is rather heavy on a system with many files. Even on an SSD, it would probably not make sense to run it more often.
    – tripleee
    Apr 16, 2017 at 17:58
  • My expirience is different, if you have enough RAM updatedb is quite fast, unfortunately I don't know if it searches the whole directory tree or is able to detect changes faster, because running it twice, with only a small delay just takes less than a second!
    – Martin T.
    Jan 24, 2020 at 10:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .