Shell学习-16-tree命令安装及使用

114 篇文章 11 订阅
16 篇文章 0 订阅
3.5 tree命令安装及使用
  • 查看运行的Linux发行版本 (#cat /etc/issue),查看运行的Linux内核信息 (#cat /proc/version )
3.5.1 tree命令简介
  • tree命令是一种递归目录列表显示命令,使用该命令可以以树状图的形式列出一个目录下所有文件内容。tree适用于以下系统:Linux,FreeBSD,OS X操作系统,Solaris,HP UX,Cygwin,HP NonStop OS / 2。

  • tree命令安装:

    • 方法一:installyum安装。Ubuntu下使用apt get-intall tree;Fedora和RedHat以及CentOS下使用#yum install tree
    • 手动安装:下载源码安装包:http://mama.indstate.edu/users/ice/tree/,选择最新版:
      在这里插入图片描述
#解压安装包命令:
[root@VM-0-3-centos ~]# cd /usr/local/src
[root@VM-0-3-centos src]# tar -zxvf tree-2.1.0.tgz
#进入解压目录,使用`ls`查看文件内容:
[root@VM-0-3-centos src]# cd tree-2.1.0
[root@VM-0-3-centos tree-2.1.0]# ll
total 208
-rw-r--r-- 1 4437 users 21406 Dec 27 00:11 CHANGES
-rw-r--r-- 1 4437 users 16158 Dec 27 03:13 color.c
drwxr-xr-x 2 root root   4096 Dec 29 14:54 doc
-rw-r--r-- 1 4437 users  6364 Dec 25 01:15 file.c
-rw-r--r-- 1 4437 users  3993 Dec 12 00:04 filter.c
-rw-r--r-- 1 4437 users  3118 Jun 16  2022 hash.c
-rw-r--r-- 1 4437 users  6669 Dec 12 01:13 html.c
-rw-r--r-- 1 4437 users  4669 Dec 12 00:02 info.c
-rw-r--r-- 1 4437 users   597 Dec  2 12:40 INSTALL
-rw-r--r-- 1 4437 users  5927 Dec  5 06:30 json.c
-rw-r--r-- 1 4437 users 18009 Aug 13  2004 LICENSE
-rw-r--r-- 1 4437 users  7251 Dec 25 02:06 list.c
-rw-r--r-- 1 4437 users  2936 Dec 27 03:15 Makefile
-rw-r--r-- 1 4437 users  9028 Dec 27 03:29 README
-rw-r--r-- 1 4437 users  5346 Apr 14  2021 strverscmp.c
-rw-r--r-- 1 4437 users   853 Dec 21  2021 TODO
-rw-r--r-- 1 4437 users 39412 Dec 25 09:01 tree.c
-rw-r--r-- 1 4437 users  8677 Dec 12 01:12 tree.h
-rw-r--r-- 1 4437 users  3166 Jun 16  2022 unix.c
-rw-r--r-- 1 4437 users  5039 Dec  5 06:36 xml.c
#安装该指令文件,命令:
[root@VM-0-3-centos tree-2.1.0]# sudo make install
#输入#tree --version测试该指令:
[root@VM-0-3-centos tree-2.1.0]# tree --version
tree v2.1.0 © 1996 - 2022 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
3.5.2 tree使用
  • tree语法如下:
tree [-aACdDfFgilnNpqstux][-I <范本样式>][-P <范本样式>][目录...]
  • 选项说明:
-a 显示所有文件和目录。
-A 使用ASNI绘图字符显示树状图而非以ASCII字符组合。
-C 在文件和目录清单加上色彩,便于区分各种类型。
-d 显示目录名称而非内容。
-D 列出文件或目录的更改时间。
-f 在每个文件或目录之前,显示完整的相对路径名称。
-F 在执行文件,目录,Socket,符号连接,管道名称名称,各自加上"*","/","=","@","|"号。
--inodes      # Print inode number of each file.
--device      # Print device ID number to which each file belongs.
-g 列出文件或目录的所属群组名称,没有对应的名称时,则显示群组识别码。
-i 不以阶梯状列出文件或目录名称。
-I pattern #Do not list files that match the given pattern.
-L level 限制目录显示层级。
-l 如遇到性质为符号连接的目录,直接列出该连接所指向的原始目录。
-n 不在文件和目录清单加上色彩。
-N 直接列出文件和目录名称,包括控制字符。
-p 列出权限标示。
-P<范本样式> 只显示符合范本样式的文件或目录名称。
-q 用"?"号取代控制字符,列出文件和目录名称。
-Q  # Quote filenames with double quotes.
-R # Rerun tree when max dir level reached.
-s 列出文件或目录大小。
-S    # Print with CP437 (console) graphics indentation lines.
--si   # Like -h, but use in SI units (powers of 1000).
-h   # Print the size in a more human readable way.
-t 用文件和目录的更改时间排序。
-u 列出文件或目录的拥有者名称,没有对应的名称时,则显示用户识别码。
-x 将范围局限在现行的文件系统中,若指定目录下的某些子目录,其存放于另一个文件系统上,则将该子目录予以排除在寻找范围外。
--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.
-v            # Sort files alphanumerically by version.
-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.
------- XML / HTML / JSON选项 -------
-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.
---- 杂项选项 ----
--version     # 输入版本信息。
--help        # 打印使用帮助信息。
--            # Options processing terminator.
  • 参数说明:
    目录:执行tree指令,它会列出指定目录下的所有文件,包括子目录里的文件。

  • 测试:在需要查看的文件夹下输入#tree指令查看当前目录结构:

[root@VM-0-3-centos usr]# cd /usr/local/redis
[root@VM-0-3-centos redis]# pwd
/usr/local/redis
[root@VM-0-3-centos redis]# tree
.
├── bin
│   ├── redis-benchmark
│   ├── redisbloom.so
│   ├── redis-check-aof -> redis-server
│   ├── redis-check-rdb -> redis-server
│   ├── redis-cli
│   ├── redis-sentinel -> redis-server
│   └── redis-server
├── conf
│   ├── appendonlydir
│   │   ├── appendonly.aof.1.base.rdb
│   │   ├── appendonly.aof.1.incr.aof
│   │   └── appendonly.aof.manifest
│   ├── redis_6500.conf
│   └── redis.conf
└── dump.rdb

4 directories, 13 files
  • 忽略文件夹
tree -I node_modules # 忽略当前目录文件夹node_modules
tree -P node_modules # 列出当前目录文件夹node_modules的目录结构
tree -P node_modules -L 2 # 显示目录node_modules两层的目录树结构
tree -L 2 > /home/www/tree.txt # 当前目录结果存到 tree.txt 文件中
  • 忽略多个文件夹,注意用''将忽略的文件和目录引起来
[root@VM-0-3-centos redis]# tree -I 'conf|dump.rdb' -L 2
.
└── bin
    ├── redis-benchmark
    ├── redisbloom.so
    ├── redis-check-aof -> redis-server
    ├── redis-check-rdb -> redis-server
    ├── redis-cli
    ├── redis-sentinel -> redis-server
    └── redis-server

2 directories, 7 files

  • 非树状结构列出目录/bin/下的所有文件
[root@VM-0-3-centos redis]# tree -if bin
bin
bin/redis-benchmark
bin/redisbloom.so
bin/redis-check-aof -> redis-server
bin/redis-check-rdb -> redis-server
bin/redis-cli
bin/redis-sentinel -> redis-server
bin/redis-server

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值