‘Locate’ Linux Command Showing File That Doesn’t Exist
I use the ‘locate‘ command quite a lot for finding files when I’m not sure where exactly they reside on a server.
I came across a scenario today where I ran the ‘locate’ command and it returned the file that I was looking for. However, when I navigated to the folder and tried to look at the file I began to get an error that the file did not in fact exist at all.
To double check, I performed the same search for a second time and it still confirmed that it had been able to find the folder, yet it definitely didn’t exist.
It turns out that the ‘locate’ command uses it’s own database of filenames that it updates periodically. In my case, this database contained the file in question, but it had since been deleted.
Luckily the solution was simple and simply requires either a) waiting until the database of filenames gets updated automatically, or b) updating the database manually by running the command below:
$ sudo updatedb
Performing a search after running the above then didn’t return the file in question, thus confirming that it had in fact been deleted.