Dutree – Linux 上的命令行磁盤使用分析工具

DUtree 是 Durep 和 Tree 的組合。 Durep 使用圖表創建磁盤使用情況報告,使我們能夠確定哪些目錄使用的空間最多。 儘管 durep 可以產生類似於 du 的文本輸出,但它的真正威力在於能夠將報告存儲在文件中。 樹是目錄顯示程序,它在終端上以樹狀結構遞歸列出目錄。 Tree 是一個乾淨簡單的程序,你可以用它來為目錄和文件系統構建樹狀結構。這讓我列出了 DUtree 的特性,

  • 花式 – 彩色輸出,
  • 分層顯示文件系統,
  • 用戶可以聚合小文件,
  • 用戶可以排除文件或目錄,
  • 用戶可以比較不同的目錄,
  • 可靠且快速。

DUTree 寫在 編程語言, 是一種運行速度驚人的系統編程語言,可以防止段錯誤和線程安全。 今天,我將向您展示如何在 CentOS 7 和 Ubuntu 16.04 上安裝 DUTree。 下面的教程從在 Git 和 RUST 上安裝開始,如果你已經完成了這個,你可以轉到 Dutree 安裝。 請注意,本教程必須安裝 RUST 才能運行。

Git安裝

Ubuntu 16.04

$ sudo apt install git

CentOS 7

$ sudo yum install git

銹安裝

Ubuntu 16.04

$ sudo apt install curl 

$ curl https://sh.rustup.rs -sSf | sh

Centos 7

$ curl https://sh.rustup.rs -sSf | sh
$ git clone https://github.com/nachoparker/dutree.git
Cloning into 'dutree'... 

remote: Counting objects: 27, done. 
remote: Compressing objects: 100% (18/18), done. 
remote: Total 27 (delta 3), reused 27 (delta 3), pack-reused 0 
Unpacking objects: 100% (27/27), done. 
Checking connectivity... done.
$ curl https://sh.rustup.rs -sSf | sh 
Welcome to Rust! 

This will download and install the official compiler for the Rust programming 
language, and its package manager, Cargo. 
It will add the cargo, rustc, rustup and other commands to Cargo's bin directory, located at:   /home/administrator/.cargo/bin 
This path will then be added to your PATH environment variable by modifying the 
profile file located at:   /home/administrator/.profile 
You can uninstall at any time with rustup self uninstall and these changes will be reverted. 
Current installation options:    
  default host triple: x86_64-unknown-linux-gnu
  default toolchain: stable 
  modify PATH variable: yes 

1) Proceed with installation (default) 
2) Customize installation 
3) Cancel installation
$ 1
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' 
info: latest update on 2018-03-01, rust version 1.24.1 (d3ae9a9e0 2018-02-27) 
info: downloading component 'rustc' 
 47.8 MiB /  47.8 MiB (100 %)   1.7 MiB/s ETA:   0 s 
info: downloading component 'rust-std' 
 66.9 MiB /  66.9 MiB (100 %)   1.0 MiB/s ETA:   0 s 
info: downloading component 'cargo' 
  4.2 MiB /   4.2 MiB (100 %)   1.7 MiB/s ETA:   0 s 
info: downloading component 'rust-docs' 
  4.6 MiB /   4.6 MiB (100 %)   1.8 MiB/s ETA:   0 s 
info: installing component 'rustc' 
info: installing component 'rust-std' 
info: installing component 'cargo' 
info: installing component 'rust-docs' 
info: default toolchain set to 'stable' 
  stable installed - rustc 1.24.1 (d3ae9a9e0 2018-02-27) 
Rust is installed now. Great! 

To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH 
environment variable. Next time you log in this will be done automatically. 
To configure your current shell run source $HOME/.cargo/env 

設置 RUST 環境

