Indented Hierarchical Listing with Tree Command on Ubuntu 14.04

You can install Tree using apt-get or yum depending on your distribution. On Ubuntu 14.04 we'll be using apt-get.

sudo apt-get update && apt-get install tree

On RHEL/CentOS

yum update -y && yum install tree -y

Once installed, use the command 'tree' followed by the directory path to view an indented hierarchical listing of your files. Piping the command into less will let you take a good look around.

root@nothing:~# tree /var/ | less
/var/
├── backups
│   ├── apt.extended_states.0
│   ├── apt.extended_states.1.gz
│   ├── apt.extended_states.2.gz
│   ├── apt.extended_states.3.gz
│   ├── dpkg.status.0
│   ├── dpkg.status.1.gz
│   ├── dpkg.status.2.gz
│   ├── dpkg.status.3.gz
│   ├── group.bak
│   ├── gshadow.bak
│   ├── passwd.bak
│   └── shadow.bak
├── cache
│   ├── apache2
│   │   └── mod_cache_disk
│   ├── apparmor
...

Or, if you'd like to impress your friends, you could use the following for a similar output:

ls -R /path/to/dir | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 1864