100

I'm using git-bash in Windows 7. I'd like to see a tree of the current directory. However

jcollum@DEVELOPER01 ~/Dev/express_coffee            
$ tree .                                            
sh.exe": tree: command not found

OK, so I don't have the tree command. How to install it? I found an article but it was for macOS.

3

11 Answers 11

77

You could also use "cmd //c tree" to use Windows' tree

Explanation:

  • Launch cmd with '/c' argument and run tree, then terminate

/C Carries out the command specified by string and then terminates

(extra slash for escaping)

/a use to run with ascii chars in case it doesn't display right.

Answered in greater detail here: https://stackoverflow.com/q/515309/1261166

5
  • 12
    you can also add this command as an alias to your ~/.bashrc: alias tree='cmd //c tree //a
    – onlyhuman
    Mar 12, 2019 at 10:17
  • This no longer works. Use tree.com /a Aug 13, 2019 at 17:15
  • 1
    @automorphic I think it has to be tree.com //a as stated below. With a single forward slash the command does not seem to work.
    – mgross
    Nov 13, 2020 at 11:14
  • 2
    cmd //c tree //a //f to also display the names of the files in each directory.
    – Smajjk
    Apr 19, 2021 at 8:10
  • You can try a variant of this command ``cmd //c "tree /f"
    – Vy Do
    Dec 26, 2022 at 12:53
61

I have downloaded the tree.exe inside the zip file from here http://gnuwin32.sourceforge.net/packages/tree.htm as suggested.

Then I have extracted the tree.exe file to C:\Program Files\Git\usr\bin (I have added this folder to windows path to make it work with the regular CMD but it works with GITBash too). Git Bash with tree command on windows

I hope this helps you somehow !

3
  • 3
    Works very well with git-bash on Windows 7, thanks!
    – cjauvin
    Dec 12, 2016 at 21:18
  • 6
    tree.exe copied to C:\Program Files\Git\usr\bin is what we were looking for. Great share . Thanks. downloads.sourceforge.net/gnuwin32/tree-1.5.2.2-bin.zip Download the zip specified for binaries it has tree.exe. Contrary try to download from the original site.
    – Doogle
    Dec 29, 2017 at 17:03
  • 6
    In windows 10 I put this in C:\Users\myuser\AppData\Local\Programs\Git\usr\bin I think the rule of thumb is to find where bash.exe or git.exe are located, go up a folder, then find usr/bin/ and put tree there
    – Charles L.
    Sep 7, 2018 at 19:32
29

There is a tree command in windows already — only problem is it is tree.com and git bash will not automatically add extension .com and execute it.

However it will find it if you press tab after you type tree or tre

To see files you have to use //f — you have to use // or bash will think it is folder name

I also used //a to show ascii lines but you don't have to use it

Example:

dean@dean:~/java$ tree
bash: tree: command not found

dean@dean:~/java$ tree.com //a
Folder PATH listing for volume c
Volume serial number is 4E70-B37A
C:.
+---atom
+---sublime
\---vscode

dean@dean:~/java$ tree.com //a //f
Folder PATH listing for volume c
Volume serial number is 4E70-B37A
C:.
+---atom
|       test1
|
+---sublime
|       test2
|
\---vscode
        test3

dean@dean:~/java$
1
9

The GnuWin32 build of tree is at http://gnuwin32.sourceforge.net/packages/tree.htm - you'd need to add it to your path manually if you're not already using GnuWin32.

If you want to use it at a Windows console also you'd need to rename or copy tree.exe to something else, e.g. lstree.exe, otherwise the Windows tree command will take precedence. The advantage of the GnuWin version is that it has lots of options - e.g. tree -L 2 would limit the recursion depth to 2.

