咱们常常在写博客或者项目设计文档时须要列出项目的结构树。咱们下能够使用tree列出项目结构,以下面这种:node
news_watch_notice
├── cmd //main
├── conf
├── dis
├── Dockerfile
├── Makefile
├── pkg
├── qrcode
├── .travis.yml
├── README.md
├── vendor
├── utils
复制代码
windows提供了一个tree命令可供咱们使用,可是不太好用。git
TREE [drive:][path] [/F] [/A]
/F 显示每一个文件夹中文件的名称。
/A 使用 ASCII 字符,而不使用扩展字符。
复制代码
D:\dev\gopath\src\news_watch_notice>tree /agithub
文件夹 PATH 列表
卷序列号为 989E-DB7E
D:.
+---.idea
+---cmd
| \---qrcode
+---conf
+---dis
| \---qrcode
+---pkg
| +---mail
| +---reptile
| \---wechat
+---qrcode
+---utils
复制代码
D:\dev\gopath\src\news_watch_notice>tree /fnpm
文件夹 PATH 列表
卷序列号为 989E-DB7E
D:.
│ .gitignore
│ .travis.yml
│ Dockerfile
│ Makefile
│ README.md
│ tree.md
│
├─.idea
│ .name
│ misc.xml
│ modules.xml
│ news_watch_notice.iml
│ vcs.xml
│ workspace.xml
│
├─cmd
│ │ news_watch_notice.go
│ │
│ └─qrcode
│ qrcode.jpg
复制代码
能够看到确实按照咱们想要的结构输出了,可是只有两个命令的使用并不能知足咱们平常的须要,好比咱们想忽略某个文件,想把生成的树状结构输出的一个文件中又该如何操做.windows
#安装tree-node-cli模块包
npm install -g tree-node-cli
复制代码
$ tree --help
Usage: tree [options]
Options:
-V, --version output the version number
-a, --all-files All files, include hidden files, are printed.
--dirs-first List directories before files.
-d, --dirs-only List directories only.
-I, --exclude [patterns] Exclude files that match the pattern. | separates alternate patterns. Wrap your entire pattern in double quotes. E.g. `"node_modules|coverage".
-L, --max-depth <n> Max display depth of the directory tree.
-r, --reverse Sort the output in reverse alphabetic order.
-F, --trailing-slash Append a '/' for directories.
-h, --help output usage information
复制代码
tree -d 只显示文件夹;bash
举例:若是咱们要显示某个项目下3层的全部文件结构,同时又过滤node_modules文件夹,最后输出到tree.md,能够这么写微信
$ tree -L 3 -I "vendor" > tree.md
复制代码
结果:tree.mdide
news_watch_notice
├── cmd
│ ├── news_watch_notice.go
│ └── qrcode
│ └── qrcode.jpg
├── conf
│ └── conf.conf
├── dis
│ ├── news_watch_notice
│ └── qrcode
│ └── qrcode.jpg
├── Dockerfile
├── Makefile
├── pkg
│ ├── mail
│ │ └── mail.go
│ ├── reptile
│ │ └── reptile.go
│ └── wechat
│ └── wechat.go
├── qrcode
│ └── qrcode.jpg
├── README.md
├── tree.md
├── utils
│ └── common_utils.go
复制代码
微信公众号
githubidea