find

find walks a tree recursively.

Name and depth

find <path> -name "<pattern>"

The search is recursive.

-maxdepth <n> and -mindepth <n> limit how deep it goes.

Empty directories

Print names of empty directories:

find <path> -type d -empty -printf "%f\n"

Exec

Run a command on each match. {} is the path; \; ends -exec.

find <path> -type d -maxdepth 1 -exec <command> {} \;

Example -exec:

-exec ln -s <path>

find includes the starting path, e.g. ./. Use basename to get the file name. basename cannot be mixed with other commands; it should be the only command of -exec.

-type -f excludes the starting-directory include (self).

Modified within last period

find /to/target/directory* -mmin 30

Form:

<path> <time-option> <[+/-]<units>>

Time options:

  • mtime — modified, in days
  • -cmin — accessed, in minutes
  • -newermt — newer created
Updated: 2026 Aug 19