Ubuntu – Where is the database for locate/updatedb on Ubuntu

locateupdatedb

I have been reading about the locate command, and the tutorial I was using says that /var/log/updatedb is where the updatedb is located. It is not there on ubuntu (xubuntu), and it doesn't even seem to be locate-able (ironically) in principle. This is what I have done to try and find it:

[HOST]:~$ sudo find / -name updatedb
[sudo] password for [USERNAME]:
find: ‘/run/user/1000/gvfs’: Permission denied
/etc/alternatives/updatedb
/usr/bin/updatedb

if I look in /usr/bin and long-list updatedb, it is linked (light blue link – and with an 'l' in the permissions, so a symlink) to /etc/alternatives/updatedb.

if I look in /etc/alternatives

[HOST]:/usr/bin$ cd /etc/alternatives
[HOST]:/etc/alternatives$ ls -l updatedb
lrwxrwxrwx 1 root root 25 Jul 15 02:35 updatedb -> /usr/bin/updatedb.mlocate

you get the above symlink to /usr/bin/updatedb.mlocate

[HOST]:/usr/bin$ ls -l updatedb.mlocate
-rwxr-xr-x 1 root root 43768 Nov 18 2014 updatedb.mlocate

[HOST]:/usr/bin$ file updatedb.mlocate
updatedb.mlocate: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=85d4fb92c2e099510893b0c2eccb13d49943e81e, stripped

I then read this link on ubuntu:

Ubuntu Manpage: updatedb – update a database for mlocate

Which says that the database is in /var/lib/mlocate.db, but this (just below) is what I got, and when opened in a text editor the message was that the data was unreadable:

[HOST]:/var/lib/mlocate$ ls
mlocate.db
[HOST]:/var/lib/mlocate$ emacs mlocate.db
[HOST]:/var/lib/mlocate$ file mlocate.db
mlocate.db: regular file, no read permission
[HOST]:/var/lib/mlocate$ ls -l mlocate.db
-rw-r----- 1 root mlocate 5291101 Aug 1 08:45 mlocate.db
[HOST]:/var/lib/mlocate$

I expect I just have a conceptual misunderstanding, but would be grateful for any comments that would help me understand where the database can be found.

Best Answer

You have the correct file, but the database is unreadable for two related reasons:

  1. You don't have permission to access it directly.
    This can be overcome with sudo emacs mlocate.db

  2. It is not a text file, so there is little utility in opening it in a text editor. It is possible to view and edit it using a text editor, but the most likely result is corruption of the database. Use the appropriate tools for reading or modifying mlocate.db: updatedb and locate.