# man > find(1)

---
type: CommandReference
command: find
mode: man
section: "1"
source: man-pages
---

## Quick Reference

- `find {{path/to/directory}} -name '{{*.ext}}'` — Find files by extension.
- `find {{path/to/directory}} -path '{{*/path/*/*.ext}}' -or -name '{{*pattern*}}'` — Find files matching multiple path/name patterns.
- `find {{path/to/directory}} -type d -iname '{{*lib*}}'` — Find directories matching a given name, case-insensitive.
- `find {{path/to/directory}} -name '{{*.py}}' -not -path '{{*/site-packages/*}}'` — Find files matching a pattern, excluding specific paths.
- `find {{path/to/directory}} -maxdepth 1 -size {{+500k}} -size {{10M}}` — Find files matching a size range, limiting depth to 1.
- `find {{path/to/directory}} -name '{{*.ext}}' -exec {{wc -l}} {} \;` — Run a command for each file.
- `find {{path/to/directory}} -daystart -mtime {{1}} -exec {{tar -cvf archive.tar}} {} \+` — Find files modified today and pass to a single command.
- `find {{path/to/directory}} -type {{f|d}} -empty -delete -print` — Search for empty files or directories and delete them verbosely.

## Name

**find** — search for files in a directory hierarchy

## Synopsis

`find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression]`

## Options

### Symbolic Link Options

- `-P` — Never follow symbolic links (default).
- `-L` — Follow symbolic links. Implies `-noleaf`.
- `-H` — Do not follow symbolic links except while processing command line arguments.

### Debug Options

- `-D debugopts` — Print diagnostic information. Valid debug options: `exec`, `opt`, `rates`, `search`, `stat`, `tree`, `all`, `help`.

### Optimization

- `-Olevel` — Enable query optimisation. Level 0-3. Default 1.

### Global Options

- `-d` — Synonym for `-depth`.
- `-depth` — Process directory contents before the directory itself.
- `-help`, `--help` — Print usage summary.
- `-ignore_readdir_race` — Ignore errors when a file is deleted between reading and stating.
- `-maxdepth levels` — Descend at most `levels` levels.
- `-mindepth levels` — Do not apply tests/actions at levels less than `levels`.
- `-mount` — Don't descend directories on other filesystems (synonym for `-xdev`).
- `-noignore_readdir_race` — Turns off `-ignore_readdir_race`.
- `-noleaf` — Do not optimise directory link count assumption.
- `-version`, `--version` — Print version and exit.
- `-xdev` — Don't descend directories on other filesystems.

### Positional Options

- `-daystart` — Measure times from beginning of today.
- `-follow` — Deprecated; use `-L`. Dereference symbolic links.
- `-regextype type` — Set regex syntax for `-regex`/`-iregex`.
- `-warn`, `-nowarn` — Turn warning messages on/off.

### Tests

Numeric arguments: `+n` (greater than), `-n` (less than), `n` (exactly).

- `-amin n` — File last accessed `n` minutes ago.
- `-anewer reference` — Access time more recent than reference's modification time.
- `-atime n` — File last accessed `n*24` hours ago.
- `-cmin n` — Status last changed `n` minutes ago.
- `-cnewer reference` — Status change time more recent than reference's modification time.
- `-ctime n` — Status last changed `n*24` hours ago.
- `-empty` — File is empty (regular file or directory).
- `-executable` — File is executable by current user.
- `-false` — Always false.
- `-fstype type` — File is on filesystem of type `type`.
- `-gid n` — Numeric group ID is `n`.
- `-group gname` — File belongs to group `gname`.
- `-ilname pattern` — Case-insensitive `-lname`.
- `-iname pattern` — Case-insensitive `-name`.
- `-inum n` — Inode number is `n`.
- `-ipath pattern` — Case-insensitive `-path`.
- `-iregex pattern` — Case-insensitive `-regex`.
- `-iwholename pattern` — See `-ipath`.
- `-links n` — Number of hard links is `n`.
- `-lname pattern` — Symbolic link whose contents match pattern.
- `-mmin n` — Data last modified `n` minutes ago.
- `-mtime n` — Data last modified `n*24` hours ago.
- `-name pattern` — Base of filename matches shell pattern.
- `-newer reference` — Modification time more recent than reference's.
- `-newerXY reference` — Compare timestamps X and Y (a: access, B: birth, c: status change, m: modification, t: direct time).
- `-nogroup` — No group corresponds to numeric GID.
- `-nouser` — No user corresponds to numeric UID.
- `-path pattern` — Full filename matches shell pattern.
- `-perm mode` — Permission bits exactly `mode` (octal/symbolic). Use `-` for all bits set, `/` for any bit set.
- `-readable` — File is readable by current user.
- `-regex pattern` — Full filename matches regular expression.
- `-samefile name` — Same inode as `name`.
- `-size n[cwbkMG]` — File uses `n` units of space (b: 512-byte blocks, c: bytes, w: 2-byte words, k: KiB, M: MiB, G: GiB).
- `-true` — Always true.
- `-type c` — File is of type: `b` (block), `c` (character), `d` (directory), `p` (named pipe), `f` (regular file), `l` (symbolic link), `s` (socket), `D` (door). Comma-separated list allowed.
- `-uid n` — Numeric user ID is `n`.
- `-used n` — Last accessed `n` days after status change.
- `-user uname` — File owned by user `uname`.
- `-wholename pattern` — See `-path`.
- `-writable` — File is writable by current user.
- `-xtype c` — Like `-type` but for symbolic links: checks target type if `-H`/`-P`, else `l` if `-L`.
- `-context pattern` — (SELinux) Security context matches pattern.

