18

I tried using tree command to see the directory structure but it dint work on my mac terminal, it says : command not found. I tried to install the package for command using $brew install tree. it did not work either???

5 Answers 5

40
brew install tree

Windows and Linux already have the function, so Mac needs installation.

Reference: https://superuser.com/q/359723

32

Why not make your own? Open up ~/.bash_profile or ~/.bashrc or /etc/bashrc (open that one with sudo) and add the following line at the bottom:

alias tree='find . -print | sed -e "s;[^/]*/;|____;g;s;____|; |;g"'

Now log out and log back in and your tree command should work - albeit lacking some function of the utility, no doubt :)

I tested this, but thanks to http://osxdaily.com/2016/09/09/view-folder-tree-terminal-mac-os-tree-equivalent/ for coming up with the idea.

1
  • Adding the alias works but -L to limit levels is not available. I instead used brew install tree. Apr 14, 2022 at 0:52
5

If you're using Homebrew on your Mac, simply use brew install tree command on your terminal.

1

If you dont have availability to install tree in linux, but you have installed gio, you can use gio tree with similar functionality.

-4

If you are using Linux, try this: sudo apt install tree.

Hope it works.

3
  • 5
    In the question: on my mac terminal
    – Eric Aya
    Jan 26, 2022 at 17:39
  • At least, it is useful for those who need tree in Docker container. Feb 22, 2022 at 10:27
  • 1
    @Bohdan And running some type of debian. apt is very specific and not really related imo
    – Y. Gherbi
    May 7, 2022 at 8:28

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.