‘Locate’ Linux Command Showing File That Doesn’t Exist

October 17th, 2013 - Posted by Steve Marks to Server Management, Web Development.

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.

The Solution

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.

This entry was posted on Thursday, October 17th, 2013 at 11:04 pm by +Steve Marks and is filed under Server Management, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (0)

No comments have been left yet. Be the first