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

后端 未结 9 1021
野趣味
野趣味 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:50

    You can use this one:

    ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
    

    It will show a graphical representation of the current sub-directories without files in a few seconds, e.g. in /var/cache/:

       .
       |-apache2
       |---mod_cache_disk
       |-apparmor
       |-apt
       |---archives
       |-----partial
       |-apt-xapian-index
       |---index.1
       |-dbconfig-common
       |---backups
       |-debconf
    

    Source

提交回复
热议问题