A disk fills up, or a config file vanishes, and suddenly we need one file out of fifty thousand. find is the tool for that, and its shape never changes: find, then where to look, then what to match. find . -name '*.log' lists every .log file under the current folder; swap the dot for /var/log to search there instead. From there we filter. -type f keeps it to files (d for directories), -size +100M pulls out the big ones. -mtime -7 catches anything changed this week. Then we act on the matches with -delete or -exec. It ships on every Linux and macOS box, no install. Here's the everyday syntax we actually reach for, plus the safe way to delete matches without wiping the wrong tree.
The short answer
find . -name '*.log' lists matching files below the current folder. Narrow
with -type and -size (or -mtime for age), then act with -delete or
-exec. Run it without -delete first and read the list. Every time.
Find by name
find . -name '*.log' That walks the current folder and everything under it. Case getting in the
way? -iname matches without caring about it.
Filter by size or age
find /var/log -name '*.log' -mtime +30 That one lists logs nobody has touched in a month. And when something’s eating the disk, we match on size, files only:
find . -type f -size +100M Act on the results, carefully
find . -name '*.tmp' -delete Run it once without -delete and read the list. Every line. find does
exactly what we tell it, including deleting a tree we never meant to touch.
I’ve watched that happen, and it’s a bad afternoon.
Other handy filters
-type d finds directories, -empty finds empty files or folders. -newer ref
matches anything modified more recently than a reference file, and -exec command {} + runs a command on every match when -delete isn’t what you need.
Frequently asked questions
How do I find a file by name?
find . -name '*.conf' lists every .conf file under the current directory. -iname does the same job but ignores case. And keep the quotes around the pattern, otherwise the shell expands the star before find ever sees it.
How do I find files bigger than a certain size?
It's -size plus a suffix: -size +100M means larger than 100 MB, -size -1k means smaller than 1 KB. We always add -type f too, so it matches files only, not directories.
How do I find files changed recently?
Days are the unit for -mtime: -mtime -7 means modified in the last 7 days, -mtime +30 means older than 30 days. Need minutes instead? -mmin works exactly the same way.
How do I delete the files I found, safely?
Run the find without -delete first and actually read the list. Once it's exactly right, append -delete (or -exec rm to act on each one). Deleting blind is how people erase the wrong tree. Look first, every time.