locateFind files instantly by name from an index
locate answers 'where is the file called X?' in milliseconds by searching a database of every path on the system, rebuilt daily by updatedb. It's fast because it never touches the disk, and stale for the same reason: files created since the last update are invisible.
locate [OPTION]... PATTERN... sudo updatedbYou remember a config file's name but not where the package put it.
locateOn Ubuntu 24.04 this is plocate, a fast replacement for mlocate with the same options.
locate never walks the filesystem. A separate program, updatedb, does that once a day (on Ubuntu 24.04 the plocate-updatedb.timer systemd unit; older systems used /etc/cron.daily). It crawls every directory, skipping what /etc/updatedb.conf prunes (/tmp, /proc, network filesystems like NFS), and writes all path names into a compressed index, /var/lib/plocate/plocate.db. plocate builds a trigram index, so a query reads only the few blocks that can contain the pattern instead of scanning every path. A plain pattern matches anywhere in the full path (as if wrapped in *...*); with several patterns plocate requires all of them to match. The database is readable only by the plocate group, and the locate binary is setgid plocate: it can read the whole index, but before printing a result it checks that you could reach that path yourself, so it doesn't leak names from directories you can't enter.
A daily job indexes every path; locate only reads that index, which makes it instant and possibly out of date.
plocate-updatedb.timer starts updatedb, usually in the night with a random delay, at idle I/O priority.
-iCase-insensitive match-l N / -n NStop after N results-cPrint only the number of matches-bMatch the base name only (with '\name' for an exact name)-r REGEX / --regexBasic / extended regular expression (slower)-eOnly print files that still exist right now-0NUL-separated output for xargs -0-d DBPATHSearch a different databasesudo updatedbRebuild the index nowUsing locate in a script to check whether a file existsThe index can be up to a day old, so files created since then are missed and deleted ones still appear.
test -e /path/file, or find for searchesConcluding a file doesn't exist because locate found nothingIt may be newer than the index, or in a pruned path (/tmp, /media, NFS), or in a directory you can't access.
sudo updatedb && locate name, or sudo find / -xdev -name namelocate nginx.conf expecting exactly one config fileA plain pattern matches anywhere in the full path, so you also get nginx.conf.default, nginx.conf.dpkg-old and every path under a directory containing that text.
locate -b '\nginx.conf' for an exact base name; with wildcards (locate '*/nginx.conf') the glob must match the whole pathTry these on a Linux machine of your own. Each task has a hint and a solution.
Use locate to find where app.conf lives on the sandbox.
Create ~/findme-test.txt, try to locate it, then make locate find it.
Count how many paths on the system contain 'python3', case-insensitively.
locateFind files instantly by name from an index
locate answers 'where is the file called X?' in milliseconds by searching a database of every path on the system, rebuilt daily by updatedb. It's fast because it never touches the disk, and stale for the same reason: files created since the last update are invisible.
locate [OPTION]... PATTERN... sudo updatedbYou remember a config file's name but not where the package put it.
locateOn Ubuntu 24.04 this is plocate, a fast replacement for mlocate with the same options.
locate never walks the filesystem. A separate program, updatedb, does that once a day (on Ubuntu 24.04 the plocate-updatedb.timer systemd unit; older systems used /etc/cron.daily). It crawls every directory, skipping what /etc/updatedb.conf prunes (/tmp, /proc, network filesystems like NFS), and writes all path names into a compressed index, /var/lib/plocate/plocate.db. plocate builds a trigram index, so a query reads only the few blocks that can contain the pattern instead of scanning every path. A plain pattern matches anywhere in the full path (as if wrapped in *...*); with several patterns plocate requires all of them to match. The database is readable only by the plocate group, and the locate binary is setgid plocate: it can read the whole index, but before printing a result it checks that you could reach that path yourself, so it doesn't leak names from directories you can't enter.
A daily job indexes every path; locate only reads that index, which makes it instant and possibly out of date.
plocate-updatedb.timer starts updatedb, usually in the night with a random delay, at idle I/O priority.
-iCase-insensitive match-l N / -n NStop after N results-cPrint only the number of matches-bMatch the base name only (with '\name' for an exact name)-r REGEX / --regexBasic / extended regular expression (slower)-eOnly print files that still exist right now-0NUL-separated output for xargs -0-d DBPATHSearch a different databasesudo updatedbRebuild the index nowUsing locate in a script to check whether a file existsThe index can be up to a day old, so files created since then are missed and deleted ones still appear.
test -e /path/file, or find for searchesConcluding a file doesn't exist because locate found nothingIt may be newer than the index, or in a pruned path (/tmp, /media, NFS), or in a directory you can't access.
sudo updatedb && locate name, or sudo find / -xdev -name namelocate nginx.conf expecting exactly one config fileA plain pattern matches anywhere in the full path, so you also get nginx.conf.default, nginx.conf.dpkg-old and every path under a directory containing that text.
locate -b '\nginx.conf' for an exact base name; with wildcards (locate '*/nginx.conf') the glob must match the whole pathTry these on a Linux machine of your own. Each task has a hint and a solution.
Use locate to find where app.conf lives on the sandbox.
Create ~/findme-test.txt, try to locate it, then make locate find it.
Count how many paths on the system contain 'python3', case-insensitively.