How do I print a tree with files in Bash for Windows?

1

I've found this command to show a tree of the directories under the current one:

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

Which produces:

 .                          
 |-docs                     
 |-lib                      
 |-node_modules             
 |---connect-file-cache     
 |-----docs                 
 |-----lib                  
 |-----node_modules         
 |-------mime               
 |-------underscore         
 |-----src                  
 |-----test                 
 |-----test_fixtures        
 |---mime                   
 |---snockets               

That's good, but the files aren't there. My bash scripting skills are weak, so I have no idea how to get the files to show in that output.

Since I'm on Windows, I don't think I can get the tree command into mingw32.

jcollum

Posted 2013-01-10T18:47:49.847

Reputation: 3 737

Does that work for you? (Second answer with the shell script) Mac OS X equivalent of the Ubuntu “tree” command

– slhck – 2013-01-10T18:52:58.383

3What is wrong with the tree command in the cmd propmpt on your windows box? – EBGreen – 2013-01-10T18:54:28.117

@EBGreen If the OP wants the files to show, he should use (Command Prompt) tree /f – BenjiWiebe – 2013-01-10T18:56:19.923

@BenjiWiebe that is why I asked what is wrong with the windows tree command. – EBGreen – 2013-01-10T18:57:48.733

@EBGreen I meant that if the OP did not like tree, he should use tree /f to display the files, not just the directories. – BenjiWiebe – 2013-01-10T18:59:05.710

"I don't think I can get the tree command into mingw32" Yes you can, just put alias tree=tree.com in your ~/.bashrc – BenjiWiebe – 2013-01-10T19:01:51.233

@BenjiWiebe that is effectively the same as what I have already -- no files. – jcollum – 2013-01-10T22:39:18.750

@jcollum OK, try this in your .bashrc: alias tree='tree.com /f' – BenjiWiebe – 2013-01-10T22:41:28.110

@EBGreen from OP: "That's good, but the files aren't there" -- which also applies to the tree command from cmd. I can add a /f to the command, but then bash thinks I'm trying to tree the /f drive. – jcollum – 2013-01-10T22:44:22.397

@BenjiWiebe nope, bash thinks the /f is a drive letter. – jcollum – 2013-01-10T22:47:54.260

@jcollum Interesting. I never noticed that. – BenjiWiebe – 2013-01-11T00:22:00.323

Answers

2

https://superuser.com/a/359728/5200

added this function to .bash_profile:

function ftree {
    SEDMAGIC='s;[^/]*/;|____;g;s;____|; |;g'

    if [ "$#" -gt 0 ] ; then
       dirlist="$@"
    else
       dirlist="."
    fi

    for x in $dirlist; do
         find "$x" -print | sed -e "$SEDMAGIC"
    done

}

It's not pretty, but it does the job. Credit to https://superuser.com/users/105575/ahmed-masud

jcollum

Posted 2013-01-10T18:47:49.847

Reputation: 3 737

Any idea how to color code the directories to a different color? Or reuse your directory listing colors? – Jen S. – 2014-09-23T05:45:59.923

Sorry, no. Sounds like a good question on its own though. – jcollum – 2014-09-23T15:55:45.247

0

A tool that will help you with this is Print Maestro. This handy solution will quickly print folder tree after preview.

When you click on some folder in the left-side folder list, you will see all its subfolders listed in the upper right side list. Below it you will find the report mock that will be printed. To the right from the mock there is a list of report types, where you need to check off 'Tree' in Standard tab.

Print Folder Tree

Tyler Hastings

Posted 2013-01-10T18:47:49.847

Reputation: 1