This articles goes over the Linux locate command, how to see when the locate database was last updated, and how to update the database the locate command pulls from to make sure it is up to date. This applies to Cloud and Dedicated Linux environments.
Using the locate command
- Login to your Linux server via SSH
- Run this command:
- locate file_name
- The results from step 2 will return any file paths containing the string file_name
Determining When the locate Database was Last Updated
- Login to your Linux server via SSH
- Run this command:
- locate mlocate.db | grep "/var/lib" | xargs ls -alh | awk {'print $6" "$7" "$8'}
- Here is an example:
- [root@12345-1 ~]# locate mlocate.db | grep "/var/lib" | xargs ls -alh | grep -v "No such" | awk {'print $6" "$7" "$8'}
Apr 6 18:34
- [root@12345-1 ~]# locate mlocate.db | grep "/var/lib" | xargs ls -alh | grep -v "No such" | awk {'print $6" "$7" "$8'}
This means if you added a new file to the Linux server after that time, locate will not find it. The next section will go over how to update the locate database so it is up to date.
Updating the locate Database
- Login to your Linux server via SSH
- Run this command
- updatedb&
- Keep running this command until it says updatedb is done
- jobs
- Here is an example:
- root@12345-1 ~]# updatedb&
[1] 19588
[root@12345-1 ~]# jobs
[1]+ Done updatedb
- root@12345-1 ~]# updatedb&
Once these steps are done, you can run the locate command for any new files you added to your Linux server. It should be able to find them now.