在Linux和Unix中,查看磁盘使用情况最常用的应用程序是 du 。Du是 d isk u sage的缩写,它被广泛用于查找哪些文件和目录占用了最多的磁盘空间。还有许多其他命令行和图形工具可以完成这项任务。我们已经讨论了其中的一些,并在过去的博客中发表了。今天,我们将介绍另一个名为 duf 的磁盘使用情况查看工具。

Duf是一个命令行实用程序,用于查找Linux和类unix系统中的磁盘使用情况。它以良好的表格列和用户友好的布局显示磁盘使用细节。您甚至可以获得 JSON 格式的磁盘使用情况输出。

如果输出超过了屏幕的可见部分,它会自动调整终端的宽度。您可以按总大小、文件系统类型、使用和空闲空间、挂载点和索引节点对结果进行排序。还可以从输出中显示、隐藏和排除特定的设备细节信息。

Duf是 d isk u sage/ f ree的缩写。它是一个用 Go 编程语言编写的开源应用程序,并在MIT许可下发布。它可以在GNU/Linux、BSD和Mac OS下工作。

目前,Duf已经被打包用于基于arch、基于deb和基于rpm的Linux操作系统。

Duf在 AUR 中被提供。如果您正在使用Arch Linux或任何Arch变体,您可以使用AUR帮助程序安装它,例如 Yay

$ yay -S duf

On DEB-based systems such as Debian, Ubuntu, Linux Mint, download the .deb binary installation file from the releases page and install it using your system's package manager.

在基于deb的系统上,如Debian, Ubuntu, Linux Mint,下载deb二进制安装文件并使用系统的包管理器安装它。

$ sudo apt install gdebi
$ sudo gdebi duf_0.3.1_linux_amd64.deb

在基于rpm的系统(如RHEL、CentOS、Fedora)上,下载rpm二进制文件并使用命令安装它:

$ sudo rpm -Uvh duf_0.3.1_linux_amd64.rpm

我们也可以从源代码来构建它。确保您的系统上已经安装了 GO language 。Git克隆duf源码仓库:

$ git clone https://github.com/muesli/duf.git

上面的命令将在一个名为“duf”的本地目录中克隆duf的在线存储库的内容。进入该目录:

$ cd duf

使用命令编译和安装:

$ go build

使用duf查找磁盘空间使用情况很容易!

你所要做的就是运行 duf 命令且不需要附加任何选项,如下所示:

$ duf

输出示例:

