Mac installation tree command error solution

Android studio can input tree command in Terminal command line to view the directory structure of the current Android project, which is very convenient, but you need to install the tree command first.
Install tree command brew install tree, the error is reported as follows:

Error: /usr/local/Cellar is not writable. You should change the
ownership and permissions of /usr/local/Cellar back to your
user account:
  sudo chown -R $(whoami) /usr/local/Cellar
Error: Cannot write to /usr/local/Cellar

Follow the prompt sudo chow-r $(whoami) /usr/local/Cellar :

sudo chown -R $zhangsan /usr/local/Cellar
//zhangsan is your name.

Then execute brew install tree.
After the installation is complete, type tree-d in the Terminal command line of as to print out all directory names. In addition tree -a display directory and content.

Read More: