Created
July 10, 2013 19:34
-
-
Save djq/5969469 to your computer and use it in GitHub Desktop.
Tree command for OSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
####################################################### | |
# UNIX TREE # | |
# Version: 2.3 # | |
# File: ~/apps/tree/tree.sh # | |
# # | |
# Displays Structure of Directory Hierarchy # | |
# ------------------------------------------------- # | |
# This tiny script uses "ls", "grep", and "sed" # | |
# in a single command to show the nesting of # | |
# sub-directories. The setup command for PATH # | |
# works with the Bash shell (the Mac OS X default). # | |
# # | |
# Setup: # | |
# $ cd ~/apps/tree # | |
# $ chmod u+x tree.sh # | |
# $ vim ~/.bash_profile # | |
# # add this line: # | |
# alias tree="/Applications/tree/tree.sh" # | |
# $ source ~/.bash_profile # | |
# # | |
# Usage: # | |
# $ tree [directory] # | |
# # | |
# Examples: # | |
# $ tree # | |
# $ tree /etc/opt # | |
# $ tree .. # | |
# # | |
# Public Domain Software -- Free to Use as You Like # | |
# http://www.centerkey.com/tree - By Dem Pilafian # | |
####################################################### | |
echo | |
if [ "$1" != "" ] #if parameter exists, use as base folder | |
then cd "$1" | |
fi | |
pwd | |
ls -R | grep ":$" | \ | |
sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' | |
# 1st sed: remove colons | |
# 2nd sed: replace higher level folder names with dashes | |
# 3rd sed: indent graph three spaces | |
# 4th sed: replace first dash with a vertical bar | |
if [ `ls -F -1 | grep "/" | wc -l` = 0 ] # check if no folders | |
then echo " -> no sub-directories" | |
fi | |
echo | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found here: http://www.centerkey.com/tree/ with minor edits for OSX 10.8.4