2

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?

6

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 '17 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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