Linux Command to Print Directory Structure in the Form of a Tree

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):

Sample Image

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



Leave a reply



Submit