Adding Tree command to the Terminal (Mac OSX)

Yesterday I saw a tutorial where a person was using the Terminal and navigated (using ‘cd’) to get into a folder. He then typed ‘tree’ and a visual representation of the file/folder structure appeared. It was pretty neat. Of course I ran home to open my Terminal and I typed ‘tree’ and received.

Terminal screen shot showing 'tree' is not a recognized command
Terminal screen shot showing ‘tree’ is not a recognized command

Did you know? One of the coolest things about the Windows Command Line (usually it’s someone bragging about the Terminal) is the ‘tree’ command. It’s native to the system. Point to the folder you want and type ‘tree’ and you’ll get the folder/file structure of that folder (options found here).

So I looked on line and I found this great article that showed me how to add it. Just open the Terminal and add this code:

[prettify]
find . -print | sed -e ‘s;[^/]*/;|____;g;s;____|; |;g’
[/prettify]

If you want to print that tree structure to a file called textfile.txt change your code to:

[prettify]
find . -print | sed -e ‘s;[^/]*/;|____;g;s;____|; |;g’ > textfile.txt
[/prettify]

If you know how to edit your .~/profile, open your .~/profile and add this:

[prettify]
function tree {
find ${1:-.} -print | sed -e ’s;[^/]*/;|____;g;s;____|; |;g’
}
[/prettify]

Then you can just type ‘tree’ and the folder path and you’ll get the tree visual print out every time.