Skip to content

Instantly share code, notes, and snippets.

@pravj
Last active September 8, 2021 09:43
Show Gist options
  • Save pravj/d39fb4149638c183b922 to your computer and use it in GitHub Desktop.
Save pravj/d39fb4149638c183b922 to your computer and use it in GitHub Desktop.
bash script to generate tree structure of a directory
#!/usr/bin/env bash
# bash script to generate tree structure of a directory
# Pravendra Singh (@hackpravj)
pwd=$(pwd)
find $pwd -print | sed -e "s;$pwd;\.;g;s;[^/]*\/;|__;g;s;__|; |;g"

I have a copy of treegen.sh file in /usr/bin with name treegen in executable mode

inside any Directory on running command treegen it result tree structure of that Directory

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.

🍻

@dhruvghulati-zz
Copy link

I downloaded the .sh file to that folder, then run your command, and get the attached.
screen shot 2016-03-17 at 14 22 07

@pravj
Copy link
Author

pravj commented Apr 4, 2016

Hi @dhruvghulati,

Sorry for replying late to this, it didn't notify me of your comment. I'm sure you have resolved the issue.

It was because you were not root, running the commands with sudo works for me.

Thanks for checking it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment