導讀 | Dutree是Durep和Tree的組合。Durep用圖表創建磁盤使用情況報告,這使我們能夠確定哪些目錄使用了最多的空間。儘管durep可以產生類似於du的文本輸出,但其真正的功能是能夠將報告存儲在文件中。Tree是目錄顯示程序,它以樹狀結構在終端上遞歸列出目錄。 |
dutree的特性:
- 彩色輸出
- 分層顯示文件系統
- 用戶可以聚合小文件
- 用戶可以排除文件或目錄
- 用戶可以比較不同的目錄
- 可靠性和速度快
系統環境
安裝
需要先安裝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是目錄顯示程序,它以樹狀結構在終端上遞歸列出目錄。