1980's Maker

一个出生于80年代的程序员 -- 喜爱创[客]、美[食]、动[画]、怀[旧]的新手艺人的博客

【常用Shell命令】- tree

浏览博客文章时经常会看到一些很漂亮的目录结构,就像下面所示

assets
├── fonts
│   ├── google
│   │   ├── bbr.woff2
│   │   └── sarpanch.woff2
│   └── icomoon
│       └── Icon.woff
└── images
    └── bg.png
1
2
3
4
5
6
7
8
9

以前不知道还以为是XX高级编辑器插件, 其实系统自带的tree命令就可以帮助我们搞定这些高大上的目录结构.

# tree 命令生成目录树

语法格式:tree [参数]

常用参数:

参数名 说明
-L level 限制目录显示层级
-C 显示目录和文件的色彩区分
-d -d 只显示目录不显示内容。
-f 在每个文件或目录之前,显示完整的相对路径名称
--dirsfirst 优先显示目录
-p 列出权限标示
-s 列出文件或目录大小

# 示例

tree blog -L 2 -C --dirsfirst

blog
├── _post
│   ├── maker-icon.md
│   ├── maker.md
│   ├── md5.md
│   ├── shell-tree.md
│   ├── theme-learning-0.md
│   ├── theme-learning-concept.md
│   └── theme-showcase.md
├── archives
│   └── index.md
├── friend-links
│   └── index.md
└── README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# mac下可通过homebrew安装tree命令

$ brew install tree
1

Buy me a cup of coffee ☕.