命令行输出目录树
2023-7-4 大约 1 分钟
# 如何使用命令行输出目录树
概述:在自己写博客的时候,总会少不了要显示目录结构以更好的表达一些内容;虽然
window
自己提供了tree
命令但是并不好用;比如我要显示项目的目录结构但是要排除node_modules
文件夹,这个时候就有点力不从心了,在这里推荐以下tree-node-cli
工具;
下载:
tree-node-cli
传送门 (opens new window)。安装:
npm install -g tree-node-cli
1参数:
$ tree -h 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 display help for command
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15使用:直接打印输出;
$ tree -L 2 -I "node_modules" webNode ├── app │ ├── app.js │ ├── db │ └── router ├── babel.config.js ├── bin │ ├── build.js │ └── dev.js ├── dist │ ├── css │ ├── favicon.ico │ ├── img │ ├── index.html │ └── js ├── package-lock.json ├── package.json ├── plugins │ └── md-loader ├── public │ ├── favicon.ico │ └── index.html ├── src │ ├── App.vue │ ├── assets │ ├── index.js │ ├── router │ ├── service │ └── views └── webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32注意:这里我命令使用的是:
tree -L 2 -I "node_modules"
并没有使用tree
命令那样它会把整个node_modules目录也给遍历出来,对我们来说是无用的。当然在不包含node_modules
的目录下直接使用tree
命令就行了。输出到单独的文件中;
`tree -L 2 -I "node_modules"` > text.md
1如果文件不存在便会自己创建一个文件,如果存在的话便会覆盖里面的内容;