Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Display a tree-like structural view of any directory' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Display a tree-like structural view of any directory
Authored by: acet on Feb 15, '06 11:20:35AM
Mind you, this code falls apart pretty quickly in the face of directories or files that have colons (':') in their name. Case in point, run it on ~/Library and watch the fireworks as it trips over Mail and cache subfolders ;)

There's a simple fix, use find instead:


find . -type d | sed -e 1d -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|-/'

The additional '-e 1d' sed command gets rid of find always printing '.' and I also tweaked the last sed command for output consistancy.

Oh, not only is this more robust, it's way faster.

Nice tip, I've added it to my toolbelt.

[ Reply to This | # ]

Display a tree-like structural view of any directory
Authored by: kenji on Jul 14, '08 11:02:49AM

Thanks for this version! I removed the "-type d" flag and added "> ~/Desktop/mytree.txt" to get a text file of not only the directory tree, but also the directory's contents. Just what I needed!



[ Reply to This | # ]