locate
is not dependable for live, current information about what files are present on your system. Information is cached in a database.
Also consider the famous line, with link:
It's not working! Should I blame caching?
For actual current information on what files/directories exist on your box right now, use ls
or find
or stat
or test -e filename && echo it is there
or even printf %s\\n *
. Pretty much anything except locate
will give you up-to-date information about your filesystem.
See also LESS=+/BUGS man locate
which (on my system) reads in part:
BUGS
The locate program may fail to list some files that are present, or may
list files that have been removed from the system. This is because
locate only reports files that are present in the database...
You can run updatedb
, but honestly if you know exactly where the files are and you are using locate
to find them...you are simply doing it wrong. locate
tells you a path. It tells you nothing about the existence or nonexistence of files at that path. If you already know the path to the file, you don't need locate
, do you?
The purpose of locate is to "find filenames quickly", not necessarily accurately or dependably.
Note: I'm not saying "don't use locate
." It does have a purpose, when you have no idea where on your system a certain file might be. But once you get the pathname from locate
, it has served its purpose and you now need to use other tools to examine/verify/etc. the file you've found.