That command is written for the FreeBSD version of find
(or similar), and you're running it with another find that doesn't support -depth n
. Probably the GNU one, based on the error message. The FreeBSD version has two -depth
options (man page):
-depth
Always true; same as the non-portable -d option. Cause find to
perform a depth-first traversal, i.e., directories are visited in
post-order and all entries in a directory will be acted on before
the directory itself. By default, find visits directories in
pre-order, i.e., before their contents. Note, the default is not
a breadth-first traversal.
-depth n
True if the depth of the file relative to the starting point of
the traversal is n.
That first one is standard(*), the second isn't. Since the standard one doesn't take an argument, and lone arguments (paths) can't be given within or after the find expression (as you saw), the FreeBSD version can somewhat get away with overriding the name. (It might still be error-prone in that forgetting the argument to -depth
would change the meaning.)
GNU and Busybox have the equally non-standard -mindepth n
and -maxdepth n
which when together can be used to require a particular depth:
find . -mindepth 1 -maxdepth 1 -type d
Note that you probably shouldn't use for f in $(find ...)
, as you'll face issues if any filenames contain whitespace.
See:
(* Like the text implies, the name -depth
is inaccurate for a pre-/post-order switch.)