demand

Sometimes, when writing a document, you need to show the directory structure, so there is a need

The installation

To install tree, run the brew install tree command using brew package management tool on a MAC

Note that Homebrew may need to be updated during installation, which is usually automatically updated. If not, manually update Homebrew update

After the installation is complete, you can run the tree –help command to view the help information.

Common commands

1. Display the project level. N indicates the number of levels. For example, to display the layer 3 structure in the current directory:

tree -L 3
Copy the code

2. Show only folders:

tree -d
Copy the code

3. Filter files and folders when printing:

tree -I "node_modules"
Copy the code

4. Export a directory structure tree to the file readme.md:

tree -L 2 > README.md
Copy the code

5. For a complete example, filter the node_modules folder to display the 4-layer structure in the directory and export it to the readme. md file:

tree -I "node_modules" -L 4 > README.md
Copy the code