benzhou 发表于 2017-5-16 11:22:34

[shell] 在没有tree命令的系统里,用find实现tree命令

  转自: http://xnlinux.haotui.com/thread-1669-1-1.html
 
下面是tree命令显示的结果:
gao@gao-virtual-machine:~/test$ tree
.
|-- test1
|   |-- test11
|   |   |-- test111
|   |   |-- test112
|   |   `-- test113
|   |-- test12
|   `-- test13
|-- test2
|   |-- test21
|   |-- test22
|   `-- test23
`-- test3
    |-- test31
    |-- test32
    `-- test33

下面是find . -print|sed -e 's;[^/]*/;|--;g;s;--|;   |;g' 命令出来的结果:
gao@gao-virtual-machine:~/test$ find . -print|sed -e 's;[^/]*/;|--;g;s;--|;   |;g'
.
|--test3
|   |--test31
|   |--test33
|   |--test32
|--test1
|   |--test11
|   |   |--test111
|   |   |--test113
|   |   |--test112
|   |--test12
|   |--test13
|--test2
|   |--test23
|   |--test21
|   |--test22
使用find即可实现tree的功能了,特别是在没有tree命令的系统里。。
页: [1]
查看完整版本: [shell] 在没有tree命令的系统里,用find实现tree命令