6

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.

KK Patel
  • 19,753
Will
  • 69

3 Answers3

6

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.

user4556274
  • 5,097
2

The file lives at /var/lib/mlocate/mlocate.db but is owned by root so you cannot access it without super user access.

to fill your screen with it's content issue the command sudo cat /var/lib/mlocate/mlocate.db

Do not attempt to edit this file

Source: ls -lhs /var/lib/mlocatelocate/mlocate.db

Elder Geek
  • 36,752
0

The file seems to reside on path /var/cache/locate/locatedb on my system (Ubuntu 20.04).

This is explained in the man page of updatedb like this:

--output=dbfile
    The database file to build.  Default is system-dependent.
    In Debian GNU/Linux, the default is /var/cache/locate/locatedb.

Similarly, the info page says:

'--output=DBFILE'
  The database file to build.  The default is system-dependent, but
  when this document was formatted it was '/var/cache/locate/locatedb'.

Please note that the permissions of the file and its parent directories are like this:

$ stat /var/cache/locate/locatedb | grep -m1 Access:
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
$ stat /var/cache/locate | grep -m1 Access:
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
$ stat /var/cache | grep -m1 Access:
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)

This means that a non-privileged user is able to locate a file's path that normally cannot list.

FedKad
  • 13,420