๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

๐Ÿ’ก File Viewing & Searching August 10, 2026 2

Linux Command: locate

Find files by name using a pre-built database

Terminal โ€” File Viewing & Searching
Command
$ locate nginx.conf
Output
/etc/nginx/nginx.conf\n/etc/nginx/nginx.conf.bak

The locate command finds files by name using a pre-built database, making it orders of magnitude faster than find for simple name searches. It searches a database of file paths rather than traversing the filesystem. The database is typically updated daily by a cron job running updatedb, or can be refreshed manually. Because it uses a database, locate cannot find files created since the last database update. locate supports pattern matching with wildcards and regular expressions. It is ideal for quickly finding where a file or program is installed, locating configuration files, and general file discovery tasks where real-time accuracy is not critical.

Syntax

locate [OPTION]... PATTERN

Key Options

  • -i โ€” Case-insensitive search
  • -c โ€” Print only the count of matches
  • -l โ€” Limit output to N results
  • -r โ€” Use POSIX regex instead of glob pattern
  • -e โ€” Print only existing files (skip deleted)
  • -b โ€” Match only the basename (filename without path)

Examples

Find a file quickly

locate nginx.conf

Output: /etc/nginx/nginx.conf\n/etc/nginx/nginx.conf.bak

Case-insensitive search

locate -i readme

Count matching files

locate -c "*.php"

Output: 2847

Pro Tips

  • locate uses a pre-built database. Newly created files will not appear until updatedb runs. Use find for real-time searches.
  • locate is 100-1000x faster than find for simple name searches. Use it as your first tool, then switch to find if you need freshness or complex criteria.
  • Modern Linux uses plocate (faster) or mlocate. Both provide the locate command with compatible interfaces.

Learn more: Full locate reference โ†’

Share this tip