Cannot delete file, but can delete parent directory

locate

So basically, I'm trying to delete the files:

/var/lib/mysql/db/nomNomina2.*

and when I look for them with locate, I get the following output:

/var/lib/mysql/db/nomNomina2.MYD
/var/lib/mysql/db/nomNomina2.MYI
/var/lib/mysql/db/nomNomina2.frm

but then I try to

 $ rm -fv  /var/lib/mysql/db/nomNomina2.frm

I get no output, but the files still show when using locate.

Notice that I can create and delete a file with the same filename in the same location, but it will still show when using locate, and I won't be able to create another table with the same name.

Any ideas what could be causing this? filesystem mess? how to correct it?

Best Answer

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.

Related Question