locate — Find files by name
Linux / Basic Linux commands / locate.html
Finds file paths quickly using a prebuilt database.
Basic Information
| Command Name | locate |
|---|---|
| One-line Introduction | Finds file paths quickly using a prebuilt database. |
| Provided by | plocate or mlocate |
| Official Documentation | https://man7.org/linux/man-pages/man1/locate.1.html |
| Supported Operating Systems | Linux, macOS (separate install), BSD |
| Installation Status | Requires a package |
| Category | Linux basic commands (tags: Linux basic commands (tags: locate, file search, updatedb, plocate)) |
What is this command?
locate queries a database instead of walking the file system, so it returns paths very quickly. Changes made after the database was built are not reflected.
The database is refreshed by updatedb, usually through a daily timer. If a newly created file is missing, run updatedb or use find.
What problems does it solve?
- When you know a file name but not its path
- Searching large file systems quickly
- Locating configuration files
- When find feels too heavy
Key features
Fast search
Queries the database and answers immediately.
- When to use: Finding names across wide trees
- What you get: It is much faster than find.
- Limitations: Recent changes may be missing.
Pattern search
Match names with wildcards or regex.
- When to use: Grouping by extension or prefix
- What you get: Narrows candidates at once.
- Limitations: Case sensitivity depends on database settings.
Database refresh
Run updatedb to reflect the current state.
- When to use: When a just-created file must be found
- What you get: Search accuracy improves.
- Limitations: A full refresh is I/O heavy.
Installation and usage
Check whether it is installed
locate --version
sudo apt install plocate # Debian/Ubuntu sudo dnf install mlocate # Fedora
Real-world examples
Find by name
Search by exact file name.
locate nginx.conf | head
Find by pattern
Find by extension.
locate -i '*.service' | head
Refresh the database
Reflect the latest files.
sudo updatedb
locate mynewfile