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!
Not as usefull as pstree for sure !
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
See if you can guess which command will be covered tomorrow!
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
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 | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | 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.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]