Monday, January 11, 2010

How to install the “tree” command on Mac OS X

Many of you have seen the tree command being used on a few Ruby on Rails and Git screencasts such as the ones on Gitcasts. 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 shows you how.

Tree provides a very useful way via command line to quickly display a graphical overview of a directory’s contents.

Installation instructions

To install, download the source code and extract the tarball like so:

curl -O ftp://mama.indstate.edu/linux/tree/tree-1.5.3.tgz
tar xzvf tree-1.5.3.tgz
cd tree-1.5.3/
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:

  1. Comment out the following lines so they look like this:
    # Linux defaults:
    #CFLAGS=-ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
    #CFLAGS=-O2 -Wall -fomit-frame-pointer -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
    #LDFLAGS=-s
  2. Uncomment these lines, like so:
    # Uncomment for OS X:
    CC=cc
    CFLAGS=-O2 -Wall -fomit-frame-pointer -no-cpp-precomp
    LDFLAGS=
    XOBJS=strverscmp.o

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

make
sudo make install

Finally, you should be able to try it out:

# Display a tree for the current working directory
tree

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

Tada!

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.

Notes

  1. admix-dev reblogged this from shaunchapman
  2. dennis-jung reblogged this from shaunchapman and added:
    MAC에서 TREE 명령어 설치하기! ^^ 너무 좋군 ㅋ
  3. dragochapel reblogged this from shaunchapman
  4. timeimp reblogged this from shaunchapman
  5. evandrix reblogged this from shaunchapman
  6. shaunchapman posted this