$ administrator@administrator:~/dutree$ source $HOME/.cargo/env 
$ administrator@administrator:~/dutree$ rustc --version 
rustc 1.24.1 (d3ae9a9e0 2018-02-27) 
$ administrator@administrator:~/dutree$ cargo install 
  Installing dutree v0.1.0 (file:///home/administrator/dutree) 
    Updating registry `https://github.com/rust-lang/crates.io-index` 
    Updating git repository `https://github.com/eminence/terminal-size.git` 
 Downloading getopts v0.2.15 
 Downloading regex v0.2.10 
 Downloading unicode-width v0.1.4 
 Downloading winapi v0.2.8 
 Downloading kernel32-sys v0.2.2 
 Downloading libc v0.2.39 
 Downloading winapi-build v0.1.1 
 Downloading regex-syntax v0.5.3 
 Downloading aho-corasick v0.6.4 
 Downloading utf8-ranges v1.0.0 
 Downloading thread_local v0.3.5 
 Downloading memchr v2.0.1 
 Downloading ucd-util v0.1.1 
 Downloading unreachable v1.0.0 
 Downloading lazy_static v1.0.0 
 Downloading void v1.0.2 
   Compiling regex v0.2.10 
   Compiling utf8-ranges v1.0.0 
   Compiling getopts v0.2.15 
   Compiling winapi v0.2.8 
   Compiling void v1.0.2 
   Compiling libc v0.2.39 
   Compiling ucd-util v0.1.1 
   Compiling winapi-build v0.1.1 
   Compiling lazy_static v1.0.0 
   Compiling unicode-width v0.1.4 
   Compiling unreachable v1.0.0 
   Compiling regex-syntax v0.5.3 
   Compiling memchr v2.0.1 
   Compiling kernel32-sys v0.2.2 
   Compiling thread_local v0.3.5 
   Compiling aho-corasick v0.6.4 
   Compiling terminal_size v0.1.7 (https://github.com/eminence/terminal-size.git#af31d2b0) 
   Compiling dutree v0.1.0 (file:///home/administrator/dutree) 
    Finished release [optimized] target(s) in 453.67 secs 
Installing /home/administrator/.cargo/bin/dutree 

設置源

source 命令可用於將任何函數文件加載到當前 shell 腳本或命令提示符中,

$ source $HOME/.cargo/env

常規幫助選項,顯示選項列表及其執行的功能,

$ dutree –-help 

Usage: dutree [options] <path> [<path>..] 
Options: 
    -d, --depth [DEPTH] show directories up to depth N (def 1) 
    -a, --aggr [N[KMG]] aggregate smaller than N B/KiB/MiB/GiB (def 1M) 
    -s, --summary       equivalent to -da, or -d1 -a1M 
    -u, --usage         report real disk usage instead of file size 
    -b, --bytes         print sizes in bytes 
    -x, --exclude NAME  exclude matching files or directories 
    -H, --no-hidden     exclude hidden files 
    -A, --ascii         ASCII characters only, no colors 
    -h, --help          show help 
    -v, --version       print version number 

下面都是 example 使用各種選項來展示 dutree 的使用,

例子

深度

深度 目錄的邊數是從文件/目錄到 樹的 根目錄。 根目錄將有一個 深度 of 1. 文件的高度是從目錄到葉子的最長路徑上的邊數。

您可以通過以下方式查看第一個目錄深度,

$ dutree -d1 test/

或想深入查看更多文件,

$ dutree -d2 test/

或看到一切,

$ dutree test/

概括

要快速查看指定目錄,請使用選項 -s。

$ dutree -s test/

您還可以使用 -b 選項以字節為單位查看文件大小,

$ dutree -b test/

如果您想查看不包括特定擴展名或文件名或目錄名的文件,您可以使用 -x 選項,

$ dutree -x dir1 test/

下面你會看到 dir1 從樹中排除,

聚合

您可以聚合某個目錄下的文件或指定某個文件大小以獲得更好的可視化,

$ dutree -a 100b test/

實際磁盤使用情況

在下圖中,您可以看到如何檢查實際磁盤使用情況而不是文件大小。 文件的文件大小不等於磁盤使用量,這是實際使用的磁盤塊數。 小文件通常比我們假設的佔用更多空間,因為一個塊中只會存儲一個小文件。

$ dutree -u test/

比較

您可以比較任意數量的不同文件夾,

ASCII 字符

在下圖中,您會看到如何使用 dutree 指定目錄路徑。 如果您是那種不關心流行顏色或在舊終端中遇到塊字符問題的人,您可以獲得舊純 ASCII 字符的輸出。

$ dutree -A test/

嘗試使用 LS_COLOR 變量為您的環境添加花哨的顏色,並讓我們知道您的意見。