Linux command to print directory structure in the form of a tree

后端 未结 9 1040
野趣味
野趣味 2020-11-28 00:05

Is there any linux command that I can call from a Bash script that will print the directory structure in the form of a tree, e.g.,

folder1
   a.txt
   b.txt
         


        
9条回答
  •  执笔经年
    2020-11-28 00:29

    This command works to display both folders and files.

    find . | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"
    

    Example output:

    .
     |-trace.pcap
     |-parent
     | |-chdir1
     | | |-file1.txt
     | |-chdir2
     | | |-file2.txt
     | | |-file3.sh
     |-tmp
     | |-json-c-0.11-4.el7_0.x86_64.rpm
    

    Source: Comment from @javasheriff here. Its submerged as a comment and posting it as answer helps users spot it easily.

提交回复
热议问题