macos – Mac OS X Equivalent of the Ubuntu ‘Tree’ Command

macosterminal.apptree

Is there an equivalent to the Ubuntu tree command for Mac OS X?

Best Answer

You can get the tree command on macOS, too. If you have Homebrew:

brew install tree

If you do not have Homebrew installed, try one approach below.


Installing a package manager approach

Follow the instructions on these websites to install Homebrew, MacPorts, or Fink. Do not install more than one package manager at the same time!

Follow the prompt for whichever you installed.

For Homebrew: brew install tree

For MacPorts: sudo port install tree

For Fink: fink install tree

Installing from source approach

  1. Install the Xcode command line tools by running xcode-select --install.

  2. Download the tree source

  3. Change the Makefile to get it to work, which is also explained in @apuche's answer below. Commenting out the Linux options and uncommenting the macOS options should be enough.

  4. Then, run ./configure, then make.

  5. Now you have to move the tree binary file to a location that's in your executable path. For example:

     sudo mkdir -p /usr/local/bin
     sudo cp tree /usr/local/bin/tree
    
  6. Now edit ~/.bash_profile to include:

     export PATH="/usr/local/bin:$PATH"
    
  7. Reload the shell, and now which tree should point to /usr/local/bin/tree.