Linux HOWTOs

About | Home | Search

HOWTO: mlocate
Description: A locate/updatedb that re-uses the existing database for efficiency
Click here for ChangeLog
NOTE: I use GNU tar >= 1.13.25 so it's -j for .tar.bz2 files,
it's safe to assume that make, gcc, binutils, fileutils/coreutils, gawk, sed, and grep are prerequisites for almost everything

# mlocate 0.25
# ============
# mlocate is another locate/updatedb, like GNU findutils' ones, and slocate.
# My understanding of the three is this:
# - GNU findutils is the standard one.  updatedb creates a database of
#   all files on the system.  locate finds any matching files in the
#   database.
# - slocate's updatedb creates a database of all files on the system too,
#   but with permissions.  It's locate does not display results for files
#   that a user does not have access to.
# - mlocate's updatedb merges the existing database together with changes,
#   speeding up the daily run of updatedb significantly.  locate can work
#   as slocate's does.

# Get it
test -f installed/mlocate-0.25.tar.xz &&
 mv -f installed/mlocate-0.25.tar.xz .
test ! -f mlocate-0.25.tar.xz &&
 wget --no-check-certificate \

# Extract the tarball
mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "mlocate-*" -exec rm -r {} \;
tar xJvf ~/mlocate-0.25.tar.xz
cd mlocate-0.25
test $UID = 0 && chown -R root:root .

# Cnfigure and build it
./configure --prefix=/usr --sysconf=/etc --localstatedir=/var/lib \
--mandir=/usr/man --disable-nls

# Become root to install it

# If you also have GNU findutils' updatedb/locate installed, remove them
( cd /usr/bin ; rm -f locate updatedb )
( cd /usr/man/man1 ; rm -f locate.1 updatedb.1 updatedb.1.gz )
rm -f /etc/cron.daily/locate /usr/man/man5/locatedb.5 /usr/var/locatedb \

# Add a 'mlocate' group
getent group | egrep -q "^mlocate:" || groupadd mlocate

# Add your non-root account to the mlocate group
usermod -G mlocate $(logname)

# Install it
make install

# See these man pages: locate, updatedb, mlocate.db, updatedb.conf

# You can create an /etc/updatedb.conf like so, or pass these options using
# commandline options (see the man page)
cat < /etc/updatedb.conf
PRUNEFS="devpts NFS nfs afs proc smbfs autofs iso9660 udf tmpfs cifs" 
PRUNEPATHS="/dev /proc /sys /tmp /usr/tmp /var/tmp /afs /net /media /mnt"
chmod 644 /etc/updatedb.conf

# Set it to run from cron every day
cat < /etc/cron.daily/mlocate
ionice -c 3 nice -n 19 /usr/bin/updatedb
chmod 700 /etc/cron.daily/mlocate

# Make sure your non-root user can remove the source later
chown -R $(logname) .
chmod -R u+w .

# Become yourself again

# Keep the tarball for later
mkdir -p -m 0700 installed
rm -f installed/mlocate-0.25.tar.*
mv -f mlocate-0.25.tar.xz installed/

# If you ever want to uninstall mlocate, this should do it:
test -d src/mlocate-* && ( cd src/mlocate-* ; make uninstall )
( cd /usr/bin ; rm -f locate updatedb )
( /usr/man/man5 ; rm -f mlocate.db.5 updatedb.conf.5 )
rm -f /usr/man/man1/locate.1 /usr/man/man8/updatedb.8
test -d /var/lib/mlocate && rm -r /var/lib/mlocate
find ~/src -maxdepth 1 -type d -name "mlocate-*" -exec rm -r {} \;
rm -f ~/installed/mlocate-*.tar.*

Back to the list

Last updated: Tue, 07 Aug 2018 12:06:17 -0400
Jason Englander <jason at englanders dot us>