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] PATTERNParameters & Attributes
| Name | Type | Description |
|---|---|---|
| -i | option | Case-insensitive matching |
| -e | option | Require the indexed path to still exist |
| -d DBPATH | option | Use a specified index |
| PATTERN | operand | Filename 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