find Search for files by name, type, age or size
Walks through a folder and everything under it, and prints the files that match your tests. Use it when you know something about a file, such as its name, age or size, but not where it is. It can also run a command on every match.
Synopsis
find [PATH]... [EXPRESSION]
find PATH -name PATTERN -exec COMMAND {} +
Common options
| Option or form | What it does |
|---|---|
-name PATTERN | Match the file name against a shell pattern such as "*.txt". Case-sensitive. Quote the pattern so the shell does not expand it |
-iname PATTERN | Same as -name but ignores upper and lower case, so "readme*" also matches README.md |
-type c | Match by type: f for regular file, d for directory, l for symbolic link |
-mtime N | Match by modification time in whole days. -mtime -1 is within the last day, -mtime +7 is more than 7 days ago |
-size N | Match by size. Add a unit: k, M or G. +1M is larger than 1 megabyte, -10k is smaller than 10 kilobytes |
-maxdepth N | Go no more than N levels down. -maxdepth 1 stays in the starting folder. Put it before other tests |
-exec COMMAND {} + | Run a command on the matches. {} stands for the file names. End with + to pass many files at once, or a backslash and semicolon to run once per file |
-delete | Delete every match. Dangerous: see the notes before using it |
Examples
find . -name "*.txt"
find . -iname "README*"
./docs/readme.md
find . -maxdepth 1 -type f
find . -type f -mtime -1 -size +0c
find photos -name "*.jpg" -exec ls -l {} +
find . -name "*.tmp" -type f && find . -name "*.tmp" -type f -delete
Notes
- Order matters. The starting path comes first, then the tests: find . -name "*.txt", not find -name "*.txt" . Modern GNU and macOS find default to the current folder if you leave the path out, but older and strict POSIX versions need it, so always write it.
- -name matches only the last part of the path, so -name "docs/*.md" never matches. Use -path for that. -name is case-sensitive and -iname is not. Quote the pattern, or the shell may expand *.txt against your current folder before find sees it.
- -mtime counts whole 24-hour periods, so -mtime 1 means exactly one day ago, not within a day. Use -mtime -1 for newer than a day and -mtime +1 for older. -size also rounds up, and without a unit it counts 512-byte blocks, not bytes. Use c for bytes.
- Ending -exec with a backslash and semicolon (\;) runs the command once per file, which is slow on large trees. Ending with + batches files and is faster. Filenames with spaces are handled safely by -exec, but not by a pipe into xargs unless you use -print0 and xargs -0.
- Warning: -delete removes files immediately, with no confirmation and no trash. Always run the same command without -delete first and read the output. Put -delete last, after all the tests. If it comes first, find tries to delete everything it visits. The same care applies to -exec rm.
See also
Last reviewed 2026-10-07.