Last Updated: February 25, 2016
·
1.132K
· barnettjw

Draw Structure of Directory Hierarchy

Linux oneliner that draw's the structure of a directory Hierarchy using the magic of sed and dash of grep

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

And then you get this:

/home/dem/apps/firefox
   |-chrome
   |---icons
   |-----default
   |-components
   |-defaults
   |---autoconfig
   |---pref
   |---profile
   |-----chrome
   |-extensions
   |---{972ce4c6-7e08-474-a285-320298ce6fd}   
   |---inspector~mozilla.org
   |-----chrome
   |-----components
   |-----defaults
   |-------preferences
   |---talkback~mozilla.org
   |-----components
   |-------talkback
   |-greprefs
   |-icons
   |-plugins
   |-res
   |---dtd
   |---entityTables
   |---fonts
   |---html
   |-searchplugins
   |-updates
   |---0

source: http://www.centerkey.com/tree/

2 Responses
Add your response

Isn't there a built-in analog of DOS-like tree? I always thought that's weird, sounds like a common task...

over 1 year ago ·

There is a command tree however it's not part of a standard package, so you probably have to install it on most systems.

over 1 year ago ·