╭──────────────────────────────────────────────────────────────────────────────────────────╮
│ 1 local device │
├────────────┬────────┬────────┬───────┬───────────────────────────────┬──────┬────────────┤
│ MOUNTED ON │ SIZE │ USED │ AVAIL │ USE% │ TYPE │ FILESYSTEM │
├────────────┼────────┼────────┼───────┼───────────────────────────────┼──────┼────────────┤
│ / │ 457.4G │ 412.1G │ 22.1G │ [##################..] 90.1% │ ext4 │ /dev/sda1 │
╰────────────┴────────┴────────┴───────┴───────────────────────────────┴──────┴────────────╯
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 7 special devices │
├────────────────┬────────┬────────┬────────┬───────────────────────────────┬──────────┬────────────┤
│ MOUNTED ON │ SIZE │ USED │ AVAIL │ USE% │ TYPE │ FILESYSTEM │
├────────────────┼────────┼────────┼────────┼───────────────────────────────┼──────────┼────────────┤
│ /dev │ 3.8G │ 0B │ 3.8G │ │ devtmpfs │ udev │
│ /dev/shm │ 3.8G │ 235.3M │ 3.6G │ [#...................] 6.0% │ tmpfs │ tmpfs │
│ /run │ 787.0M │ 1.8M │ 785.2M │ [....................] 0.2% │ tmpfs │ tmpfs │
│ /run/lock │ 5.0M │ 4.0K │ 5.0M │ [....................] 0.1% │ tmpfs │ tmpfs │
│ /run/snapd/ns │ 787.0M │ 1.8M │ 785.2M │ [....................] 0.2% │ tmpfs │ tmpfs │
│ /run/user/1000 │ 787.0M │ 238.2M │ 548.8M │ [######..............] 30.3% │ tmpfs │ tmpfs │
│ /sys/fs/cgroup │ 3.8G │ 0B │ 3.8G │ │ tmpfs │ tmpfs │
╰────────────────┴────────┴────────┴────────┴───────────────────────────────┴──────────┴────────────╯

打开网易新闻 查看更多图片

正如你在上面的输出中看到的,Duf以一种很好的表格列格式列出了以下细节:

  • 总的挂载设备数,

  • 挂载点,

  • 根分区的总大小

  • 使用和空闲磁盘空间的总大小

  • 磁盘使用总量的百分比

  • 文件系统类型

  • 文件系统名称等

要显示所有细节,包括伪文件系统,复制和不可访问的文件系统,运行:

$ duf --all

输出示例:

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 24 local devices │
├────────────────────────────────┬────────┬────────┬───────┬───────────────────────────────┬──────────┬─────────────┤
│ MOUNTED ON │ SIZE │ USED │ AVAIL │ USE% │ TYPE │ FILESYSTEM │
├────────────────────────────────┼────────┼────────┼───────┼───────────────────────────────┼──────────┼─────────────┤
│ / │ 457.4G │ 412.1G │ 22.1G │ [##################..] 90.1% │ ext4 │ /dev/sda1 │
│ /run/snapd/ns/multipass.mnt │ 0B │ 0B │ 0B │ │ nsfs │ nsfs │
│ /snap/bashtop/128 │ 23.1M │ 23.1M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop0 │
│ /snap/bashtop/134 │ 23.1M │ 23.1M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop1 │
│ /snap/chromium/1298 │ 162.1M │ 162.1M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop2 │
│ /snap/chromium/1320 │ 162.0M │ 162.0M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop3 │
│ /snap/core/9804 │ 96.6M │ 96.6M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop4 │
│ /snap/core/9993 │ 97.1M │ 97.1M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop6 │
│ /snap/core18/1880 │ 55.0M │ 55.0M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop15 │
│ /snap/core18/1885 │ 55.4M │ 55.4M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop5 │
│ /snap/gifcurry/8 │ 149.0M │ 149.0M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop7 │
│ /snap/gnome-3-26-1604/100 │ 140.8M │ 140.8M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop16 │
│ /snap/gnome-3-26-1604/98 │ 140.8M │ 140.8M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop8 │
│ /snap/gnome-3-28-1804/116 │ 160.2M │ 160.2M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop14 │
│ /snap/gnome-3-28-1804/128 │ 161.5M │ 161.5M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop10 │
│ /snap/gnome-3-34-1804/33 │ 255.6M │ 255.6M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop9 │
│ /snap/gnome-3-34-1804/36 │ 255.6M │ 255.6M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop11 │
│ /snap/gnome-system-monitor/145 │ 2.2M │ 2.2M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop17 │
│ /snap/gnome-system-monitor/148 │ 2.2M │ 2.2M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop18 │
│ /snap/gtk-common-themes/1502 │ 54.9M │ 54.9M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop12 │
│ /snap/gtk-common-themes/1506 │ 62.1M │ 62.1M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop13 │
│ /snap/multipass/2531 │ 220.0M │ 220.0M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop19 │
│ /snap/multipass/2604 │ 220.0M │ 220.0M │ 0B │ [####################] 100.0% │ squashfs │ /dev/loop20 │
│ /sys/fs/fuse/connections │ 0B │ 0B │ 0B │ │ fusectl │ fusectl │
╰────────────────────────────────┴────────┴────────┴───────┴───────────────────────────────┴──────────┴─────────────╯
╭─────────────────────────────────────────────────────────────────────────────────╮
│ 1 FUSE device │
├─────────────────────┬──────┬──────┬───────┬──────┬─────────────────┬────────────┤
│ MOUNTED ON │ SIZE │ USED │ AVAIL │ USE% │ TYPE │ FILESYSTEM │
├─────────────────────┼──────┼──────┼───────┼──────┼─────────────────┼────────────┤
│ /run/user/1000/gvfs │ 0B │ 0B │ 0B │ │ fuse.gvfsd-fuse │ gvfsd-fuse │
╰─────────────────────┴──────┴──────┴───────┴──────┴─────────────────┴────────────╯
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 32 special devices │
├─────────────────────────────────┬────────┬────────┬────────┬───────────────────────────────┬─────────────┬─────────────┤
│ MOUNTED ON │ SIZE │ USED │ AVAIL │ USE% │ TYPE │ FILESYSTEM │
├─────────────────────────────────┼────────┼────────┼────────┼───────────────────────────────┼─────────────┼─────────────┤
│ /dev │ 3.8G │ 0B │ 3.8G │ │ devtmpfs │ udev │
│ /dev/hugepages │ 0B │ 0B │ 0B │ │ hugetlbfs │ hugetlbfs │
│ /dev/mqueue │ 0B │ 0B │ 0B │ │ mqueue │ mqueue │
│ /dev/pts │ 0B │ 0B │ 0B │ │ devpts │ devpts │
│ /dev/shm │ 3.8G │ 224.1M │ 3.6G │ [#...................] 5.7% │ tmpfs │ tmpfs │
│ /proc │ 0B │ 0B │ 0B │ │ proc │ proc │
│ /proc/sys/fs/binfmt_misc │ 0B │ 0B │ 0B │ │ binfmt_misc │ binfmt_misc │
│ /run │ 787.0M │ 1.8M │ 785.2M │ [....................] 0.2% │ tmpfs │ tmpfs │
│ /run/lock │ 5.0M │ 4.0K │ 5.0M │ [....................] 0.1% │ tmpfs │ tmpfs │
│ /run/snapd/ns │ 787.0M │ 1.8M │ 785.2M │ [....................] 0.2% │ tmpfs │ tmpfs │
│ /run/user/1000 │ 787.0M │ 238.2M │ 548.8M │ [######..............] 30.3% │ tmpfs │ tmpfs │
│ /sys │ 0B │ 0B │ 0B │ │ sysfs │ sysfs │
│ /sys/fs/bpf │ 0B │ 0B │ 0B │ │ bpf │ none │
│ /sys/fs/cgroup │ 3.8G │ 0B │ 3.8G │ │ tmpfs │ tmpfs │
│ /sys/fs/cgroup/blkio │ 0B │ 0B │ 0B │ │ cgroup │ cgroup │
│ /sys/fs/cgroup/cpu,cpuacct │ 0B │ 0B │ 0B │ │ cgroup │ cgroup │
│ /sys/fs/cgroup/cpuset │ 0B │ 0B │ 0B │ │ cgroup │ cgroup │
│ /sys/fs/cgroup/devices │ 0B │ 0B │ 0B │ │ cgroup │ cgroup │
│ /sys/fs/cgroup/freezer │ 0B │ 0B │ 0B │ │ cgroup │ cgroup │
│ /sys/fs/cgroup/hugetlb │ 0B │ 0B │ 0B │ │ cgroup │ cgroup │
│ /sys/fs/cgroup/memory │ 0B │ 0B │ 0B │ │ cgroup │ cgroup │
│ /sys/fs/cgroup/net_cls,net_prio │ 0B │ 0B │ 0B │ │ cgroup │ cgroup │
│ /sys/fs/cgroup/perf_event │ 0B │ 0B │ 0B │ │ cgroup │ cgroup │
│ /sys/fs/cgroup/pids │ 0B │ 0B │ 0B │ │ cgroup │ cgroup │
│ /sys/fs/cgroup/rdma │ 0B │ 0B │ 0B │ │ cgroup │ cgroup │
│ /sys/fs/cgroup/systemd │ 0B │ 0B │ 0B │ │ cgroup │ cgroup │
│ /sys/fs/cgroup/unified │ 0B │ 0B │ 0B │ │ cgroup2 │ cgroup2 │
│ /sys/fs/pstore │ 0B │ 0B │ 0B │ │ pstore │ pstore │
│ /sys/kernel/config │ 0B │ 0B │ 0B │ │ configfs │ configfs │
│ /sys/kernel/debug │ 0B │ 0B │ 0B │ │ debugfs │ debugfs │
│ /sys/kernel/security │ 0B │ 0B │ 0B │ │ securityfs │ securityfs │
│ /sys/kernel/tracing │ 0B │ 0B │ 0B │ │ tracefs │ tracefs │
╰─────────────────────────────────┴────────┴────────┴────────┴───────────────────────────────┴─────────────┴─────────────╯

有时,您可能希望从输出中排除一些细节。例如,下面的命令将排除特殊设备的详细信息(比如/run/lock, /sys/fs/bpf)。

$ duf --hide-special

这将只显示本地设备的磁盘使用细节,即从输出中删除特殊设备:

╭──────────────────────────────────────────────────────────────────────────────────────────╮
│ 1 local device │
├────────────┬────────┬────────┬───────┬───────────────────────────────┬──────┬────────────┤
│ MOUNTED ON │ SIZE │ USED │ AVAIL │ USE% │ TYPE │ FILESYSTEM │
├────────────┼────────┼────────┼───────┼───────────────────────────────┼──────┼────────────┤
│ / │ 457.4G │ 412.0G │ 22.1G │ [##################..] 90.1% │ ext4 │ /dev/sda1 │
╰────────────┴────────┴────────┴───────┴───────────────────────────────┴──────┴────────────╯

其他支持的选项有:

  • --hide-local

  • --hide-network

  • --hide-fuse

  • --hide-loops

  • --hide-binds

对输出进行排序

我们可以根据各种参数来对磁盘使用情况的信息进行排序,如:

  • mountpoint,

  • size,

  • used,

  • avail,

  • usage,

  • inodes,

  • inodes_used,

  • inodes_avail,

  • inodes_usage,

  • type,

  • filesystem etc.

例如,要按大小对输出进行排序,可以使用以下命令:

$ duf --sort size

按文件系统排序输出:

$ duf --sort filesystem

显示或隐藏特定列

与从输出中排除某些设备细节类似,我们还可以从输出中显示或隐藏特定的列。

下面的命令将只显示 mountpointsizeusage 列的输出:

$ duf --output mountpoint,size,usage

输出示例:

╭─────────────────────────────────────────────────────╮
│ 1 local device │
├────────────┬────────┬───────────────────────────────┤
│ MOUNTED ON │ SIZE │ USE% │
├────────────┼────────┼───────────────────────────────┤
│ / │ 457.4G │ [##################..] 90.1% │
╰────────────┴────────┴───────────────────────────────╯
╭─────────────────────────────────────────────────────────╮
│ 7 special devices │
├────────────────┬────────┬───────────────────────────────┤
│ MOUNTED ON │ SIZE │ USE% │
├────────────────┼────────┼───────────────────────────────┤
│ /dev │ 3.8G │ │
│ /dev/shm │ 3.8G │ [#...................] 6.9% │
│ /run │ 787.0M │ [....................] 0.2% │
│ /run/lock │ 5.0M │ [....................] 0.1% │
│ /run/snapd/ns │ 787.0M │ [....................] 0.2% │
│ /run/user/1000 │ 787.0M │ [######..............] 30.3% │
│ /sys/fs/cgroup │ 3.8G │ │
╰────────────────┴────────┴───────────────────────────────╯

支持的选项列表是:

  • mountpoint ,

  • size ,

  • used ,

  • avail ,

  • usage ,

  • inodes ,

  • inodes_used ,

  • inodes_avail ,

  • inodes_usage ,

  • type ,

  • filesystem .

显示inode详细信息

如果你想列出inode信息而不是块的使用情况,运行这个命令:

$ duf --inodes

显示JSON格式的磁盘使用输出

我们可以使用JSON格式显示输出,而不是使用表格列格式显示输出。

为此,请运行:

$ duf --json

输出示例:

[
{
"device": "sysfs",
"device_type": "special",
"mount_point": "/sys",
"fs_type": "sysfs",
"type": "sysfs",
"opts": "rw,nosuid,nodev,noexec,relatime",
"total": 0,
"free": 0,
"used": 0,
"inodes": 0,
"inodes_free": 0,
"inodes_used": 0,
"blocks": 0,
"block_size": 4096
},
.
.
.
{
"device": "binfmt_misc",
"device_type": "special",
"mount_point": "/proc/sys/fs/binfmt_misc",
"fs_type": "binfmt_misc",
"type": "binfmt_misc",
"opts": "rw,nosuid,nodev,noexec,relatime",
"total": 0,
"free": 0,
"used": 0,
"inodes": 0,
"inodes_free": 0,
"inodes_used": 0,
"blocks": 0,
"block_size": 4096
}
]

获取帮助

要显示duf实用程序的帮助文档,请运行:

$ duf --help

输出示例:

Usage of duf:
-all
include pseudo, duplicate, inaccessible file systems
-hide-binds
hide bind mounts (default true)
-hide-fuse
hide fuse devices
-hide-local
hide local devices
-hide-loops
hide loop devices (default true)
-hide-network
hide network devices
-hide-special
hide special devices
-inodes
list inode information instead of block usage
-json
output all devices in JSON format
-output string
output fields: mountpoint, size, used, avail, usage, inodes, inodes_used, inodes_avail, inodes_usage, type, filesystem
-sort string
sort output by: mountpoint, size, used, avail, usage, inodes, inodes_used, inodes_avail, inodes_usage, type, filesystem (default "mountpoint")
-width uint
max output width

使用Warpinator在Linux桌面之间共享文件

2020年Linux最佳图形设计软件

在Linux中使用Bashtop与Bpytop监管系统资源

Structflow结构处理能力汇总(干货)

OpenCV 强大的开源计算机视觉库

DuMux: 基于Dune的多孔介质流体输运研究工具

10种在Linux上分析二进制文件的方法

KiCad: 一款跨平台开源电子设计自动化套件

打开网易新闻 查看更多图片