linux find depth参数理解

man find 
-depth Process each directory’s contents before the directory itself.

参数-depth 的意思是:在处理目录以前首先处理目录下的子内容。
也即是说在不加-depth的时候, 处理顺序是首先处理目录本身,然后处理目录下的子内容。加不加-depth参数,会影响输出结构的输出顺序。

-------------------------------------------------------------
例如下面的两个命令,输出结果是相反的:
先输出子内容,再输出上层目录内容,直到最顶层:
[oracle@oracledb ~]$ find test -depth  ! -empty
test/test1/test2/test3
test/test1/test2
test/test1
test

先输出顶层目录,再输出下面的各层子目录内容,直到最低层:
[oracle@oracledb ~]$ find test   ! -empty
test
test/test1
test/test1/test2
test/test1/test2/test3
---------------------------------------------------------------


去掉顶层目录test的那行输出, 加-mindepth 1(可以看到输出结果为3行,少了一会"test")。因为默认是包含顶层目录的:
[oracle@oracledb ~]$ find test -depth  -mindepth 1  ! -empty  
test/test1/test2/test3
test/test1/test2
test/test1


[oracle@oracledb ~]$ find test  -mindepth 1  ! -empty
test/test1
test/test1/test2
test/test1/test2/test3




请使用浏览器的分享功能分享到微信等