Linux command to print directory structure in the form of a tree
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.
Unix command to print directory structure in the form of a tree?
I think you are looking for the "tree" command. If you are having issues running it you might have to find out how to install it on your specific distribution. For ubuntu installs you can find instructions here:
https://askubuntu.com/questions/507588/not-able-to-install-tree-comand-in-ubuntu
Not sure what you mean by "on Unix". What OS are you running, specifically? Tree should be compatible on Unix systems. You may just have to compile it for your particular OS.
This command prints output like the following (on cygwin):
List all directories recursively in a tree format
Try doing this (not exactly the same output, but very close) :
find ./ -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
From http://mlsamuelson.com/content/tree-approximation-using-find-and-sed
with awk
find . -type d -print 2>/dev/null|awk '!/\.$/ {for (i=1;i<NF;i++){d=length($i);if ( d < 5 && i != 1 )d=5;printf("%"d"s","|")}print "---"$NF}' FS='/'
See http://www.unix.com/shell-programming-scripting/50806-directory-tree.html
How does Linux use Tree command group sorting
From tree --help
:
--dirsfirst List directories before files (-U disables).
CentOS directory structure as tree?
As you can see here. tree is not installed by default in CentOs, so you'll need to look for an RPM and install it manually
Creating a full directory tree at once
Change shebang to
#!/bin/bash
to run the script with bash as it supports brace expansion.
The problem is that you are using shell that does not support it. Your /bin/sh
does not point to /bin/bash
but to something like /bin/dash
.
https://wiki.ubuntu.com/DashAsBinSh#A.7B
Related Topics
Separately Redirecting and Recombining Stderr/Stdout Without Losing Ordering
How to Kill All Processes With a Given Partial Name
Shell Script: Run Function from Script Over Ssh
Syntax Error in Shell Script With Process Substitution
When Should We Use Mutex and When Should We Use Semaphore
Get Most Recent File in a Directory on Linux
How to Setup Public-Key Authentication
Setting Environment Variables in Linux Using Bash
Why Do You Need to Put #!/Bin/Bash At the Beginning of a Script File
Bash Script Processing Limited Number of Commands in Parallel
Automatically Capture Output of Last Command into a Variable Using Bash
How to Get Cmake to Find My Alternative Boost Installation
Bluetooth Low Energy: Listening For Notifications/Indications in Linux
How to Escape Single Quotes in Bash/Grep
Quickly Create a Large File on a Linux System
Does Linux Guarantee the Contents of a File Is Flushed to Disc After Close()
How to Find Out What All Symbols Are Exported from a Shared Object
Use Expect in a Bash Script to Provide a Password to an Ssh Command