> tree --help
usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]]
        [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]
        [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]
        [--filelimit #] [<directory list>]
  -a            All files are listed.
  -d            List directories only.
  -l            Follow symbolic links like directories.
  -f            Print the full path prefix for each file.
  -i            Don't print indentation lines.
  -q            Print non-printable characters as '?'.
  -N            Print non-printable characters as is.
  -p            Print the protections for each file.
  -u            Displays file owner or UID number.
  -g            Displays file group owner or GID number.
  -s            Print the size in bytes of each file.
  -h            Print the size in a more human readable way.
  -D            Print the date of last modification.
  -F            Appends '/', '=', '*', or '|' as per ls -F.
  -v            Sort files alphanumerically by version.
  -r            Sort files in reverse alphanumeric order.
  -t            Sort files by last modification time.
  -x            Stay on current filesystem only.
  -L level      Descend only level directories deep.
  -A            Print ANSI lines graphic indentation lines.
  -S            Print with ASCII graphics indentation lines.
  -n            Turn colorization off always (-C overrides).
  -C            Turn colorization on always.
  -P pattern    List only those files that match the pattern given.
  -I pattern    Do not list files that match the given pattern.
  -H baseHREF   Prints out HTML format with baseHREF as top directory.
  -T string     Replace the default HTML title and H1 header with string.
  -R            Rerun tree when max dir level reached.
  -o file       Output to file instead of stdout.
  --inodes      Print inode number of each file.
  --device      Print device ID number to which each file belongs.
  --noreport    Turn off file/directory count at end of tree listing.
  --nolinks     Turn off hyperlinks in HTML output.
  --dirsfirst   List directories before files.
  --charset X   Use charset X for HTML and indentation line output.
  --filelimit # Do not descend dirs with more than # files in them.

Compared to the Windows tree:

> tree /?
Graphically displays the folder structure of a drive or path.

TREE [drive:][path] [/F] [/A]

   /F   Display the names of the files in each folder.
   /A   Use ASCII instead of extended characters.
2
  • IMO, this is the most straight forward way to get tree cmd in Cygwin and I tried the compilation route before unsuccessfully. With this you just download the binary, extract it to a folder on your cygwins path and violla, tree command out of the box
    – niken
    Apr 11, 2016 at 18:53
  • 1
    in cygwin: apt-cyg install tree and tree.exewill be in the cygwin bin folder.
    – Timo
    Oct 26, 2017 at 10:03
3

Git for Windows (https://gitforwindows.org/) (has Git Bash) but it does not include tree. tree is available for via pacman (Package Manager) but that is only available if you install "Git for Windows SDK" (scroll to the bottom of gitforwindows.org/ which provides a link to download installer for it from https://github.com/git-for-windows/build-extra/releases/latest)

This SO: "Package management in git for windows?" was very helpful https://stackoverflow.com/questions/32712133/package-management-in-git-for-windows

Also as commented in the above SO, they link to this git for windows issue [Pacman missing on fresh 2.5.2 install #397] that it was intended to not include pacman in the default install.

Anyways, I installed "Git for Windows SDK", then in it's bash prompt (SDK-64) I ran the following to install current tree v1.7.0-1 (as of this posting Aug 30, 2018):

[SDK-64: Bash Terminal for Git for Windows SDK]
pacman -S tree
...
Proceed with installation? [Y/n] Y

On my system, Git for Windows SDK is installed under: C:\git-sdk-64, so from my Git for Windows Bash shell (that did not have tree installed), I copied it over tree.exe to it's /usr/bin directory, e.g.

[MINGW64: Bash Terminal for Git for Windows]
cd /usr/bin
cp /c/git-sdk-64/usr/bin/tree.exe .

Now I can run tree v1.7.0 from both Git Bash shells.

So, to make it even easier for others and maybe myself on a future machine, I looked at where pacman was getting the tree package from by running following in my Git for Windows SDK Bash terminal:

$ pacman -S --info tree
Repository      : msys
Name            : tree
Version         : 1.7.0-1
Description     : A directory listing program displaying a depth indented list of files
Architecture    : x86_64
...

The key thing, here is that pacman is getting it from the "msys" repository (FYI: even though it says msys, it really is using msys2), so I looked at /etc/pacman.d/mirrorlist.msys and the first mirror points to http://repo.msys2.org/msys/$arch/

So next time you want a package that is NOT in Git for Windows, you can download them from: http://repo.msys2.org/msys/x86_64/ (for 64-bit) or from http://repo.msys2.org/msys/i686/ (32-bit)

e.g. direct download link for tree v1.7.0-1

1
2

git-bash is really just a cut down version of mingw. Install Cygwin from cygwin.com, and then either use the package manager to install 'tree' or whatever package it's in, or if it doesn't exist, then install gcc, download the tree source from here:

http://mama.indstate.edu/users/ice/tree/

Then follow the instructions in the INSTALL file (make, make install)

2
  • So is it impossible in minggw?
    – Jen S.
    Jan 21, 2014 at 9:27
  • 1
    I'd imagine it isn't too hard from mingw, but isn't possible from your default git-bash prompt, because I imagine that git-bash doesn't come with tools you need like a C/C++ compiler. But you could try installing mingw, making sure to include gcc, and following the instructions in the tree INSTALL file. I have used mingw to compile things like this on Windows in the past, so this part is definitely possible. Jan 22, 2014 at 9:30
2

In windows 10 locate tree.com and copy it as tree.exe in the mingw bin folder (in my case C:\Program Files\Git\mingw64\bin)

1

Another option would be to use the MinGW package, if you already have MinGW installed, tree is packaged there, just install it by opening a MinGW terminal and running pacman -Sy tree.

If you don't have MinGW installed already it's probably overkill to install it just for the tree command.

0

You must install the Three for Windows as said above by the link: http://gnuwin32.sourceforge.net/packages/tree.htm

Besides that you need to add the tree program to your windows path or the tree command will be available only on cmd. Access your windows path and add this (for default installation):

;C:\Program Files (x86)\GnuWin32\bin

Them you will be able to use tree command on git bash on windows.

0

This is the beginning of my .gitconfig file : I made an alias for log --graph

# This is Git's per-user configuration file.
[user]
# Please adapt and uncomment the following lines:
    name = xxxxxx
    email = [email protected] 
[alias]
    tree = log --graph --oneline --all --pretty=format:'%C(yellow)%h%Creset -%Cred%d%Creset %s %Cgreen%cr%Creset %C(cyan)%an%Creset %gn'
1
  • 2
    Not the solution. The alias shows the commit and not the files / dirs.
    – Timo
    Oct 26, 2017 at 10:01
0

I use Windows Terminal in Windows 10, whenever I need this, I switch the terminal just typing cmd, after I get what I need, I can change the terminal cmd -> bash with typing bash

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .