使用 gdu 进行更快的磁盘使用情况检查
磁盘 du df
![](/data/attachment/album/202103/24/233818dkfvi4fviiysn8o9.jpg)


在 Linux 终端中有两种常用的 [检查磁盘使用情况的方法](https://linuxhandbook.com/df-command/)：`du` 命令和 `df` 命令。[du 命令更多的是用来检查目录的使用空间](https://linuxhandbook.com/find-directory-size-du-command/)，`df` 命令则是提供文件系统级别的磁盘使用情况。


还有更友好的 [用 GNOME “磁盘” 等图形工具在 Linux 中查看磁盘使用情况的方法](https://itsfoss.com/check-free-disk-space-linux/)。如果局限于终端，你可以使用像 [ncdu](https://dev.yorhel.nl/ncdu) 这样的 [TUI](https://itsfoss.com/gui-cli-tui/) 工具，以一种图形化的方式获取磁盘使用信息。


### gdu: 在 Linux 终端中检查磁盘使用情况


[gdu](https://github.com/dundee/gdu) 就是这样一个用 Go 编写的工具（因此是 gdu 中的 “g”）。gdu 开发者的 [基准测试](https://github.com/dundee/gdu#benchmarks) 表明，它的磁盘使用情况检查速度相当快，特别是在 SSD 上。事实上，gdu 主要是针对 SSD 的，尽管它也可以在 HDD 上工作。


如果你在使用 `gdu` 命令时没有使用任何选项，它就会显示你当前所在目录的磁盘使用情况。


![](/data/attachment/album/202103/24/233827bsoqzsu7onk8jb3b.png)


由于它具有文本用户界面（TUI），你可以使用箭头浏览目录和磁盘。你也可以按文件名或大小对结果进行排序。


你可以用它做到：


* 向上箭头或 `k` 键将光标向上移动
* 向下箭头或 `j` 键将光标向下移动
* 回车选择目录/设备
* 左箭头或 `h` 键转到上级目录
* 使用 `d` 键删除所选文件或目录
* 使用 `n` 键按名称排序
* 使用 `s` 键按大小排序
* 使用 `c` 键按项目排序


你会注意到一些条目前的一些符号。这些符号有特定的意义。


![](/data/attachment/album/202103/24/233829jd2z8826u9e9ad4i.png)


* `!` 表示读取目录时发生错误。
* `.` 表示在读取子目录时发生错误，大小可能不正确。
* `@` 表示文件是一个符号链接或套接字。
* `H` 表示文件已经被计数（硬链接）。
* `e` 表示目录为空。


要查看所有挂载磁盘的磁盘利用率和可用空间，使用选项 `d`：



```
gdu -d

```

它在一屏中显示所有的细节：


![](/data/attachment/album/202103/24/233830f9mkzjz6ymm9bfj9.png)


看起来是个方便的工具，对吧？让我们看看如何在你的 Linux 系统上安装它。


### 在 Linux 上安装 gdu


gdu 是通过 [AUR](https://itsfoss.com/aur-arch-linux/) 提供给 Arch 和 Manjaro 用户的。我想，作为一个 Arch 用户，你应该知道如何使用 AUR。


它包含在即将到来的 Ubuntu 21.04 的 universe 仓库中，但有可能你现在还没有使用它。这种情况下，你可以使用 Snap 安装它，这可能看起来有很多条 `snap` 命令：



```
snap install gdu-disk-usage-analyzer
snap connect gdu-disk-usage-analyzer:mount-observe :mount-observe
snap connect gdu-disk-usage-analyzer:system-backup :system-backup
snap alias gdu-disk-usage-analyzer.gdu gdu

```

你也可以在其发布页面找到源代码：


* [下载 gdu 的源代码](https://github.com/dundee/gdu/releases)


我更习惯于使用 `du` 和 `df` 命令，但我觉得一些 Linux 用户可能会喜欢 gdu。你是其中之一吗？




---


via: <https://itsfoss.com/gdu/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

There are two popular [ways to check disk usage in Linux terminal](https://linuxhandbook.com/df-command/?ref=itsfoss.com): du command and df command.

The [du command is more for checking the space used by a directory](https://linuxhandbook.com/find-directory-size-du-command/?ref=itsfoss.com) and the df command gives you the disk utilization on filesystem level.

The gdu tool sorts of combined the functionality of both.

You can use it to check the size of directories as well as disk utilization. The built in sorting feature makes it easier to use as you don't need to combine the sort command here.

## Gdu: Disk usage checking in Linux terminal

[Gdu](https://github.com/dundee/gdu?ref=itsfoss.com) is a tool written in Go (hence the ‘g’ in gdu). Gdu developer has [benchmark tests](https://github.com/dundee/gdu?ref=itsfoss.com#benchmarks) to show that it is quite fast for disk usage checking, specifically on SSDs. In fact, gdu is intended primarily for SSDs though it can work for HDD as well.

If you use the gdu command without any options, it shows the disk usage for the current directory you are in.

Since it has a terminal user interface (TUI), you can navigate through directories and disk using arrows. You can also sort the result by file names or size.

Here’s how to do that:

- Use the Up arrow or
**k**to move the cursor up. Similarly, use the down arrow or**j**to move the cursor down - Enter to select directory / device
- Left arrow or
**h**to go to parent directory

- Use
**d**to delete the selected file or directory

- Use
**n**to sort by name and use**s**to sort by size.

- Use
**c**to sort by items

You’ll notice some symbols before some file entries. Those have specific meaning.

![Gdu entry symbols](https://itsfoss.com/content/images/wordpress/2021/03/gdu-entry-symbols-800x302.png)

`!`

means an error occurred while reading the directory.`.`

means an error occurred while reading a subdirectory, size may not be correct.`@`

means file is a symlink or socket.`H`

means the file was already counted (hard link).`e`

means directory is empty.

To see the disk utilization and free space for all mounted disks, use the option `d`

:

```
gdu -d
```


It shows all the details in one screen:

Sounds like a handy tool, right?

## More Gdu options for Disk Usage Analysis

Here are some more options, that you can use with Gdu.

Command | Usage |
---|---|

gdu -H | Ignore Hidden Directories |

gdu -i /sys,/proc / | Ignore the specified directories and do gdu on root dorectory |

gdu -d | Show all mounted disks |

gdu -n | Run in a non-interactive mode |


## Installing gdu on Linux

Interested in trying gdu. Here are a few ways of installing it.

### From Official Repositories

Gdu is available in the repositories of Ubuntu, Debian, Arch Linux etc. In Debian/Ubuntu, you can install it [using the apt command](https://itsfoss.com/apt-command-guide/).

So, open a terminal and run:

```
sudo apt update
sudo apt install gdu
```


If you are an Arch Linux user, you can install it [using the pacman command](https://itsfoss.com/pacman-command/).

```
sudo pacman -Syu gdu
```


### Alternatively, install gdu using the official binary

Gdu provides a binary, which you can download and use. First, make sure you have [curl installed](https://itsfoss.com/install-curl-ubuntu/).

`sudo apt install curl`


Then, download the file and extract it using the commands below:

```
curl -L https://github.com/dundee/gdu/releases/latest/download/gdu_linux_amd64.tgz | tar xz
```


Now, give it execution permission and move the binary file [somewhere that is in the path](https://itsfoss.com/add-directory-to-path-linux/). You can do it by:

```
chmod +x gdu_linux_amd64
mv gdu_linux_amd64 /usr/bin/gdu
```


## Wrapping Up

There are more friendly [ways to see the disk usage in Linux with graphical tools like GNOME Disks](https://itsfoss.com/check-free-disk-space-linux/). If you are confined to the terminal, you can use a [TUI](https://itsfoss.com/gui-cli-tui/) tool like [ncdu](https://dev.yorhel.nl/ncdu?ref=itsfoss.com) to get the disk usage information with a sort of graphical touch. Gdu is one such entry to this list.

Gdu is a neat tool, that does not come with overwhelming options. It provides some necessary functions with speed in mind. It's something you can add to your toolbox.