1

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?

  • 1
    Try updating the database used by locate using updatedb. – Vikyboss Apr 2 '16 at 2:35
  • The locate database is updated on a schedule; may be daily -- check cron or use vikyboss's suggestion to update is manually b – Jeff Schaller Apr 2 '16 at 3:13
6

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.

  • Some versions of locate have a -e option to make it check for a file's existence before printing a line. But, you're still stuck with the reverse problem: files created since the last updatedb run won't appear, unless you're using a version of locate that ties into FSEvents or similar. – Warren Young Apr 2 '16 at 6:06
  • Well, guess one learns new things everyday. I wasn't so sure why "ls" or "find" weren't returning any results. The interesting thing is that mysql prevented me from creating a table with the same name until I ran "updatedb". Thanks. – Snivs Apr 2 '16 at 15:57
0

locate command does not search the files on disk rather it searches for file paths in a database. The database is a file that contains information about the files and their path on your system.

So one limitation of the ‘locate’ command is its dependency on the database which can be updated by another utility ‘updatedb’. Hence, in order to get the latest and reliable results from ‘locate’ command the database on which it works should be updated at regular intervals.

hence, after deleting the file, you should check the file existence using #find command which searches the file in real time. #find /var/lib/mysql/db/ -iname "nomNomina2.*"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.