updatedb - Linux Command - Unix Command

Update the database of your system files to make finding them easier

Developers In Their Home Office
vgajic / Getty Images

The updatedb command is used in conjunction with locate command, like locate, mlocate, and slocate, to generate a searchable database of the files currently on your Linux system.

Install Updatedb With mlocate

This guide is going to focus on the mlocate package, but an alternative, if available, will work just as well.

Debian/Ubuntu/Mint

sudo apt install mlocate

Fedora

sudo dnf install mlocate

CentOS/RHEL

sudo yum install mlocate

OpenSUSE

sudo zypper install mlocate

Arch Linux/Manjaro

sudo pacman -S mlocate

Using Updatedb

The updatedb command comes with mlocate, and you'll need to use it to create a database before you can search. Since updatedb will try to log everything on your system by default, you'll need to run it with root permissions using 'sudo.' If you only want to use it as a regular user, you can with a few options, but that's a topic for later.

First, try creating a general system-wide database with root permissions.

sudo updatedb

It will take a few minutes to complete, depending on how many many files are on your system. From there, you can try finding a file with mlocate.

mlocate gnome

Notice the amount of junk that comes up? You can, if you choose exclude certain directories with the '-e' flag.

sudo updatedb -e /usr/share, /var/lib

If you want to see which files are being added to the database, use the '-v' flag.

sudo updatedb -v

Now, if you want to run updatedb as a regular user, you can use the '-l' flag with a value of '0' to exclude everything that your user doesn't have access to. Then, specify a local output in your home directory with the '-o' flag.

updatedb -l 0 -o ~/.mlocate.db

To search that user-specific database, instead of the system one, use the -d flag to specify your user one.

mlocate -d ~/.mlocate.db

These are the most common ways that you'll work with updatedb. For a more complete breakdown, refer to the complete technical manual below.

Updatedb Technical Manual

Below is the full technical breakdown of what the updatedb command can do.

NAME

updatedb - update the slocate database 

SYNOPSIS

updatedb [-u] [-u path] [-e path1,path2,...] [-f fstype1,...] [-l [01] ] [-q] [-v,--verbose] [-V, --version] [-h, --help] pattern...  

DESCRIPTION

This manual page documents slocate, a security-enhanced version of locate. updatedb is simply a link to slocate that implies the -u option.  

OPTIONS

-u

Create slocate database starting at the root directory. This is the default behavior when called as updatedb.

-U path

Create slocate database starting at path path.

-e dirs

Exclude directories in the comma-separated list dirs from the slocate database.

-f fstypes

Exclude file systems in the comma-separated list dirs from the slocate database.

-l <num>

Security level. -l 0 turns security checks off, which will make searches faster. -l 1 turns security checks on. This is the default.

-q

Quiet mode; error messages are suppressed.

-v

Verbose mode; display files indexed when creating database

--help

Print a summary of the options to slocate and exit.

--version

Print the version number of slocate and exit.

Use the man command (% man) to see how a command is used on your particular computer.