Linux Command: locate
Find files by name using a pre-built database
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]... PATTERNKey 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.confOutput: /etc/nginx/nginx.conf\n/etc/nginx/nginx.conf.bak
Case-insensitive search
locate -i readmeCount 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 โ