LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1019|回复: 7

怎样让 find 的输出目录层次 由深到浅?

[复制链接]
发表于 2006-3-12 20:01:32 | 显示全部楼层 |阅读模式
比如路径:/AA/BB/CC/DD

按 find / -name * -type d 的结果类似于:

/
/AA
/AA/BB
/AA/BB/CC
/AA/BB/CC/DD

也就是说,目录层次是由浅到深的。 现在我想让输出的目录层次由深到浅,即类似于:

/AA/BB/CC/DD
/AA/BB/CC
/AA/BB
/AA
/

应当怎样实现呢? 谢谢
发表于 2006-3-12 20:18:02 | 显示全部楼层
pipe到tac
回复 支持 反对

使用道具 举报

发表于 2006-3-12 20:35:21 | 显示全部楼层
$ find
.
./23
./23/34
./23/34/45

$ find -depth
./23/34/45
./23/34
./23
.
回复 支持 反对

使用道具 举报

发表于 2006-3-12 20:49:57 | 显示全部楼层
好像这样还不是最理想:

  1. find AA -type d
  2. AA
  3. AA/BB
  4. AA/BB/CC
  5. AA/BB/CC/DD
  6. AA/BB/CC/EE
  7. AA/BB/CC/EE/FF

  8. find AA -type d -depth
  9. 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.

  10. AA/BB/CC/DD
  11. AA/BB/CC/EE/FF
  12. AA/BB/CC/EE
  13. AA/BB/CC
  14. AA/BB
  15. AA
复制代码

当然最好避免pipe。
回复 支持 反对

使用道具 举报

发表于 2006-3-12 21:00:07 | 显示全部楼层
语法应该是:find 23 -depth -type d,就不会出现那个 warning 了。

$ find
./AA
./AA/BB
./AA/BB/CC
./AA/BB/CC/EE
./AA/BB/CC/EE/FF
./AA/BB/DD

$ find -depth
./AA/BB/CC/EE/FF
./AA/BB/CC/EE
./AA/BB/CC
./AA/BB/DD
./AA/BB
./AA
.
回复 支持 反对

使用道具 举报

发表于 2006-3-12 21:03:40 | 显示全部楼层
对的,warning没了,连warning内容都没注意,不该啊。
find AA -depth -type d
AA/BB/CC/DD
AA/BB/CC/EE/FF
AA/BB/CC/EE
AA/BB/CC
AA/BB
AA

但最理想的是否应该是
AA/BB/CC/EE/FF
排在最前。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-12 21:11:22 | 显示全部楼层
非常谢谢FF兄和seamonkey兄!
回复 支持 反对

使用道具 举报

发表于 2006-3-12 21:14:21 | 显示全部楼层
不客气,_welans_兄。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表