Fast tools for checking disk utilization
Disk Usage
Three modern tools, gdu, godu, and duf, make the task of checking the utilization level of hard disks easier thanks to fast execution speed and a good graphical implementation.
Hard disks have three states: empty, dead, and full. You can reach a full disk faster than expected due to carelessly hoarded data, much like in a kitchen junk drawer. Error messages logged once a millisecond, such as .xsession-errors
, can also quickly fill up a logfile causing even large hard disks to overflow overnight.
If your disk is filling up, you first need to identify the cause, specifically which directories or files are hogging the most space. Plasma and Gnome have graphical tools such as Filelight, GdMap, or Baobab, which display the utilization level. However, these tools are very slow, making them unsuitable for network servers or full hard disks, because a graphical user interface will often fail to launch if the disk utilization level exceeds 95 percent.
Instead, you need a terminal-based solution. Linux on-board tools, such as du
or df
can show disk utilization, but they are not necessarily renowned for their clarity. For example, you can use the du
command in Listing 1 to display the 20 largest directories in home
but in a pretty awkward way. Another option is ncdu
[1], an Ncurses-based tool available in the archives of all major distributions, which I covered in an earlier issue [2]. While ncdu
does a fantastic job, it lacks speed during indexing.
Listing 1
Checking with Du
$ du -a /home/ | sort -n -r | head -n 20
If you are looking for speed, three lesser-known tools can do the job: gdu
[3], godu
[4], and duf
[5]. These three tools replace the ncdu
tool completely or partially and also do their job at lightning speed. All three owe their speed to the Go programming language in which they are written (ncdu
is written in C). All three tools are optimized for SSD use, which also makes full use of parallel processing. According to the gdu
developer, the performance gain is lower with HDDs but still noticeable.
gdu
Currently the most popular, gdu
can be found in the archives of Debian, Devuan, Manjaro, PureOS, and Raspberry Pi OS. You will also find packages for 32- and 64-bit Linux, ARM, and many BSD variants on gdu
's website. Arch Linux users will find gdu
in the Arch User Repository (AUR).
If you use Snap, you can install gdu
with the command-line call from the first line of Listing 2; the project's GitHub page reveals the further steps. If your distribution does not have gdu
, the tool can also be installed quickly at the command line (lines 2 to 4).
Listing 2
Installing gdu
01 $ sudo snap install gdu-disk-usage-analyzer 02 $ curl -L https://github.com/dundee/gdu/releases/latest/download/gdu_linux_amd64.tgz | tar xz 03 $ chmod +x gdu_linux_amd64 04 $ sudo mv gdu_linux_amd64 /usr/bin/gdu
First launching with gdu -h
lists the startup parameters. gdu -d
shows you all the mounted partitions with their sizes and the used and free space (Figure 1). The -i
parameter excludes directories, and you can view the history log with gdu -l
.
Normally, gdu
runs in interactive mode, which can be switched off for use in scripts with -n
. If you prefer monochrome, -c
disables the colored display. To navigate, you use the arrow keys in gdu
, just like in ncdu
. Pressing Enter or the right arrow key lets you change to the selected directory, while the left arrow key moves you up one directory level again. Pressing Q returns to the terminal.
If you press ?, gdu
lists the available options (Figure 2). Table 1 shows more keyboard shortcuts. If you call gdu
without parameters, it shows the contents of the current working directory. By specifying a path, you can steer gdu
precisely to a location in the filesystem without being in that directory (Figure 3).
Table 1
gdu Keyboard Shortcuts
Key | Function |
---|---|
Up arrow |
Move up in the output |
Down arrow |
Move down in the output |
Right arrow |
Change to selected directory |
Left arrow |
Move one directory level up |
Enter |
Change to selected directory |
A |
Change actual size/occupied space |
C |
Sort by number of contents |
D |
Delete selected file |
J |
Move down in the output |
K |
Move up in the output |
L |
Change to selected directory |
N |
Sort by file name |
Q |
Quit gdu |
R |
Recompute selected element |
S |
Sort by file size |
The only destructive parameter, D, deletes the selected file or directory. As an alternative to the arrow keys, use K to move up and J to move down. L moves you to the selected directory.
Overall, gdu
leans heavily on ncdu
in both appearance and operation, though ncdu
has more options. The biggest difference, however, is in speed. ncdu
took 7.4 seconds to scan a home directory with around 280GB of content on an NVMe disk in the test, while gdu
completed the same task within milliseconds – so quickly that the duration could not be measured with a stopwatch. It would be interesting to compare the two tools on an HDD, but there was no HDD available for the test.
godu
Pursuing the same goal, godu
takes a slightly different approach. The difference lies in the representation: godu
uses Miller columns [6] to allow for more flexible visualization (Figure 4). The columns let you open multiple hierarchy levels at the same time and provide a better overview of where you are in the directory tree.
The easiest way to install godu
on your machine is to download the appropriate archive containing the binary [7], which you then unzip and move to ~/.local/bin/
. If this directory does not already exist, create it, and add it to the path by adding the command in Listing 3 to ~/.bashrc
. A subsequent source ~/.bashrc
activates the change. If you want all users to use godu
, store it in /usr/local/bin/
. Other installation methods include Homebrew or a Golang environment. However, the latter can be tricky for nonexpert users.
Listing 3
Supplementing the Path
export PATH="/home/$USER/.local/bin:$PATH"
Typing godu -h
reveals that godu
provides only one parameter apart from the help and the version information: godu -l
lets you exclude files if they are below a specified size. For example,
godu -l 100 /
scans the entire file tree but only considers files larger than 100MB. gdu
lacks this convenient option. If you do not specify anything else, godu
uses 10MB as the limit for -l
.
If you want to exclude certain directories from the display, enter them in the .goduignore
file in the home directory, which you need to create for this purpose. This can also speed up content scanning, especially if you exclude directories with a large number of small files.
Navigation in godu
also relies on the arrow keys. Up to three levels can be opened side by side. If you move further down the directory tree, the level shown on the left disappears and makes room for a new one on the right (Figure 5). Pressing the space bar lets you select several directories or files for deletion or moving.
To delete or move the selected entries, exit godu
by pressing Q and use
godu -print0 | xargs -0 COMMAND
where COMMAND
is the appropriate command for the desired action. For example, to move previously selected entries, use the command shown in line 1 of Listing 4. To simplify the process, you can create an appropriate alias in .bashrc
(line 2).
Listing 4
Moving Selected Entries
01 $ godu -print0 | xargs -0 -I _ mv _ <I>Ziel<I> 02 $ alias gmv="godu -print0 | xargs -0 -I _ mv _ "
godu
provides a better overview by outputting all previously selected objects for checking in the standard output after exiting. It is worth looking through this list carefully before you let xargs
loose on it.
duf
The third tool, duf
, stands for Disk Usage/Free. It differs from gdu
and godu
both in terms of operation and how it displays the results. duf
is available for Alpine, NixOS, and Void Linux in their respective repositories; on Arch Linux, you will find duf
in the AUR. The developer also offers a variety of binaries on GitHub [8] for various Linux and BSD distributions, macOS, Windows, and ARM. duf
also runs on Android. To try this, enter the command
pkg install duf
in Android's Termux app.
At first glance, entering duf
without any further parameters results in impressive output. Of the three tools, duf
offers the clearest and most detailed view of the mounted devices, distinguishing between local and network devices. As a third category, duf
displays directories mounted in memory via tmpfs
. The -all
parameter expands the display again to include mounted FUSE devices, as well as the pseudo filesystems under /proc
and /sys
(Figure 6).
Entering duf -h
shows more than a dozen other ways to shape the output. duf -hide AREA
lets you hide individual areas, while duf -only AREA
only shows certain areas. The default dark display can be changed to a light theme with duf -theme light
.
You do not navigate with duf
; you just define the mount point view via the options at startup. The output is sorted using the --sort
and --output
parameters, to which you can assign keywords that you will find in the help if needed. For example, duf --sort size
sorts the mount points by size, while duf --output mountpoint
simply lists the mount points without any other information.
duf -json
gives you output that can be further processed with other applications (Figure 7). However, data manipulation is left to gdu
and godu
; duf
does not offer an interactive mode.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.