tree是用于查看当前目录的项目结构,可以帮我们迅速了解当前目录的结构。

安装

mac下安装tree的命令:

$ brew install tree

使用

$ tree -I ".tox|venv|python_demo.egg-info|__pycache__"
.
├── LICENSE
├── MANIFEST.in
├── README.md
├── docs
│   └── development.md
├── pyproject.toml
├── requirements.txt
├── setup.cfg
├── src
│   └── strategy_sdk_python
│       ├── __init__.py
│       ├── cmdline.py
│       ├── config
│       │   ├── __init__.py
│       │   └── settings.yml
│       └── log.py
├── tests
│   ├── __init__.py
│   ├── conftest.py
│   ├── settings.yml
│   └── test_version.py
└── tox.ini

6 directories, 17 files

忽略目录

有些文件夹里的内容我们是不想看到的(可能里面有太多的文件,又或许我们已经对里面的内容已经了解)

这时就需要忽略掉这些内容。

-I命令允许你使用正则匹配来排除掉你不想看到的文件夹,例如:

$ tree -I "node_modules"

也可以使用|同时排除掉多个文件夹:

$ tree -I "node_modules|cache|test_*"

最后一个使用到正则匹配,这样以test_开头的文件夹都不会被显示出来。

只看两级目录

有时候文件夹层级很深,我们只关心前两级的文件,可以使用如下命令:

$ tree -L 2

例如, go项目中vendor文件夹下面可能会有许多go文件,如果想忽略查看这些文件:

$ tree -L 2
.
├── Gopkg.lock
├── Gopkg.toml
├── conf
│   └── app.conf
├── controllers
│   └── default.go
├── main.go
├── models
├── routers
│   └── router.go
├── static
│   ├── css
│   ├── img
│   └── js
├── tests
│   └── default_test.go
├── vendor
│   ├── github.com
│   ├── golang.org
│   └── gopkg.in
└── views
    └── index.tpl