This site is now 100% read-only, and retired.

Commands you might have missed: tree

Posted by Steve on Thu 17 Jul 2008 at 06:42

tree is a very simple utility which will draw a tree of a directory structure. It isn't a command which is generally useful, but it can be very handy to know about if you're writing articles!

The tree command is contained in the tree package. If you don't have it installed you may get it via one of the following two commands:

root@sethra:~#  apt-get update && apt-get install tree
root@sethra:~#  aptitude update && aptitude install tree

Once installed it is invoked by running tree [/path/to/draw. For example I could run:

skx@sethra:~$  tree /boot/
/boot
|-- System.map-2.6.18-6-amd64
|-- System.map-2.6.18-6-xen-amd64
|-- config-2.6.18-6-amd64
|-- config-2.6.18-6-xen-amd64
|-- debian.bmp -> /boot/sarge.bmp
|-- grub
|   |-- default
|   |-- device.map
|   |-- e2fs_stage1_5
|   |-- fat_stage1_5
|   |-- jfs_stage1_5
|   |-- menu.lst
|   |-- menu.lst~
|   |-- minix_stage1_5
|   |-- reiserfs_stage1_5
|   |-- stage1
|   |-- stage2
|   |-- stage2_eltorito
|   `-- xfs_stage1_5
|-- initrd.img-2.6.18-6-amd64
|-- initrd.img-2.6.18-6-xen-amd64
|-- initrd.img-2.6.18-6-xen-amd64.bak
|-- lost+found [error opening dir]
|-- vmlinuz-2.6.18-6-amd64
|-- vmlinuz-2.6.18-6-xen-amd64
`-- xen-3.0.3-1-amd64.gz

2 directories, 24 files

The output is customisable via command line flags. For example it is possible to tell the utility to avoid displaying files, (such that only directories are shown), via:

skx@sethra:~$  tree -d /boot/
/boot/
|-- grub
`-- lost+found [error opening dir]

2 directories

Similarly "tree -C" causes tree to display files in colour, in a similar manner to that which you might be used to being produced via ls. (When "ls --color=auto" is in use.)

For a full list of options please read the manpage via "man tree" - whilst this utility isn't going to be the most popular command we've ever covered there are times when it is very useful to have to hand!

 

 


Re: Commands you might have missed: tree
Posted by Nilshar (195.200.xx.xx) on Thu 17 Jul 2008 at 08:27
[ View Weblogs ]
it have little use indeed, but can be really usefull at time :)

Not as usefull as pstree for sure !

[ Parent ]

Re: Commands you might have missed: tree
Posted by Steve (217.28.xx.xx) on Thu 17 Jul 2008 at 10:15
[ View Weblogs ]

See if you can guess which command will be covered tomorrow!

Steve

[ Parent ]

Re: Commands you might have missed: tree
Posted by Anonymous (85.25.xx.xx) on Thu 17 Jul 2008 at 11:07
pstree ;)

[ Parent ]

Re: Commands you might have missed: tree
Posted by ajt (204.193.xx.xx) on Thu 17 Jul 2008 at 10:30
[ View Weblogs ]

Tree along with sudo and less are usually the first three commands I install on a box after installation. When I showed tree to my partner she wondered why it wasn't standard and no one* had mentioned it before.

On the Red Hat Enterprise systems at work tree is no longer available, it's one of the more annoying features of Red Hat, where they have removed long standing simple console applications in favour of fancy GUI alternatives. Therefore I usually keep the source files at hand should I need to compile and install it.

* Well, why I hadn't told her...

--
"It's Not Magic, It's Work"
Adam

[ Parent ]

Re: Commands you might have missed: tree
Posted by Steve (82.41.xx.xx) on Thu 17 Jul 2008 at 21:27
[ View Weblogs ]

When I showed tree to my partner she wondered why it wasn't standard and no one* had mentioned it before.

That's pretty much why I've run this "mini-series". I came across a couple of people in short succession who'd never seen, used, or heard of "tree" specifically.

Steve

[ Parent ]

Re: Commands you might have missed: tree
Posted by Anonymous (71.53.xx.xx) on Mon 21 Jul 2008 at 03:23
I find tree to be useful... sometimes. ls -R can be a bit hard to follow.

[ Parent ]