使用 tree 命令生成目录

前言

在分析项目结构的时候,像按照结构路径做一下记录,把目录提取出来
windows 的 cmd 中的 tree 命令可用的参数有限 ,效果并不直观,所以尝试使用 linux 下的tree命令


提示:以下是本篇文章正文内容,下面案例可供参考

一、windows CMD 中的 tree

在文件所在位置的命令行窗口中输入 tree 命令

tree [path] [/f] [/a]
#/f 显示每个文件中文件的名称
#/a 使用ASCII字符,而不使用扩展字符
tree/f
tree/a

会以递归的方式展示所有的目录层级
但是分析项目的时候有一些文件夹是希望可以被忽略掉,或者说想要指定生成的目录层级,windows 中的功能做不到

在windows DOS终端下,tree对应的参数功能有限,无法过滤特定的文件,而且在git bash终端下此命令却无法使用,如果要使用,特用特定的方法,后文中提供了具体的解决方法
tree命令使用:

二、在git命令行工具里使用 tree 命令

1.下载 tree

  • 下载tree

  • 下载binaries文件

  • 在这里插入图片描述

  • 添加tree,将下载文件解压bin/目录下的 tree.exe 复制到 git/usr/bin 目录中,如下图所示:

  • 将tree放到Git/usr/bin目录下

  • 在这里插入图片描述

2.使用 tree 命令

1. 常见参数

$ tree --help
usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]]
        [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]
        [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]
        [--filelimit #] [<directory list>]
  -a            All files are listed(列出所有文件).
  -d            List directories only(只列出目录).
  -l            Follow symbolic links like directories.(遵循象目录这样的符号链接)
  -f            Print the full path prefix for each file(打印每个文件的完整路径前缀).
  -i            Don't print indentation lines()不要打印压痕线.
  -q            Print non-printable characters as '?'.(将不可打印字符打印为'?')
  -N            Print non-printable characters as is.(按原样打印不可打印字符)
  -p            Print the protections for each file.(打印每个文件的保护)
  -u            Displays file owner or UID number(显示文件所有者或UID号).
  -g            Displays file group owner or GID number.(显示文件组所有者或GID编号)
  -s            Print the size in bytes of each file.(打印每个文件的字节大小)
  -h            Print the size in a more human readable way.(以更容易被人阅读的方式打印尺寸)
  -D            Print the date of last modification.(打印上次修改的日期)
  -F            Appends '/', '=', '*', or '|' as per ls -F.(根据ls -F添加'/''=''*''|')
  -v            Sort files alphanumerically by version.(按版本对文件进行字母数字排序)
  -r            Sort files in reverse alphanumeric order.(按字母数字倒序排列文件。)
  -t            Sort files by last modification time.(按上次修改时间排序文件)
  -x            Stay on current filesystem only.(只保留当前文件系统)
  -L level      Descend only level directories deep.(只向下深入到级别目录)
  -A            Print ANSI lines graphic indentation lines.(打印ANSI线图形压痕线)
  -S            Print with ASCII graphics indentation lines.(用ASCII图形缩进行打印)
  -n            Turn colorization off always (-C overrides).(始终关闭着色(-C覆盖))
  -C            Turn colorization on always.(始终打开彩色化)
  -P pattern    List only those files that match the pattern given.(只列出与给定模式匹配的文件)
  -I pattern    Do not list files that match the given pattern.(不要列出与给定模式匹配的文件)
  -H baseHREF   Prints out HTML format with baseHREF as top directory.(打印出以baseHREF作为顶部目录的HTML格式)
  -T string     Replace the default HTML title and H1 header with string.(用字符串替换默认的HTML标题和H1标题)
  -R            Rerun tree when max dir level reached.(当达到最大dir级别时重新运行树)
  -o file       Output to file instead of stdout.(输出到文件而不是stdout)
  --inodes      Print inode number of each file.(打印每个文件的inode编号)
  --device      Print device ID number to which each file belongs.(打印每个文件所属的设备ID号)
  --noreport    Turn off file/directory count at end of tree listing.(在树列表末尾关闭文件/目录计数)
  --nolinks     Turn off hyperlinks in HTML output(关闭HTML输出中的超链接).
  --dirsfirst   List directories before files.(在文件之前列出目录)
  --charset X   Use charset X for HTML and indentation line output.(使用charset X作为HTML和缩进行输出)
  --filelimit # Do not descend dirs with more than # files in them.(不要下载包含超过#文件的dirs)

2. 生成 HbuilderX 中这样文件夹在上,文件在下,字母排序,两层目录层级,忽略 node_modules 和 uview-ui

命令

$ tree -C -L 2  -I "node_modules" --dirsfirst
$ tree -C -L 2  -I "node_modules|uview-ui" --dirsfirst

-C : 彩色
-L 2 : 目录层级两层
-I  "node_modules"  : 忽略 node_modules
-I  "node_modules|uview-ui" 忽略 node_modules 和 uview-ui

生成效果

在这里插入图片描述

3. 生成 md 文件并指定生成的位置

$ tree -C -L 2  -I "node_modules|uview-ui" --dirsfirst > "C:\Users\HP\Desktop\开发文档\料塔称\tree.md"
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值