mlocate
mlocate is a merging locate and database package. "Merging" means updatedb reuses the existing database to avoid re-reading most of the file system. This makes the database update faster and does not tax the system caches.[1] mlocate can index several file systems including network file systems for network shares. This package is essential when attempting to quickly find documents in a terminal.
Installation
USE flags
USE flags for sys-apps/mlocate Merging locate is an utility to index and quickly search for files
Emerge
Emerge sys-apps/mlocate via:
root #
emerge --ask sys-apps/mlocate
Once installed mlocate can be invoked with the locate command.
Configuration
Files
To have network file systems included when mlocate's index is populated edit the pruning of the file system variable (PRUNEFS) in the /etc/updatedb.conf file. Remove the nfs
, NFS
, and nfs4
, nfsd
entries:
/etc/updatedb.conf
Include network file systems example# This file sets variables that are used by updatedb.
# For more info, see the updatedb.conf(5) manpage.
# Filesystems that are pruned from updatedb database
PRUNEFS="afs anon_inodefs auto autofs bdev binfmt binfmt_misc cgroup cifs coda configfs cramfs cpuset debugfs devfs devpts devtmpfs ecryptfs eventpollfs exofs futexfs ftpfs fuse fusectl gfs gfs2 hostfs hugetlbfs inotifyfs iso9660 jffs2 lustre misc mqueue ncpfs nnpfs ocfs ocfs2 pipefs proc ramfs rpc_pipefs securityfs selinuxfs sfs shfs smbfs sockfs spufs sshfs subfs supermount sysfs tmpfs ubifs udf usbfs vboxsf vperfctrfs"
# Paths which are pruned from updatedb database
PRUNEPATHS="/tmp /var/tmp /var/cache /var/lock /var/run /var/spool"
# Folder names that are pruned from updatedb database
PRUNENAMES=".git .hg .svn CVS"
# Skip bind mounts.
PRUNE_BIND_MOUNTS="yes"
Services
OpenRC
On OpenRC, systems, if a cron daemon is installed and added to a runlevel, updatedb will run routinely via a cron job. See the /etc/cron.daily/mlocate and /etc/mlocate-cron.conf files for more details.
systemd
To enable updatedb to run routinely (each day), activate its timer file:
root #
systemctl enable --now updatedb.timer
Usage
Initial database indexing
Upon installation, the updatedb command will automatically be added as a scheduled cron job. To index the files immediately run:
root #
updatedb
Searching can be performed as soon as this step is complete.
Invocation
See more options from the command-line by asking for help:
user $
locate --help
To find all Firefox executables:
user $
locate firefox | grep bin
Troubleshooting
Cannot find a file
When having trouble finding a newly installed file, be sure the database has been manually rebuilt before the search. The default cron job will index on a daily basis, however the chances of it running directly after new files have been added to the system is slim.
More information concerning the default cron job can be found in the /etc/cron.daily/mlocate file.
External resources
- mlocate (Arch Wiki)