Created
June 5, 2013 11:08
-
-
Save harshavardhana/5713145 to your computer and use it in GitHub Desktop.
Print directory tree structure
This file contains hidden or 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 | |
# 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