Monday, 12 March 2012

Directory tree in Bash

I was recently searching for a bash script that could be used to create the skeleton of a yaml file containing directory structure. The best material I found is here: http://systembash.com/content/one-line-linux-command-to-print-out-directory-tree-listing/

With the modification of this line:
find ./ -type d | sed -e 's/[^-][^\/]*\//--/g;s/--/ |-/'
I managed to produce the best skeleton:
find ./ | sed -e 's/[^\/]*\// /g'
Since I still have to shape this file up with more data I am not bothering with finding a method to put the ':' at the end of each directory as I can do it myself with little effort. I use Vim's visual mode to get rid of the extra leading spaces at each line.