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
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.