mac 生成目录结构tree brew安装

使用Tree命令管理项目目录
本文介绍如何利用Tree命令清晰地展示项目文件结构,并提供了一系列实用技巧,如限制目录层级显示、导出目录结构到文件及过滤特定文件夹等。

目录示例

.
├── README.md
├── build
│   ├── build.js
│   ├── check-versions.js
│   ├── utils.js
│   ├── vue-loader.conf.js
│   ├── webpack.base.conf.js
│   ├── webpack.dev.conf.js
│   └── webpack.prod.conf.js
├── config
│   ├── dev.env.js
│   ├── index.js
│   ├── prod.env.js
│   └── test.env.js
├── dist
│   ├── index.html
│   └── static
│       ├── css
│       │   └── app.css
│       ├── img
│       │   ├── 1.png
│       │   ├── 2.png
│       │   ├── 3.png
│       └── js
│           ├── app.js
│           ├── manifest.js
│           └── vendor.js
├── index.html
├── package-lock.json
├── package.json
├── src
│   ├── App.vue
│   ├── assets
│   │   ├── img
│   │   │   ├── 1.png
│   │   │   ├── 2.png
│   │   │   ├── 3.png
│   │   │   ├── 4.png
│   │   └── logo.png
│   ├── components
│   │   ├── HelloWorld.vue
│   │   └── game.vue
│   ├── js
│   │   └── sdpro.js
│   ├── main.js
│   ├── pages
│   │   ├── four.vue
│   │   ├── home.vue
│   │   ├── nine.vue
│   │   ├── result.vue
│   │   └── six.vue
│   ├── router
│   │   └── index.js
│   └── store
│       └── index.js
├── static
└── test
    ├── e2e
    │   ├── custom-assertions
    │   │   └── elementCount.js
    │   ├── nightwatch.conf.js
    │   ├── runner.js
    │   └── specs
    │       └── test.js
    └── unit
        ├── jest.conf.js
        ├── setup.js
        └── specs
            └── HelloWorld.spec.js

安装tree

mac 下使用 brew包管理工具安装 tree

没有装brew 的看这里=> brew官网
直接安装:
打开命令终端 复制粘贴回车 /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

安装命令
brew install tree

安装成功后可以查看tree 的相关命令
tree –help

