简体   繁体   中英

How can I go about printing a directory tree in a bash script?

I want the output to be something like

|-------File1 

|-------File2

|-------Folder

       |-------somefile

       |-------Makefile

       |-------Directory

                |-------hi.txt
|-------hello.c

I am writing a bash script to obtain this kind of output. I'm having trouble on how to go about this. I want to do this without using the tree command.

Don't reinvent the wheel, this is exactly what tree command does.

Check man tree to get details.


All popular distros should have tree (installed or) available in their repositories; so if not installed already you can install it using usual manner.

For example, in Debian (and derivatives):

sudo apt-get install tree

In RPM based distros:

sudo yum install tree

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM