macOs | 使用 tree 命令

如何安装和使用 tree 命令查看目录结构?

Posted by Haauleon on April 30, 2021

背景

  很多时候看别人的项目代码,都需要使用 tree 命令来查看目录结构。macOs 系统虽然是类 Unix 系统,但是安装和使用却跟 Linux 还是有些差别的,它是使用 brew 来管理 tree 扩展。



使用技巧

1
2
3
$ brew search tree
$ brew install tree
$ tree


安装成功后,使用效果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
192:utx haauleon$ tree
.
├── __init__.py
├── __pycache__
│   ├── __init__.cpython-37.pyc
│   ├── core.cpython-37.pyc
│   ├── log.cpython-37.pyc
│   ├── runner.cpython-37.pyc
│   ├── setting.cpython-37.pyc
│   └── tag.cpython-37.pyc
├── core.py
├── log.py
├── report
│   ├── __init__.py
│   ├── style_1.py
│   └── style_2.py
├── runner.py
├── setting.py
└── tag.py

2 directories, 15 files
192:utx haauleon$