Locating the right file or folder quickly in Linux matters when configuration paths, logs, backups, or application data are spread across a large filesystem. Fast, precise searches reduce guesswork before editing files, rotating data, or checking whether a directory exists in the expected location.
The find command walks the live filesystem from a starting path and tests each entry against conditions such as name, type, depth, size, and modification time. The locate command answers the same kind of question from a prebuilt path index, so it is much faster for broad lookups but only as current as its last updatedb run.
Search scope affects both speed and signal. Running find from a focused starting directory is usually faster and clearer than searching from /, while system-wide searches may need sudo and can still return permission errors unless they are redirected. Indexed lookups also vary by distribution: many current systems provide locate through plocate or an mlocate-compatible package, and minimal installs may not include it until added.
$ find /srv/search-demo -type f -name "report-2024.txt" /srv/search-demo/reports/report-2024.txt
-type f limits matches to regular files so directories with the same name are excluded.
$ find /srv/search-demo -type d -name "reports" /srv/search-demo/reports
-type d returns directories only, which is useful when the target is a project tree, upload directory, or application data path.
$ find /srv/search-demo -maxdepth 2 -type f -name "*.txt" | sort /srv/search-demo/.hidden.txt /srv/search-demo/reports/report-2023.txt /srv/search-demo/reports/report-2024.txt
Quote glob patterns such as "*.txt" so the shell does not expand them before find runs.
$ find /srv/search-demo -type f -iname "settings.conf" /srv/search-demo/Archive/Settings.conf
The -iname test is useful on mixed-case directory trees where the file name is remembered but not its exact spelling.
$ find /srv/search-demo/reports -type f -mtime -2 | sort /srv/search-demo/reports/report-2023.txt /srv/search-demo/reports/report-2024.txt
-mtime -2 matches files modified within the last two 24-hour periods. Use +N for files older than N days.
$ find /srv/search-demo -type f -size +1M /srv/search-demo/large.bin
Size tests accept units such as k, M, and G. Prefix the value with + for larger than or - for smaller than the threshold.
$ sudo find / -xdev -type f -name "shadow" 2>/dev/null /etc/shadow
-xdev keeps the search on the current filesystem, which prevents results from expanding into mounted backup, container, or network volumes. Redirecting stderr hides permission noise, so use it only when the search scope is already clear.
$ sudo updatedb
On many current distributions, updatedb is provided by plocate and usually runs from a scheduled timer. Minimal installations may not include locate until the package is added.
$ locate report-2024.txt /srv/search-demo/reports/report-2024.txt
locate searches the last built database, so renamed or newly created paths can be missing until the index is refreshed.
$ ls -ld /srv/search-demo/reports/report-2024.txt -rw-r--r-- 1 root root 5 Apr 14 10:15 /srv/search-demo/reports/report-2024.txt
Listing the match confirms the file type, permissions, timestamp, and final path before a follow-up action such as opening the file or removing it.