Skip to content

Instantly share code, notes, and snippets.

@harshavardhana
Created June 5, 2013 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshavardhana/5713145 to your computer and use it in GitHub Desktop.
Save harshavardhana/5713145 to your computer and use it in GitHub Desktop.
Print directory tree structure
#!/bin/sh
# 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 [ $# -eq 1 ]; then
ls -R $1 | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
elif [ $# -gt 1 ]; then
echo "Only one directory at a time please!!"
exit 255
else
echo "Please provide a directory to display tree structure"
echo "Usage: ./tree.sh <dir>"
exit 1
fi
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment