Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos Ubuntu上的findutils 4.4.x不允许我指定'depth'选项_Macos_Ubuntu_Command Line_Gnu Findutils - Fatal编程技术网

Macos Ubuntu上的findutils 4.4.x不允许我指定'depth'选项

Macos Ubuntu上的findutils 4.4.x不允许我指定'depth'选项,macos,ubuntu,command-line,gnu-findutils,Macos,Ubuntu,Command Line,Gnu Findutils,任务:列出目录本身的所有直接代理 在BSD(Mac OS)上,find-d型-深度1工作正常 这是Ubuntu 12.04(GNU findutils 4.4.2)的输出: 好的,下一次尝试: $ 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...]

任务:列出目录本身的所有直接代理

在BSD(Mac OS)上,
find-d型-深度1工作正常

这是Ubuntu 12.04(GNU findutils 4.4.2)的输出:

好的,下一次尝试:

$ 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>
$find-mindepth 1-最大深度1-d型
耶,成功但是,呃,为什么


另外,作为一个额外的问题,
-mindepth 1-maxdepth 1
为什么比BSD/OSX上的
-depth 1
快得多?

-depth
选项不带参数:

-depth Process each directory's contents before the directory itself.

-name
-type
这样的选项后面应该跟一些东西,这不适用于
-depth
。它更像是一个布尔选项。

不同版本的
find
使用
-depth
primary表示完全不同的含义:

  • -depth
    表示执行深度优先搜索(即访问目录本身之前的内容)。这与大多数原色不同,因为它不控制匹配的文件,而是控制搜索的执行方式。据我所知,所有版本的
    find
    都支持此功能

  • -depth n
    表示仅匹配深度为n的项目(即您想要的内容)。这是一个完全不同于
    -depth
    的含义,当它后面没有数字时,可能会非常混乱。另外,并非所有版本的
    find
    都支持这一点(OSX支持,GNUfindutils显然不支持)


-find n
主要功能很有用,但不幸的是不可移植。如果您需要便携性,我想您必须使用
-mindepth n-maxdepth n

Hrm,那么我应该使用RTFM,谢谢您的提示。如果文件相对于遍历起点的深度为n,则BSD手册页会告诉我
-depth n:True。
。很明显我滥用这个选项好几年了,该死的。。。
-depth Process each directory's contents before the directory itself.