### Actions

- `-delete` — Delete files; implies `-depth`.
- `-exec command {} ;` — Execute command once per file, `{}` replaced by filename. Return true if exit status 0.
- `-exec command {} +` — Execute command with multiple filenames appended. Only one `{}` allowed at end.
- `-execdir command {} ;` — Like `-exec` but run from subdirectory containing the file.
- `-execdir command {} +` — Like `-execdir` with multiple files, only from same subdirectory.
- `-fls file` — Like `-ls` but write to `file`.
- `-fprint file` — Print full filename to `file`.
- `-fprint0 file` — Like `-print0` but write to `file`.
- `-fprintf file format` — Like `-printf` but write to `file`.
- `-ls` — List file in `ls -dils` format.
- `-ok command {} ;` — Like `-exec` but prompt user.
- `-okdir command {} ;` — Like `-execdir` but prompt user.
- `-print` — Print full filename followed by newline.
- `-print0` — Print full filename followed by null character.
- `-printf format` — Print formatted string with escapes (`\n`, `\t`, etc.) and `%` directives (e.g., `%p` filename, `%f` basename, `%h` dirname, `%s` size, `%m` permissions, `%t` mtime).
- `-prune` — If file is a directory, do not descend into it.
- `-quit` — Exit immediately (with zero return value if no errors).

### Operators

Listed in decreasing precedence:

- `( expr )` — Force precedence.
- `! expr` — Logical NOT.
- `-not expr` — Same as `! expr`.
- `expr1 expr2` — Implied AND; `expr2` evaluated only if `expr1` true.
- `expr1 -a expr2` — Explicit AND.
- `expr1 -and expr2` — Same as `-a`.
- `expr1 -o expr2` — Logical OR; `expr2` evaluated only if `expr1` false.
- `expr1 -or expr2` — Same as `-o`.
- `expr1 , expr2` — List; both evaluated, value of `expr2` used.

## Examples

### Simple `find|xargs` approach

shell
$ find /tmp -name core -type f -print | xargs /bin/rm -f
### Safer `find -print0 | xargs -0` approach

shell
$ find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
### Executing a command for each file

shell
$ find . -type f -exec file '{}' \;
### Traversing the filesystem just once — for 2 different actions

shell
$ find / \
    \( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \) , \
    \( -size +100M -fprintf /root/big.txt '%-10s %p\n' \)
### Searching files by age

shell
$ find $HOME -mtime 0
### Searching files by permissions

shell
$ find . -perm -664
$ find . -perm /222
$ find . -perm -a+r -perm /a+w \! -perm /a+x
### Pruning — omitting files and subdirectories

shell
$ find . -name .snapshot -prune -o \( \! -name '*~' -print0 \) | cpio -pmd0 /dest-dir
### Search for several file types

shell
$ find /tmp -type f,d,l
### Find first occurrence and stop

shell
$ find / -name needle -print -quit
## See Also

- [chmod(1)](https://www.chedong.com/phpMan.php/man/chmod/1/markdown)
- [locate(1)](https://www.chedong.com/phpMan.php/man/locate/1/markdown)
- [ls(1)](https://www.chedong.com/phpMan.php/man/ls/1/markdown)
- [updatedb(1)](https://www.chedong.com/phpMan.php/man/updatedb/1/markdown)
- [xargs(1)](https://www.chedong.com/phpMan.php/man/xargs/1/markdown)
- [lstat(2)](https://www.chedong.com/phpMan.php/man/lstat/2/markdown)
- [stat(2)](https://www.chedong.com/phpMan.php/man/stat/2/markdown)
- [ctime(3)](https://www.chedong.com/phpMan.php/man/ctime/3/markdown)
- [fnmatch(3)](https://www.chedong.com/phpMan.php/man/fnmatch/3/markdown)
- [printf(3)](https://www.chedong.com/phpMan.php/man/printf/3/markdown)
- [strftime(3)](https://www.chedong.com/phpMan.php/man/strftime/3/markdown)
- [locatedb(5)](https://www.chedong.com/phpMan.php/man/locatedb/5/markdown)
- [regex(7)](https://www.chedong.com/phpMan.php/man/regex/7/markdown)

Full documentation: <https://www.gnu.org/software/findutils/find> or `info find`

## Exit Codes

- `0` — All files processed successfully.
- `>0` — Errors occurred; results may not be reliable.