usage: tree [-acdfghilnpqrstuvxACDFJQNSUX] [-H baseHREF] [-T title ]
    [-L level [-R]] [-P pattern] [-I pattern] [-o filename] [--version]
    [--help] [--inodes] [--device] [--noreport] [--nolinks] [--dirsfirst]
    [--charset charset] [--filelimit[=]#] [--si] [--timefmt[=]<f>]
    [--sort[=]<name>] [--matchdirs] [--ignore-case] [--] [<directory list>]
  ------- Listing options -------
  -a            All files are listed.
  -d            List directories only.
  -l            Follow symbolic links like directories.
  -f            Print the full path prefix for each file.
  -x            Stay on current filesystem only.
  -L level      Descend only level directories deep.
  -R            Rerun tree when max dir level reached.
  -P pattern    List only those files that match the pattern given.
  -I pattern    Do not list files that match the given pattern.
  --ignore-case Ignore case when pattern matching.
  --matchdirs   Include directory names in -P pattern matching.
  --noreport    Turn off file/directory count at end of tree listing.
  --charset X   Use charset X for terminal/HTML and indentation line output.
  --filelimit # Do not descend dirs with more than # files in them.
  --timefmt <f> Print and format time according to the format <f>.
  -o filename   Output to file instead of stdout.
  -------- File options ---------
  -q            Print non-printable characters as '?'.
  -N            Print non-printable characters as is.
  -Q            Quote filenames with double quotes.
  -p            Print the protections for each file.
  -u            Displays file owner or UID number.
  -g            Displays file group owner or GID number.
  -s            Print the size in bytes of each file.
  -h            Print the size in a more human readable way.
  --si          Like -h, but use in SI units (powers of 1000).
  -D            Print the date of last modification or (-c) status change.
  -F            Appends '/', '=', '*', '@', '|' or '>' as per ls -F.
  --inodes      Print inode number of each file.
  --device      Print device ID number to which each file belongs.
  ------- Sorting options -------
  -v            Sort files alphanumerically by version.
  -t            Sort files by last modification time.
  -c            Sort files by last status change time.
  -U            Leave files unsorted.
  -r            Reverse the order of the sort.
  --dirsfirst   List directories before files (-U disables).
  --sort X      Select sort: name,version,size,mtime,ctime.
  ------- Graphics options ------
  -i            Don't print indentation lines.
  -A            Print ANSI lines graphic indentation lines.
  -S            Print with CP437 (console) graphics indentation lines.
  -n            Turn colorization off always (-C overrides).
  -C            Turn colorization on always.
  ------- XML/HTML/JSON options -------
  -X            Prints out an XML representation of the tree.
  -J            Prints out an JSON representation of the tree.
  -H baseHREF   Prints out HTML format with baseHREF as top directory.
  -T string     Replace the default HTML title and H1 header with string.
  --nolinks     Turn off hyperlinks in HTML output.
  ---- Miscellaneous options ----
  --version     Print version and exit.
  --help        Print usage and this help message and exit.
  --            Options processing terminator.

切换到指定目录输出

使用 cd 项目路径 指定到需要输出目录的文件夹

tree 回车
可查看所有层级的目录

常用方法

指定遍历层级

tree -L 2

2表示第几级

.
├── README.md
├── build
│   ├── build.js
│   ├── check-versions.js
│   ├── utils.js
│   ├── vue-loader.conf.js
│   ├── webpack.base.conf.js
│   ├── webpack.dev.conf.js
│   └── webpack.prod.conf.js
├── config
│   ├── dev.env.js
│   ├── index.js
│   ├── prod.env.js
│   └── test.env.js
├── dist
│   ├── index.html
│   └── static
├── index.html
├── node_modules
│   ├── @babel
│   ├── @types
│   ├── abab
、、、
│   ├── yargs
│   ├── yargs-parser
│   └── yauzl
├── package-lock.json
├── package.json
├── src
│   ├── App.vue
│   ├── assets
│   ├── components
│   ├── js
│   ├── main.js
│   ├── pages
│   ├── router
│   └── store
├── static
└── test
    ├── e2e
    └── unit

导出到文件 Readme.md

tree -L 2 >README.md

过滤指定文件夹

tree -I “文件夹名”
如下过滤 node_modules
tree -I “node_modules”

.
├── README.md
├── build
│   ├── build.js
│   ├── check-versions.js
│   ├── utils.js
│   ├── vue-loader.conf.js
│   ├── webpack.base.conf.js
│   ├── webpack.dev.conf.js
│   └── webpack.prod.conf.js
├── config
│   ├── dev.env.js
│   ├── index.js
│   ├── prod.env.js
│   └── test.env.js
├── dist
│   ├── index.html
│   └── static
│       ├── css
│       │   └── app.css
│       ├── img
│       │   ├── 1.png
│       │   ├── 2.png
│       │   ├── 3.png
│       │   ├── 4.png
│       └── js
│           ├── app.js
│           ├── manifest.js
│           └── vendor.js
├── index.html
├── package-lock.json
├── package.json
├── src
│   ├── App.vue
│   ├── assets
│   │   ├── img
│   │   │   ├── 1.png
│   │   │   ├── 2.png
│   │   │   ├── 3.png
│   │   │   ├── 4.png
│   │   └── logo.png
│   ├── components
│   │   ├── HelloWorld.vue
│   │   └── game.vue
│   ├── js
│   │   └── sdpro.js
│   ├── main.js
│   ├── pages
│   │   ├── four.vue
│   │   ├── home.vue
│   │   ├── nine.vue
│   │   ├── result.vue
│   │   └── six.vue
│   ├── router
│   │   └── index.js
│   └── store
│       └── index.js
├── static
└── test
    ├── e2e
    │   ├── custom-assertions
    │   │   └── elementCount.js
    │   ├── nightwatch.conf.js
    │   ├── runner.js
    │   └── specs
    │       └── test.js
    └── unit
        ├── jest.conf.js
        ├── setup.js
        └── specs
            └── HelloWorld.spec.js

只显示文件夹

tree -d
如下 过滤node_modules➕只显示文件夹
tree -d -I “node_modules”

.
├── build
├── config
├── dist
│   └── static
│       ├── css
│       ├── img
│       └── js
├── src
│   ├── assets
│   │   └── img
│   ├── components
│   ├── js
│   ├── pages
│   ├── router
│   └── store
├── static
└── test
    ├── e2e
    │   ├── custom-assertions
    │   └── specs
    └── unit
        └── specs
为代码项目生成目录结构的方法有多种,可以根据操作系统、工具偏好以及输出格式进行选择。以下是一些常见方式及其使用场景: ### 1. 使用命令行工具 `tree` 在 Windows 系统中,可以通过 `cmd` 使用 `tree` 命令生成目录结构。该方法适用于快速查看或导出文本形式的目录树。 - **Windows**: ```bash tree /f > project_structure.txt ``` 这条命令会递归列出当前目录下的所有文件和子目录,并将其保存到 `project_structure.txt` 文件中。 - **Mac/Linux**: 在 Unix 系统上也可以使用 `tree` 命令,但可能需要先安装 `tree` 工具。 ```bash tree > project_structure.txt ``` 如果系统未安装 `tree`,可通过包管理器(如 `brew` 或 `apt-get`)进行安装[^2]。 --- ### 2. 使用 NPM 工具 `treer` 对于前端或 Node.js 项目,可以使用 `treer` 模块来生成更灵活的目录结构。它支持忽略特定文件夹(如 `node_modules`),并将结果导出为 `.txt` 或 `.md` 文件。 - 安装: ```bash npm install -g treer ``` - 使用示例: ```bash treer -i "node_modules" -e "project_structure.md" ``` 此命令会忽略 `node_modules` 目录,并将结构输出到 `project_structure.md` 文件中。 --- ### 3. 使用 IntelliJ IDEA 内置功能 IntelliJ IDEA 提供了“Project Structure”功能,可以直接在 IDE 中查看项目的文件层级结构。虽然不能直接导出为纯文本目录树,但结合 Structurizr 插件可以生成图形化的架构图和文档,适合展示高层次的模块划分和依赖关系。 - 打开项目后,在菜单栏选择 `File -> Project Structure` 查看模块结构。 - 对于可视化架构图,可集成 Structurizr 插件并定义 C4 模型来生成类图与系统图[^1]。 --- ### 4. 使用 SourceTree 导出目录结构 SourceTree 是一款 Git 图形化管理工具,虽然主要用于版本控制,但它也提供了查看和导出项目目录结构的功能。 - 打开项目后,在左侧边栏可以看到完整的文件目录。 - 可通过截图或复制路径信息的方式导出目录结构,适用于展示文件组织层次。 --- ### 5. 使用 VSCode 插件或脚本 在 VSCode 中,可以通过扩展插件(如 “Project Tree”)或自定义脚本来生成美观的目录树。例如,以下是一个典型的 VSCode 输出样式: ``` project-tree ├─ .git ├─ .gitignore ├─ .vscodeignore ├─ images ├─ node_modules ├─ src │ ├─ config.ts │ ├─ index.ts │ └─ utils.ts ├─ tsconfig.json ├─ tslint.json └─ webpack.config.js ``` 可以使用第三方工具或脚本(如 Python 脚本遍历目录)来自动生成此类结构[^3]。 --- ### 6. 使用在线目录结构生成器 有一些专门的小工具可以帮助一键生成目录树,支持自定义样式、忽略规则、前缀设置等功能。用户可以选择目录根路径,生成经典或现代风格的目录结构,并一键复制到剪贴板用于文档编写或分享[^4]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值