前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >linux命令tree的使用

linux命令tree的使用

原创
作者头像
挥刀北上
修改2020-08-03 17:57:53
1.2K0
修改2020-08-03 17:57:53
举报
文章被收录于专栏:Node.js开发Node.js开发

有时候我们新建完项目,想查看一下项目的目录结构,此时我们就可以使用tree命令了,但是mac电脑没有自带tree命令,我们需要安装tree。

我们可以使用brew工具进行安装,安装命令如下:

代码语言:javascript
复制
brew install tree

安装完成之后,我们可以运行 help指令查看tree有哪些指令:

代码语言:javascript
复制
tree --help

打印如下:

代码语言:javascript
复制
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.
  -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.
  -D            Print the date of last modification.
  -F            Appends '/', '=', '*', or '|' as per 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.
  -S            Print with ASCII graphics indentation lines.
  -n            Turn colorization off always (-C overrides).
  -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.
  -T string     Replace the default HTML title and H1 header with string.
  -R            Rerun tree when max dir level reached.
  -o file       Output to file instead of stdout.
  --inodes      Print inode number of each file.
  --device      Print device ID number to which each file belongs.
  --noreport    Turn off file/directory count at end of tree listing.
  --nolinks     Turn off hyperlinks in HTML output.
  --dirsfirst   List directories before files.
  --charset X   Use charset X for HTML and indentation line output.
  --filelimit # Do not descend dirs with more than # files in them.

这里命令很多,这里只简单介绍下常用的几个指令:

代码语言:javascript
复制
- 显示深度达到 “级数” 级的文件和目录(其中 1 表示当前目录):
    tree -L 级数
- 只显示目录:
    tree -d
- 同时显示隐藏文件:
    tree -a
- 忽略文件或目录:
    tree -I 文件名称/目录名称

此时我们还可以借助另外一个命令行工具tldr来显示tree命令工具的常用命令,安装tldr有多种方式,这里我们采用npm来安装,

代码语言:javascript
复制
 npm install tldr -g

之后运行:

代码语言:javascript
复制
tldr tree 

打印如下:

代码语言:javascript
复制
tree

  以树的形式显示当前目录的内容.

  - 显示深度达到 “级数” 级的文件和目录(其中 1 表示当前目录):
    tree -L 级数

  - 只显示目录:
    tree -d

  - 同时显示隐藏文件:
    tree -a

  - 打印没有缩进行的树,显示完整路径(使用-N不转义空格和特殊字符):
    tree -i -f

  - 以可读格式打印每个文件节点的大小,目录显示其累积大小(类似在du命令中所示):
    tree -s -h --du

  - 使用通配符(glob)模式在树层次结构中查找文件,并删除不包含匹配文件的目录:
    tree -P '*.txt' --prune

  - 在树层次结构中查找目录,删除不属于所需目录的目录:
    tree -P 文件夹名 --matchdirs --prune


See also: du

以上便是tree命令的使用,希望对你有所帮助。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档