vieyahn2017 / shellv

shell command test and study
4 stars 1 forks source link

12.1 在没有tree命令的系统里,用find实现tree命令 #77

Open vieyahn2017 opened 2 years ago

vieyahn2017 commented 2 years ago

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

vieyahn2017 commented 2 years ago

下面是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命令的系统里。。 ———————————————— 版权声明:本文为CSDN博主「duanyu010」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/duanyu010/article/details/84477202

vieyahn2017 commented 2 years ago

find . -print|sed -e 's;[^/]*/;|--;g;s;--|;   |;g'