locate command in Linux: fast indexed search
Updated November 1, 2026
The locate command finds files through a prebuilt index of names.
Syntax
locate nameCommon cases
locate sshd_config # find a file by name
locate -i readme # ignore case
sudo updatedb # rebuild the system-wide index
locate -c .conf # how many matchesSample output
$ locate .bashrc
/etc/bash.bashrc
/etc/skel/.bashrc
/home/student/.bashrc
/usr/share/dot.bashrc
/usr/share/base-files/dot.bashrc
$ locate -c conf
424How it works: an index versus walking the tree
findwalks the directory tree live every time - accurate, but slow.locatereads an index (a name database) built by theupdatedbcommand, usually scheduled once a day. Solocateanswers instantly but cannot see files created since the lastupdatedb. The rule is simple: if the file is fresh, usefind; to look up a long-standing file by name,locateis faster.
Common mistakes
locate matches a substring of the whole path, not of the filename. The first line of locate .bashrc is /etc/bash.bashrc: that file has a different name, the string .bashrc just happens to sit inside bash.bashrc. For the same reason locate profile.d returns /etc/profile.d/gawk.sh, whose name contains neither word - the directory matched. locate -b narrows the search down to the filename.
A deleted file stays in the index until the next updatedb. Create report.conf, run updatedb, delete the file, and locate report.conf still prints /home/student/report.conf. locate -e checks that the path is still alive: on a deleted file it prints nothing and returns exit code 1.
Parts of the tree never reach the index at all. /etc/updatedb.conf carries the line PRUNEPATHS="/tmp /var/spool /media ...", so a file created in /tmp stays invisible even right after updatedb: locate zzz-report.conf says nothing and returns 1, while find /tmp -name zzz-report.conf prints /tmp/zzz-report.conf. Network mounts listed in PRUNEFS are skipped the same way.
Used in
You need this in the lesson Finding files. The theory is the chapter Finding files: find, locate, which.
See also
The find command, which, type, whereis.
Try it
Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.