find Commands

find commands cheatsheet.

Locate files by name, size or age — then act on them. Tap any command to copy it.

By name & type
find . -name '*.txt'Find files by name pattern
find . -iname '*.txt'Case-insensitive name search
find . -type fFind files only (not directories)
find . -type dFind directories only
find . -name '*.log' -type fCombine name and type
By size, time & depth
find . -size +100MFiles larger than 100 MB
find . -size -1kFiles smaller than 1 KB
find . -mtime -7Modified in the last 7 days
find . -mtime +30Not modified in over 30 days
find . -maxdepth 1 -name '*.sh'Limit the search to one level deep
find . -emptyFind empty files and directories
Act on the results
find . -name '*.tmp' -deleteDelete every matching file
find . -name '*.sh' -exec chmod +x {} \;Run a command once per result
find . -name '*.log' -exec rm {} +Run once with all results batched
find . -type f | xargs grep 'pattern'Pipe results into another command
Owner & permissions
find . -perm 644Find files with specific permissions
find . -user aliceFind files owned by a user
find . -type f -name '*.jpg' | wc -lCount files matching a pattern
-exec cmd {} \; runs the command once for each file; -exec cmd {} + passes many files to one invocation (faster). Test destructive runs by swapping -delete for -print first.

How find thinks

find walks a directory tree and tests every file against the conditions you give it. The first argument is where to start (. for the current directory), and everything after is a filter. -name '*.txt' matches by filename (use -iname to ignore case), and -type f or -type d restricts to files or directories. Conditions stack left to right, so find . -type f -name '*.log' reads naturally as "files, named *.log, under here."

Filtering by size and age

Two of find's most useful filters are size and time. -size +100M finds files bigger than 100 megabytes (great for tracking down what's filling a disk), and -mtime -7 finds files modified in the last seven days (+30 flips it to "older than 30 days"). The + and - prefixes mean "more than" and "less than", a convention that trips people up until it clicks. -maxdepth stops find from descending too far, which keeps big searches fast.

Acting on what you find

Finding files is only half the job — usually you want to do something with them. -delete removes matches (always preview with -print first), while -exec runs any command on each result, with {} standing in for the filename. The terminator matters: \; runs the command once per file, and + batches many files into a single call for speed. For more complex pipelines, piping find's output into xargs is the classic combo. Pair find with grep to search inside the files you locate.

FAQ

How do I find files modified in the last day?
Use find . -mtime -1, which matches files changed within the last 24 hours. Use +1 instead for files older than a day, and -mmin -60 for the last hour.
What's the difference between -exec {} \; and -exec {} +?
With \; find runs the command separately for every matched file; with + it groups many files into one command invocation, which is much faster for large result sets.

More cheatsheets