导读 Dutree是Durep和Tree的组合。Durep用图表创建磁盘使用情况报告,这使我们能够确定哪些目录使用了最多的空间。尽管durep可以产生类似于du的文本输出,但其真正的功能是能够将报告存储在文件中。Tree是目录显示程序,它以树状结构在终端上递归列出目录。

dutree的特性:

  • 彩色输出
  • 分层显示文件系统
  • 用户可以聚合小文件
  • 用户可以排除文件或目录
  • 用户可以比较不同的目录
  • 可靠性和速度快
系统环境

Centos7

安装

需要先安装cargo包管理器:

[root@localhost ~]# yum -y install cargo

其次配置cargo的仓库地址,因为默认使用国外源,下载速度超慢:

进入$HOME/.cargo创建config配置文件:

[root@localhost ~]# cd $HOME/.cargo
[root@localhost .cargo]# touch config

将下面内容复制到config配置文件中:

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"

# 替换成速度比较快的镜像源,这里使用上海交大的。
replace-with = 'sjtu'

# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

# rustcc社区
[source.rustcc]
registry = "git://crates.rustcc.cn/crates.io-index"


开始安装dutree吧:

[root@localhost ~]# cargo install dutree
    Updating `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index` index
  Downloaded dutree v0.2.16 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded 1 crate (638.0 KB) in 0.37s
  Installing dutree v0.2.16
  Downloaded signal-hook v0.1.16 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded terminal_size v0.1.13 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded thread_local v1.0.1 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded signal-hook-registry v1.2.2 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded unicode-width v0.1.8 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded memchr v2.3.4 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded regex-syntax v0.6.21 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded aho-corasick v0.7.14 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded regex v1.4.2 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded libc v0.2.80 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded lazy_static v1.4.0 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded getopts v0.2.21 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded unicode-segmentation v1.6.0 (registry `https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index`)
  Downloaded 13 crates (1.4 MB) in 0.43s
   Compiling libc v0.2.80
   Compiling memchr v2.3.4
   Compiling lazy_static v1.4.0
   Compiling unicode-width v0.1.8
   Compiling regex-syntax v0.6.21
   Compiling unicode-segmentation v1.6.0
   Compiling thread_local v1.0.1
   Compiling getopts v0.2.21
   Compiling signal-hook-registry v1.2.2
   Compiling terminal_size v0.1.13
   Compiling aho-corasick v0.7.14
   Compiling signal-hook v0.1.16
   Compiling regex v1.4.2
   Compiling dutree v0.2.16
    Finished release [optimized] target(s) in 1m 35s
  Installing /root/.cargo/bin/dutree
   Installed package `dutree v0.2.16` (executable `dutree`)
warning: be sure to add `/root/.cargo/bin` to your PATH to be able to run the installed binaries


看到上面最后一个warning提示,需要将/root/.cargo/bin目录添加到PATH环境变量中:

[root@localhost ~]# echo "export PATH=$PATH:/root/.cargo/bin" >> ~/.bashrc 
[root@localhost ~]# source ~/.bashrc 

现在可以使用dutree了

实例
目录深度

通过-d选项,加上数字,查看一层目录或者多层目录,下面是查看/root用户家目录的,查查看一层目录:

[root@localhost ~]# dutree -d1 ./


下面是查看/root家目录最多3层目录:

[root@localhost ~]# dutree -d3 ./


如果不限制目录层数,可以不加-d选项,下面查看/root/test目录:

[root@localhost ~]# dutree test/

排除某个文件

要排除与文件或目录名称匹配的内容,请使用-x选项。下面排除test目录中包括dir1的项目:

[root@localhost ~]# dutree -x dir1 test/


使用-H选项,可以排除隐藏文件:

[root@localhost ~]# dutree -H


可以看到隐藏文件没有列出来。

进度条使用ASCII字符显示

可以使用ASCII字符#号来代替默认的进度条:

[root@localhost ~]# dutree -d1 -A /root

总结

Dutree是Durep和Tree的组合。Durep用图表创建磁盘使用情况报告,这使我们能够确定哪些目录使用了最多的空间。尽管durep可以产生类似于du的文本输出,但其真正的功能是能够将报告存储在文件中。Tree是目录显示程序,它以树状结构在终端上递归列出目录。

本文原创地址:https://www.linuxprobe.com/dutree-linux-disk.html编辑:逄增宝,审核员:逄增宝