1. 介绍
官网地址:https://github.com/chenquan/diskusage/blob/master/README-CN.md
diskusage:一个显示磁盘使用情况的工具。(Linux、MacOS 和 Windows)
2. 安装
[root@k8s-node01 ~]# wget https://github.com/chenquan/diskusage/releases/download/v1.1.4/diskusage-v1.1.4-linux-amd64.tar.gz
[root@k8s-node01 ~]# ll
-rw------- 1 root root 2749766 5月 10 13:42 diskusage-v1.1.4-linux-amd64.tar.gz
[root@k8s-node01 ~]# tar xf diskusage-v1.1.4-linux-amd64.tar.gz -C /usr/locl/bin
3. 使用
3.1 参数
[root@k8s-node01 ~]# diskusage -h
A tool for showing disk usage.
GitHub: https://github.com/chenquan/diskusage
Issues: https://github.com/chenquan/diskusage/issues
Usage:
diskusage [flags]
Examples:
1.The maximum display unit is GB: diskusage -u G
2.Only files named doc or docx are counted:
a.diskusage -t doc,docx
b.diskusage -f ".+\.(doc|docx)$"
3.Supports color output to pipeline:
a.diskusage -c always | less -R
b.diskusage -c always | more
4.Displays a 2-level tree structure: diskusage -d 2
5.Specify the directory /usr: diskusage --dir /usr
6.Export disk usage to file: diskusage > diskusage.txt
Flags:
-a, --all display all directories, otherwise only display folders whose usage size is not 0
-c, --color string set color output mode. optional: auto, always, ignore (default "auto")
-d, --depth int shows the depth of the tree directory structure (default 1)
--dir string directory path (default "./")
-D, --directory only display directory
-f, --filter string regular expressions are used to filter files
-h, --help help for diskusage
-l, --limit int limit the number of files and directories displayed (default 9223372036854775807)
-r, --recursion automatically calculate directory depth, for recursively traversing all sub directories
-t, --type strings only count certain types of files (default all)
-u, --unit string displayed units. optional: B(Bytes), K(KB), M(MB), G(GB), T(TB) (default "M")
-v, --version version for diskusage
-w, --worker int number of workers searching the directory (default 32)
3.2 使用演示
3.2.1 统计指定目录下的所有文件
# 两种方式
## 方式1:指定目录
[root@k8s-node01 ~]# diskusage --dir /
Total: 5910.655M /
-----------------------------
2506.2M 42.4% ┌─ usr
1361.6M 23.0% ├─ data
876.6M 14.8% ├─ var
554.9M 9.4% ├─ run
352.4M 6.0% ├─ sys
162.6M 2.8% ├─ boot
68.3M 1.2% ├─ root
28.1M 0.5% ├─ etc
1.4K 0.0% ├─ dev
37.0B 0.0% ├─ tmp
9.0B 0.0% ├─ lib64
8.0B 0.0% ├─ sbin
7.0B 0.0% ├─ lib
7.0B 0.0% ├─ bin
0.0B 0.0% └─ .autorelabel
## 方式2:cd到指定目录
[root@k8s-node01 ~]# cd /
[root@k8s-node01 /]# diskusage
Total: 5910.658M /
-----------------------------
2506.2M 42.4% ┌─ usr
1361.6M 23.0% ├─ data
876.6M 14.8% ├─ var
554.9M 9.4% ├─ run
352.4M 6.0% ├─ sys
162.6M 2.8% ├─ boot
68.3M 1.2% ├─ root
28.1M 0.5% ├─ etc
1.4K 0.0% ├─ dev
37.0B 0.0% ├─ tmp
9.0B 0.0% ├─ lib64
8.0B 0.0% ├─ sbin
7.0B 0.0% ├─ lib
7.0B 0.0% ├─ bin
0.0B 0.0% └─ .autorelabel
3.2.2 GB级别显示
[root@k8s-node01 ~]# diskusage --dir / -u G
Total: 5.772G /
--------------------------
2.4G 42.4% ┌─ usr
1.3G 23.0% ├─ data
0.9G 14.8% ├─ var
0.5G 9.4% ├─ run
0.3G 6.0% ├─ sys
0.2G 2.8% ├─ boot
68.3M 1.2% ├─ root
28.1M 0.5% ├─ etc
1.4K 0.0% ├─ dev
37.0B 0.0% ├─ tmp
9.0B 0.0% ├─ lib64
8.0B 0.0% ├─ sbin
7.0B 0.0% ├─ lib
7.0B 0.0% ├─ bin
0.0B 0.0% └─ .autorelabel