commands

locate — Search an indexed filename database

Search filenames using a previously generated database. This is not a recursive search of live file contents. Newly created files may not appear until indexing; -e filters out entries that no longer exist but does not discover missing new entries. This entry targets plocate. Restrict practice to a private index; the index itself may contain sensitive pathnames.

Formal Syntax & Structure

linux syntaxlinux
locate [-i] [-e] [-d DBPATH] PATTERN

Parameters & Attributes

NameTypeDescription
-ioptionCase-insensitive matching
-eoptionRequire the indexed path to still exist
-d DBPATHoptionUse a specified index
PATTERNoperandFilename pattern

Return Value

exit status and output

Matching paths on stdout; plocate returns 0 when matches are found, 1 for no matches or errors.

Working Example

Example Snippetlinux
d=$(mktemp -d) || exit 1trap 'rm -rf -- "$d"' EXITmkdir "$d/site"printf "demo\n" > "$d/site/report.txt"updatedb -l 0 -U "$d/site" -o "$d/index.db" &&locate -d "$d/index.db" -e report.txt
Linux Reference