updatedb

file managementlinux
The updatedb command is one of the most frequently used commands in Linux/Unix-like operating systems. updatedb The updatedb command updates the file name database used by the locate command. It scans your filesystem and builds a database of file names and locations, which allows for fast file searches without having to scan the filesystem in real-time.

Quick Reference

Command Name:

updatedb

Category:

file management

Platform:

linux

Basic Usage:

updatedb [options] [arguments]

Common Use Cases

  • 1

    File database

    Update the file database for faster file location

  • 2

    Performance

    Improve the speed of file searches

  • 3

    System maintenance

    Keep the file database up-to-date

  • 4

    Scripting

    Use in shell scripts to update the file database programmatically

Syntax

updatedb [OPTION...]

Options

Option Description
--localpaths=PATH Non-network directories to put in the database
--netpaths=PATH Network directories to put in the database
--prunepaths=PATH Directories to exclude from the database
--prunefs=FILESYSTEM Filesystems to exclude from the database
--output=DBFILE Database file to build
--netuser=USER User to search network directories as
--dbformat=FORMAT Database format to use (often 'LOCATE02')
-v, --verbose Print paths as they are found
-h, --help Display help information
-V, --version Display version information

Examples

How to Use These Examples

The examples below show common ways to use the updatedb command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

#

Basic Examples:

sudo updatedb

Update the file name database with default settings. This requires superuser privileges to access all files.

sudo updatedb --prunepaths="/tmp /var/tmp"

Update the database while excluding the /tmp and /var/tmp directories.

sudo updatedb -v

Run with verbose output to show the progress of the database creation.

Advanced Examples:

sudo updatedb --localpaths="/home"

Only index files in the /home directory, ignoring all other locations.

sudo updatedb --output=/path/to/custom/locate.db

Store the database in a custom location instead of the default.

sudo updatedb --netpaths="/mnt/network"

Include network mounted directories like /mnt/network in the database.

sudo updatedb --prunefs="nfs,tmpfs"

Exclude specific filesystem types (like NFS and tmpfs) from being indexed.

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

Key Points:

  • The updatedb command is typically run once a day via cron job
  • It requires root privileges to access all directories on the filesystem
  • The database is stored at /var/lib/mlocate/mlocate.db on many systems
  • Configuration settings can be found in /etc/updatedb.conf
  • The locate command depends on this database being updated regularly

Configuration Variables:

  • PRUNEFS: Filesystems to exclude from the database
  • PRUNENAMES: Directory names to exclude
  • PRUNEPATHS: Specific paths to exclude
  • PRUNE_BIND_MOUNTS: Whether to exclude bind mounts

Common Use Cases:

  • Creating a searchable index of all files on the system
  • Enabling fast file searches with the locate command
  • Setting up a scheduled task to keep the file database current
  • Customizing which files and directories are indexed
  • Creating separate databases for different purposes or security levels

Related Commands:

  • locate - Quickly find files by name using the database
  • find - Search for files in real-time (without a database)
  • slocate - Security-enhanced version of locate
  • mlocate - An implementation of locate that maintains file metadata
  • cron - Scheduling system often used to run updatedb periodically

Database Implementations:

  • mlocate: The most common implementation (merges and updates the database incrementally)
  • slocate: Security-enhanced locate, which adds file permissions to the database
  • GNU locate: Part of the GNU findutils package

Tips & Tricks

1

Use the -o option to specify the output file

2

Use the -U directory option to exclude directories

3

Use the -l level option to set the logging level

4

Use the -h option to display help

5

Use the -V option to display version information

Common Use Cases

File database

Update the file database for faster file location

Performance

Improve the speed of file searches

System maintenance

Keep the file database up-to-date

Scripting

Use in shell scripts to update the file database programmatically

File management

Manage and maintain the file database

Related Commands

These commands are frequently used alongside updatedb or serve similar purposes:

Use Cases

1

File database

Update the file database for faster file location

2

Performance

Improve the speed of file searches

3

System maintenance

Keep the file database up-to-date

4

Scripting

Use in shell scripts to update the file database programmatically

5

File management

Manage and maintain the file database

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the updatedb command works in different scenarios.

$ updatedb
View All Commands