all. I'm looking for a quick and dirty way to generate some diagrams of some directories that have almost, but not exactly, the same hierarchy, so I can show them around at a meeting and we can decide which flavor we like best. I'm not interested in the "leaf" nodes, just the directories.

The catch: I don't want to mess with X. This is a server system I deal with entirely through SSH. So I'm looking for something that will do ASCII layout, maybe with simple pipes-and-hyphens for lines or something.

Does anyone know of such a utility? I'm sure I could write something myself, but it's such a fiddly little sort of project, with handling spacing and layout and such; I'd really like to discover that someone's done it for me. Alas, Google doesn't seem to know of such a thing...or if it does, it's hidden beneath heaps of excellent visual explications of the standard general Unix file hierarchy. Thanks!


I would use tree.

$ tree -d /usr|head -n 12
|-- X11R6
|   `-- lib
|       `-- X11
|           `-- wily
|-- bin
|   `-- X11 -> .
|-- games
|-- i586-mingw32msvc
|   |-- bin
|   |-- include
|   |   |-- GL
  • Perfect! Exactly what I was looking for. It's amazing how hard it is (at least for me) to find the simple little stuff in Unix sometimes. man -k directory didn't do it -- but man -k directories would have. Thanks again! – Jenn D. May 22 '10 at 18:18
  • @Jenn: That's why I use a common root portion of a word for that kind of query apropos director (or man -k director) will find both. It works to include various prefixes as well: apropos known finds "known", "unknown" and "well-known". – Dennis Williamson May 22 '10 at 18:43
  • And tree also works on Windows. – Mark Tomlin Jun 4 '12 at 17:48
  • Using tree (version 1.5.3) I get some unicode characters to make the diagram look prettier. To get only ascii characters, I had to use tree --charset ascii – jcollado Aug 20 '12 at 12:30
  • Not directly related, but there's also pstree. Tree is one of those programs like top; there are a number of fun variants. – Parthian Shot Aug 5 '14 at 20:18

If you don't have tree you could use this linux/unix command:

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

You can also make a shell script see details here.

Explanation for the above command:

ls -R list all directories, sub-directories,

Explanation ls -R list all the file and directories recursively


addr_assign_type  device            iflink            speed


grep ":$" filters only the files that have : before line end, thus remains, something like.


Then a series of multiple command are passed using -e switch to sed

's/:$//' strips all the trailin :

's/[^-][^\/]*\//--/g' leaves only what is between / - and replace each with --

the rest two command add a few spaces and a |

The result is something like:

  • +1 for effort, -1 because you didn't explain the regex. I can be swayed to upvote if an explanation is forthcoming... (I know regexes, and you know regexes, but a lot of people find them frightening) – Parthian Shot Aug 5 '14 at 20:20
  • 1
    @ParthianShot I tried and I added explanation – Eduard Florinescu Aug 5 '14 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.