List all directories recursively in a tree format

前端 未结 5 1930
春和景丽
春和景丽 2020-12-28 09:47

I want to simulate a tree command using Shell Script that displays all the directories recursively in this format:

.
|-- Lorem
|-- Lorem
|-- Lor         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 10:19

    Try doing this (not exactly the same output, but very close) :

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

    From http://mlsamuelson.com/content/tree-approximation-using-find-and-sed

    with awk

    find . -type d -print 2>/dev/null|awk '!/\.$/ {for (i=1;i

    See http://www.unix.com/shell-programming-scripting/50806-directory-tree.html

提交回复
热议问题