Skip to main content
As a system administrator you’ll frequently need to locate files—configuration files, logs, scripts, or misplaced data. This guide shows how to search a Linux file system quickly and reliably using the find and locate commands. It explains when to use each tool, demonstrates a short root-level demo, and provides practical find examples you can adapt on RHEL or other Linux distributions. Why use these tools?
  • find searches the filesystem in real time and is precise and flexible.
  • locate is much faster because it queries a pre-built database rather than scanning the whole disk.
Use find for accuracy and complex filtering. Use locate for speed when a periodically updated index is sufficient.
The updatedb command refreshes the database used by locate. On many systems this runs automatically (cron or systemd timers), but you can run updatedb manually to get the latest results. It typically requires root privileges to index the full filesystem.
A dark presentation slide titled "Demo: Locating and Finding Files" on the left. On the right is a simple blue outline icon of a folder with a magnifying glass.
Demo (run as root) Steps:
  1. Create a directory and a file.
  2. Try locate (it won’t find the file until the database is updated).
  3. Run updatedb, then use locate again.
  4. Demonstrate find examples for real-time search.
Example session:
Using locate
  • Very fast because it uses an indexed database.
  • By default locate is case-sensitive. Use -i for case-insensitive searches:
  • Keep in mind locate results reflect the state of the last database update; newly created files may not appear until after updatedb runs.
Using find (real-time, powerful) Basic syntax:
  • Start directory then expression:
    • find <start-dir> <expression>
  • Examples below assume you are searching from the current directory . or root /.
Common find options and examples Practical find examples
Advanced capabilities
  • find supports many more predicates: permissions (-perm), modification time (-mtime, -mmin), pruning directories you want to skip (-prune), and executing commands on matches (-exec, -ok).
  • For complex tasks, combine find with xargs, -print0, or -exec ... + for efficient processing.
find is extremely flexible — use man find to explore predicates like -mtime, -perm, -prune, and -exec. For large searches consider -xdev to avoid crossing filesystem boundaries, and -mount on some systems.
Quick comparison Links and references Summary
  • Use locate when you want very fast filename lookups and can tolerate slightly out-of-date results; refresh its database with updatedb as needed.
  • Use find for accurate, on-the-fly searches and advanced filtering. It’s slower but far more powerful.

Watch Video

Practice Lab