Search code examples
unicodemarkdowndirectory-structure

Print Directory & File Structure with icons for representation in Markdown


I want a Linux command to print directory & file structures in the form of a tree, possibly with Unicode icons before each file, and some hint for the best syntax to include the output in a Markdown document, without spaces between lines.

Example:

.
├── _config.yml
├── _drafts
│   ├── begin-with-the-crazy-ideas. Textile
│   └── on-simplicity-in-technology. Markdown
├── _includes
│   ├── footer.html
│   └── header.html
├── _layouts
│   ├── default.html
│   └── post.html
├── _posts
│   ├── 2007-10-29-why-every-programmer-should-play-nethack.textile
│   └── 2009-04-26-barcamp-boston-4-roundup.textile
├── _data
│   └── members.yml
├── _site
└── index.html

Solution

  • If you are concerned about Unicode characters you can use ASCII to build the structures, so your example structure becomes

    .
    +-- _config.yml
    +-- _drafts
    |   +-- begin-with-the-crazy-ideas.textile
    |   +-- on-simplicity-in-technology.markdown
    +-- _includes
    |   +-- footer.html
    |   +-- header.html
    +-- _layouts
    |   +-- default.html
    |   +-- post.html
    +-- _posts
    |   +-- 2007-10-29-why-every-programmer-should-play-nethack.textile
    |   +-- 2009-04-26-barcamp-boston-4-roundup.textile
    +-- _data
    |   +-- members.yml
    +-- _site
    +-- index.html
    

    Which is similar to the format tree uses if you select ANSI output.