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?
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.