locate(1)

โœจ locate(1) โ€” find files by name, bestie โœจ

okay so like, this is the locate manpage from the General Commands Manual. it's giving "where is that file tho" energy and honestly? iconic. let's get into it ๐ŸŽ€


๐ŸŒธ NAME ๐ŸŒธ

locate โ€” find files by name. that's it. that's the whole vibe. you're looking for a file, locate finds it, slay.


๐Ÿ’… SYNOPSIS ๐Ÿ’…

locate [OPTION]... PATTERN...

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so here's the tea, bestie: locate reads one or more databases that were prepared by updatedb(8) โ€” like, someone else did the homework and now you get to just look at the answers โ€” and then it writes file names that match at least one of the PATTERNs to standard output, one per line. literally just handing you the list. ๐Ÿซถ

okay but here's where it gets interesting (no cap): if you don't specify --regex, your PATTERNs can contain globbing characters. and if any PATTERN contains no globbing characters, locate behaves as if the pattern were *PATTERN*. so like, it auto-wraps your search in wildcards so you don't have to. thoughtful queen behavior โœจ

โš ๏ธ important caveat, don't come for me: by default, locate does not check whether files found in the database still exist. (but it does require all parent directories to exist if the database was built with --require-visibility no.) and like, locate can never report files created after the most recent update of the relevant database. so if your file is brand new? it's not in the database yet. the database is not a time traveler. ๐Ÿ’€

๐Ÿ”ฅ EXIT STATUS ๐Ÿ”ฅ

locate exits with status 0 if any match was found, OR if locate was invoked with one of the --limit 0, --help, --statistics or --version options. like, even if you found nothing, if you used one of those, you're still good. we love a forgiving exit. ๐Ÿ˜Œ

if no match was found or a fatal error was encountered, locate exits with status 1. rip.

and heads up: errors encountered while reading a database are not fatal โ€” search continues in other specified databases, if any. so like, one database is being messy? the others still get searched. resilience. ๐Ÿ’ช


โœจ OPTIONS โœจ

okay this is the part where we go through every single flag because we do not skip. periodt. ๐Ÿ‘‘

  • -A, --all โ€” Print only entries that match all PATTERNs instead of requiring only one of them to match. so like, AND instead of OR. picky but make it fashion. ๐Ÿ’…
  • -b, --basename โ€” Match only the base name against the specified patterns. this is the opposite of --wholename. so like, just the filename, not the whole path. ๐ŸŽ€
  • -c, --count โ€” Instead of writing file names on standard output, write the number of matching entries only. just the count, bestie. no names. ๐Ÿ”ข
  • -d, --database DBPATH โ€” Replace the default database with DBPATH. DBPATH is a :-separated list of database file names. if more than one --database option is specified, the resulting path is a concatenation of the separate paths. so you can stack 'em. ๐Ÿ—‚๏ธ
    • An empty database file name is replaced by the default database.
    • A database file name - refers to the standard input.
    • Note that a database can be read from the standard input only once. so don't try to rewind it, it's not a tape. โช
  • -e, --existing โ€” Print only entries that refer to files existing at the time locate is run. like, filtering out the ghosts. ๐Ÿ‘ป
  • -L, --follow โ€” When checking whether files exist (if the --existing option is specified), follow trailing symbolic links. this causes broken symbolic links to be omitted from the output. so broken symlinks get yeeted from the results. ๐Ÿซก
    • This is the default behavior. The opposite can be specified using --nofollow.
  • -h, --help โ€” Write a summary of the available options to standard output and exit successfully. your little cheat sheet. ๐Ÿ“
  • -i, --ignore-case โ€” Ignore case distinctions when matching patterns. FILE and file are the same thing, we don't discriminate. ๐Ÿ” 
  • -l, --limit, -n LIMIT โ€” Exit successfully after finding LIMIT entries. if the --count option is specified, the resulting count is also limited to LIMIT. so like, you can cap the vibes. ๐Ÿ›‘
  • -m, --mmap โ€” Ignored, for compatibility with BSD and GNU locate. it's just there to be polite. ๐Ÿ™ˆ
  • -P, --nofollow, -H โ€” When checking whether files exist (if the --existing option is specified), do not follow trailing symbolic links. this causes broken symbolic links to be reported like other files. so the broken ones show up instead of getting hidden. ๐Ÿ’€
    • This is the opposite of --follow.
  • -0, --null โ€” Separate the entries on output using the ASCII NUL character instead of writing each entry on a separate line. this option is designed for interoperability with the --null option of xargs(1). so if you're piping into xargs, this is your moment. ๐Ÿ”—
  • -S, --statistics โ€” Write statistics about each read database to standard output instead of searching for files and exit successfully. numbers, not names. data queen. ๐Ÿ“Š
  • -q, --quiet โ€” Write no messages about errors encountered while reading and processing databases. silence is golden. ๐Ÿคซ
  • -r, --regexp REGEXP โ€” Search for a basic regexp REGEXP. No PATTERNs are allowed if this option is used, but this option can be specified multiple times. so you can stack regexps but not patterns. pick a lane. ๐Ÿงš
  • --regex โ€” Interpret all PATTERNs as extended regexps. different flavor of regex, same drama. ๐ŸŒˆ
  • -s, --stdio โ€” Ignored, for compatibility with BSD and GNU locate. another polite ghost. ๐Ÿ‘ป
  • -V, --version โ€” Write information about the version and license of locate on standard output and exit successfully. the receipts. ๐Ÿงพ
  • -w, --wholename โ€” Match only the whole path name against the specified patterns. the full path, not just the base. ๐Ÿ›ค๏ธ
    • This is the default behavior. The opposite can be specified using --basename.

