So sorry but this is a geeky entry!

I had an experience today which wasn’t good. I had a runaway process and I SO did not want a restart (I’m an uptime whore) so I needed to see which process was the issue. pstree had been recommended to be, but I didn’t have that on my Mac and finding current source was a pain in the bum. I’d seen ‘tree’ before as an alternative and the tree package is available on most package managers such as MacPorts and Fink for Mac OS X, however it’s nice to roll your own. This tutorial tries to show you how.

Tree provides a very useful way via command line to quickly display a graphical overview of a directory’s contents. To install, download the source code and extract the tarball like so:

curl -O
tar xzvf tree-1.6.0.tgz
cd tree-1.6.0/
ls -al

Now you have to change Makefile to match your environment. If you’re using Linux, you can probably skip this step. If not, simply uncomment the lines for your operating system and comment out all the others. For example, if you’re using Mac OS X, do the following:

Comment out the following lines so they look like this:

# Linux defaults:
#CFLAGS=-O2 -Wall -fomit-frame-pointer -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64

Uncomment these lines, like so:

# Uncomment for OS X:
CFLAGS=-O2 -Wall -fomit-frame-pointer -no-cpp-precomp

Now you can make and install (if you get any errors on the following commands, you probably didn’t edit Makefile correctly):

sudo make install

Finally, you should be able to try it out:

# Display a tree for the current working directory

# …or append whatever directory you want
tree /whatever/directory/you/want/

That’s it! Now you can get a quick overview of what a directory contains in an easy to understand format. Let me know if you have any problems or questions.

Techie rant over ……..

admin posted at 2011-8-25 Category: Computing