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 folder2 folder3
You need to use command called tree. It will list contents of directories in a tree-like format. It is a recursive directory listing program that produces a depth indented listing of files. When directory arguments are given, tree lists all the files and/or directories found in the given directories each in turn.
In the Windows command prompt you can use "tree /F" to view a tree of the current folder and all descending files & folders. In File Explorer under Windows 8.1: Select folder.
Is this what you're looking for tree? It should be in most distributions (maybe as an optional install).
~> tree -d /proc/self/ /proc/self/ |-- attr |-- cwd -> /proc |-- fd | `-- 3 -> /proc/15589/fd |-- fdinfo |-- net | |-- dev_snmp6 | |-- netfilter | |-- rpc | | |-- auth.rpcsec.context | | |-- auth.rpcsec.init | | |-- auth.unix.gid | | |-- auth.unix.ip | | |-- nfs4.idtoname | | |-- nfs4.nametoid | | |-- nfsd.export | | `-- nfsd.fh | `-- stat |-- root -> / `-- task `-- 15589 |-- attr |-- cwd -> /proc |-- fd | `-- 3 -> /proc/15589/task/15589/fd |-- fdinfo `-- root -> / 27 directories
sample taken from maintainer's web page.
You can add the option -L #
where #
is replaced by a number, to specify the max recursion depth.
Remove -d
to display also files.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With