[find] Limit search depth with -maxdepth

Created on November 30, 2026

Use -maxdepth to stop a search at a particular depth. The starting directory is depth 0. Suppose the directory tree looks like this.

.
├── logs
│   ├── app.log
│   └── archive
│       └── old.log
└── main.txt

This command lists regular files at depths up to 2.

find . -maxdepth 2 -type f | sort
./logs/app.log
./main.txt

./logs/archive/old.log is at depth 3, so it falls outside the search.

Shell command find