程式設計師經常會有需求,需要列出專案的結構樹。mac或者linux下可以使用tree列出專案結構,如下圖這種:
tree examples
examples
└── example.js
使用起來也非常簡單。
mac下可以使用brew install tree進行安裝。安裝後,在terminal中輸入tree -a便可以檢視某個資料夾下的所有檔案。
常用的命令
當然了,我們的需求肯定不止列出所有檔案這麼簡單。下面介紹幾個常用的命令
* tree -d 只顯示資料夾;
* tree -l n 顯示專案的層級。n表示層級數。比如想要顯示專案三層結構,可以用tree -l 3;
* tree -i pattern 用於過濾不想要顯示的檔案或者資料夾。比如你想要過濾專案中的node_modules資料夾,可以使用tree -i "node_modules";
* tree > tree.md 將專案結構輸出到tree.md這個檔案。
舉個例子,如果我們要顯示某個專案下3層的所有檔案結構,同時又過濾node_modules資料夾,最後輸出到tree.md,可以這麼寫
tree -l 3 -i "node_modules"
結果為:
.
├── readme.md
├── build
│ ├── build.js
│ ├── check-versions.js
│ ├── dev-client.js
│ ├── dev-server.js
│ ├── utils.js
│ ├── webpack.base.conf.js
│ ├── webpack.dev.conf.js
│ └── webpack.prod.conf.js
├── config
│ ├── dev.env.js
│ ├── index.js
│ └── prod.env.js
├── docs
│ ├── index.html
│ └── static
│ ├── css
│ └── js
├── git.sh
├── index.html
├── npm-debug.log
├── open
├── package.json
├── src
│ ├── assets
│ │ ├── list.scss
│ │ ├── logo.png
│ │ ├── search-btn.png
│ │ └── style.scss
│ ├── components
│ │ ├── hello.vue
│ │ ├── spinner.vue
│ │ └── header.vue
│ ├── main.js
│ ├── router.js
│ ├── store
│ │ ├── api.js
│ │ ├── modules
│ │ ├── store.js
│ │ └── types.js
│ └── views
│ ├── book
│ ├── index.vue
│ ├── movie
│ └── vuex-demo.vue
├── static
└── tree.md
更多命令的使用可以檢視tree --help。
tree /f d:\dir1 > d:\tree.txt
就是將d:\dir1的目錄結構以樹狀形式輸出報告到檔案tree.txt中。
MacOS如何使用 tree 生成目錄結構
homebrew官網 homebrew介紹和使用 根據官網的方法安裝 usr bin ruby e curl fssl 比如我的 this script will install usr local bin brew usr local share doc homebrew usr local sh...
使用tree生成專案目錄樹結構
全域性安裝 npm install g treer 使用示例 treer e result.txt i node modules 遍歷到result.txt檔案,忽略node modules 缺陷 格式固定,引數順序前後順序不可隨意調換,不能選擇目錄層級 npm詳細使用文件 全域性安裝 npm in...
js 根據 目錄結構,生成tree結構
根據 aws s3 獲取 bucket 下的 所有檔案 返回格式如下 var arr root root a root a new b.png root a qa root a qa 新建文字文件 3 txt root asdfasdfasdfasdfasdfasdfasdf.txt root b ...