任务:列出目录本身的所有直接后代。
在 BSD (Mac OS) 上find . -type d -depth 1
有效。
这是 Ubuntu 12.04(GNU findutils 4.4.2)的输出:
$ find . -type d -depth 1
find: warning: you have specified the -depth option after a non-option argument -type,
but options are not positional (-depth affects tests specified before it as well as
those specified after it). Please specify options before other arguments.
find: paths must precede expression: 1
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
好的,下次试试:
$ find . -depth 1 -type d
find: paths must precede expression: 1
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
嗯,好吧,也许它想要...
$ find -depth 1 . -type d
find: paths must precede expression: 1
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
显然不是,wtf,它应该需要......
$ find . -depth=1 -type d
find: unknown predicate `-depth=1'
不,这很明显。所以让我们尝试作为最后的手段......
$ find . -mindepth 1 -maxdepth 1 -type d
<my directories>
耶,成功!但是,呃,为什么……?
而且,作为一个额外的问题,为什么比BSD / OSX-mindepth 1 -maxdepth 1
快得多?-depth 1