#!/bin/sh ####################################################### # tree - Displays Structure of Directory Hierarchy # J. David Schronce - Wed Feb 6 23:46:26 CST 2008 ####################################################### # This tiny script uses "ls", "grep", and "sed" # in a single command to show the nesting of # sub-directories. # # Usage: # % tree [directory] # # Examples: # % tree # % tree /etc/opt # % tree .. # ####################################################### echo # If parameter exists, use as base folder if [ "$1" != "" ] then cd "$1" fi pwd # 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 ls -R 2>/dev/null \ | grep ":$" \ | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' # check if no folders if [ `ls -F -1 | grep "/" | wc -l` = 0 ] then echo " -> no sub-directories" fi echo exit