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

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

    You can also use the combination of find and awk commands to print the directory tree. For details, please refer to "How to print a multilevel tree directory structure using the linux find and awk combined commands"

    find . -type d | awk -F'/' '{ 
    depth=3;
    offset=2;
    str="|  ";
    path="";
    if(NF >= 2 && NF < depth + offset) {
        while(offset < NF) {
            path = path "|  ";
            offset ++;
        }
        print path "|-- "$NF;
    }}'
    

提交回复
热议问题