A system may contain too many files for manual cd and ls browsing. find walks the live filesystem, while locate queries a prebuilt path database, trading freshness for speed.
find: query the live filesystem
find . -name "notes.txt" searches recursively from the current directory. Change the starting point to ~ or / to widen the scope. A whole-system search may take time and encounter Permission denied.
Name, type, size, and time conditions
Quote wildcards, as in find /var/log -name "*.log", so the shell does not expand them early. -iname ignores case; -type f selects regular files and -type d directories. Conditions can be combined.
**find /etc -type f -name "*.conf"**Find regular .conf files under /etc.
find /var -type f -size +100MFind regular files over 100 MB; -1M means under 1 MB.
find . -type f -mtime -7Find files modified in the last seven days; +30 commonly means older than 30 days.
find . -name "*.tmp" -exec ls -l \;{} is the current match; preview before using a command that changes data.
locate: fast but potentially stale
locate nginx.conf queries a path database and is usually fast, but a new file may be absent and a deleted path may linger until updatedb refreshes it. Minimal systems may not include locate. Choose find for current truth and locate for a fast search where a slightly stale index is acceptable.
Safety habit: before attaching a modifying command such as rm to find -exec, run the search alone and inspect every match.
Filesystem Search Radar
/varwalk directory tree live/var/log/archive.log/var/log/app.log/etc/nginx/nginx.conf/etc/system.conf/home/alice/report.md/home/bob/notes.txt/home/alice/backup/opt/backup/usr/share/doc/nginx/nginx.conffind /var -type f -name "*.log" -size +100MKNOWLEDGE QUIZ
KNOWLEDGE QUIZ
Audit a Backup Tree
Complete four read-only queries under /srv/backups. Do not delete or modify anything.
- Find every regular file named manifest.json.
- Find regular files larger than 1 GB.
- Find *.tar.gz files modified more than 30 days ago.
- Find directories named archive, ignoring case.