bash script to generate tree structure of a directory
treegen
#!/usr/bin/env bash
# bash script to generate tree structure of a directory
# Pravendra Singh : https://pravj.github.io
pwd=$(pwd)
find $pwd -print | sed -e "s;$pwd;\.;g;s;[^/]*\/;|__;g;s;__|; |;g"
How to use
Download
# basically adding this file to your $PATH in executable mode
cd /usr/bin
wget http://git.io/vEYZ9A && cp vEYZ9A treegen && chmod 755 treegen
Start using it
run treegen
command in any directory and it will generate tree structure of directory.
See it on gist.github.com
Written by Pravendra Singh
Related protips
2 Responses
This is a really cool tool, but I think this exists already in the forms below. Does your alternative offer any alternate advantage to the traditional tree command?
Ubuntu : sudo apt-get update && sudo apt-get install tree
Mac OS X : brew install tree
OR
sudo port install tree
OR
fink install tree
@pddevins yeah I know about 'tree' but here is why I tried this :
I was working on something and needed to add tree structure of a directory in a .markdown file, but 'tree' was not installed on my system and internet was not working. -- all bad situations :D
that's why I tried this short script.