๐Ÿ’– EXAMPLES ๐Ÿ’–

so like, say you wanna search for a file named exactly NAME (not *NAME*), here's the move:

locate -b '\NAME'

because \ is a globbing character, this disables the implicit replacement of NAME by *NAME*. so the backslash is doing the heavy lifting. iconic. ๐Ÿซถ


๐ŸŽ€ FILES ๐ŸŽ€

  • /var/lib/mlocate/mlocate.db โ€” The database searched by default. that's the one. the main character database. ๐Ÿ‘‘

๐ŸŒธ ENVIRONMENT ๐ŸŒธ

  • LOCATE_PATH โ€” Path to additional databases, added after the default database or the databases specified using the --database option. so it's like, extra databases appended to the list. ๐Ÿ—ƒ๏ธ

๐Ÿ’€ NOTES ๐Ÿ’€

okay these notes are important, don't skip them just because they're at the bottom. bestie please. ๐Ÿ™

  • The order in which the requested databases are processed is unspecified, which allows locate to reorder the database path for security reasons. so like, don't assume order. it's for your own good. ๐Ÿ”’
  • locate attempts to be compatible to slocate (without the options used for creating databases) and GNU locate, in that order. this is the reason for the impractical default --follow option and for the confusing set of --regex and --regexp options. so like, the weirdness has lore. ๐Ÿ“œ
  • The short spelling of the -r option is incompatible to GNU locate, where it corresponds to the --regex option. Use the long option names to avoid confusion. so like, -r means different things in different places. don't get got. โš ๏ธ
  • The LOCATE_PATH environment variable replaces the default database in BSD and GNU locate, but it is added to other databases in this implementation and slocate. so like, different behavior in different implementations. iykyk. ๐ŸŒ€

๐Ÿฆ‹ AUTHOR ๐Ÿฆ‹

Miloslav Trmac <mitr@redhat.com> โ€” thank you for your service. ๐Ÿซก


โญ SEE ALSO โญ

  • updatedb(8) โ€” the one that actually builds the database. the behind-the-scenes queen. ๐Ÿ‘‘

and that's the whole page, bestie! this was mlocate, dated Sep 2012, and honestly? it ate. ๐Ÿ’…โœจ no cap, fr fr. now go find those files. ๐Ÿฆ‹๐Ÿ’–

๐Ÿ“ฆ where this page comes from