find a files with -maxdepth and -mindepth

Unix utility find allows many arguments. Here is how one can limit searched directories. Arguments -maxdepth and -mindepth should be used first before let’s say -name or -type.

Let’s created four sub directories to investigate how it works:

$ mkdir -p a/b/c/d

$ find a
a
a/b
a/b/c
a/b/c/d

$ find a -maxdepth 2
a
a/b
a/b/c

$ find a -maxdepth 2 -mindepth 2
a/b/c

$ find a -mindepth 2
a/b/c
a/b/c/d

See also find a files with mmin

This entry was posted in workday. Bookmark the permalink.

Leave a Reply