The updatedb command is used to build a database of files based on the /etc/updatedb.conf file. This command is used to update the /var/lib/mlocate/mlocate.db database. The /etc/updatedb.conf file consists of the paths that should be excluded while building the database. To add a path that needs to be excluded while building the database, open the /etc/updatedb.conf file and, in the PRUNEPATH variable, specify the path that need not be included while building the database. For example, PRUNEPATH=”/etc” will exclude the /etc directory while building the database.
Though this is the default database searched by the locate command, there may be more databases containing file paths. If the database is not updated before performing a search, all files created after the last update will be excluded from the search.
If you encounter below error while running the updatedb commnad:
updatedb: command not found
you may try installing the below package as per your choice of distribution:
Distribution | Command |
---|---|
Debian | apt-get install mlocate |
Ubuntu | apt-get install mlocate |
Alpine | apk add mlocate |
Arch Linux | pacman -S mlocate |
Kali Linux | apt-get install mlocate |
CentOS | yum install mlocate |
Fedora | dnf install mlocate |
Raspbian | apt-get install mlocate |
updatedb Command Examples
1. Refresh the slocate database, excluding files in temporary locations:
# updatedb -e "/tmp,/var/tmp,/usr/tmp,/afs,/net,/proc"
2. to create an index yourself of a directory and all its subdirectories (say, storing it in /tmp/myindex), run:
# updatedb -l0 -U directory -o /tmp/myindex
3. Refresh database content:
# updatedb
4. Display file names as soon as they are found:
# updatedb --verbose