The sys admin's daily grind: ncdu

Bloated Data


I've never heard of an admin having to remove disks from a server because of a chronic lack of data, but full disks are part of the daily grind. The du clone ncdu will help slim down your data.

By Charly Kühnast

I use Nagios to keep track of hard-disk capacity on my server disks. Whenever the successor to NetSaint kindly informs me that the remaining disk capacity on server XY has dropped below the magical threshold of 10%, I may be warned, but the trouble is just starting. If I'm out of luck, the whole data repository could reside on a RAID system without anything in the line of partitioning, and believe me, this is fairly typical for smaller servers.

With a bit more luck, Nagios [1] might tell me that the /var partition is the bottleneck, leaving me to launch du and find out where the disk hogs have their megabytes stashed. Unfortunately, output from the Disk Usage tool for overly complicated directory trees, like the ones I have, is less than intuitive.

Enter NCurses [2], a knight in shining armor with a mission to chop a few heads off the Hydra known as Disk Usage. ncdu [1], by 18-year-old Dutchman Yoran Heling, is a lightweight 91KB tarball, and the normal steps, ./configure && make && make install, will soon have it up and fighting. ncdu gives you an uncluttered view of the current directory (Figure 1), and you can use the arrow keys to navigate the NCurses window.

Figure 1: Ncdu is what du should be - it gives the user hotkeys to navigate directories and to modify the sorting order.

Hotkeys

Once you have it up and running, ncdu will accept a couple of keyboard shortcuts. For example, you can press N to switch to alphabetical sorting - ncdu normally sorts by size. Pressing N twice enables alphabetical sorting in reverse order. At times, directories can seem innocuous because ncdu displays a couple of low-volume subdirectories at the top, but lower down in the tree, and out of sight until you scroll down to them, you might discover the fat DVD images of a dozen Linux distributions. Pressing tells ncdu to sort the objects by size, whether they are files or directories.

If you want to be really sure, you can switch the size display from units of 1000 to units of 1024 by pressing P, although it might be more important to press H to reveal hidden directories. You might be surprised how much space directories hog if you lift the veil.

Conclusions

Now that I have become used to the tool, ncdu has a secure place in my toolbox, and du is definitely out.

For admins who do not like the monochromatic style of ncdu, its author (and black metal fan), Heling, lists some similar but more colorful tools under Similar projects on his website [1]. The similar tools in Heling's list include gt5, which bills itself as a "diff-capable du browser," tdu, which Heling refers to as "another small ncurses-based disk visualization utility," a pair of arboreal GTK tools (Treesize and Baobab), and finally Firelight, which provides "beautiful disk visualization" in KDE. If you ask me, the mysterious overnight proliferation of data is lurid enough without having a diagnostic tool that looks like Las Vegas by night.

INFO
[1] Nagios: http://www.nagios.org/
[2] NCurses: http://www.gnu.org/software/ncurses/
[3] Ncdu: http://dev.yorhel.nl/ncdu/
THE AUTHOR

Charly Kühnast is a Unix System Manager at the data center in Moers, near Germany's famous River Rhine. His tasks include ensuring firewall security and availability and taking care of the DMZ (demilitarized zone).