Marcio Cunha

Linux disk full? How to free space with ncdu

Learn how to quickly audit inodes, directory bloat caused by container logs, and orphaned packages on production servers using ncdu and the command line.

Marcio Cunha•5 min
Also available in:PortuguêsEspañol
Summary
  • The df command shows general disk usage, but ncdu visually maps which folders consume all storage space.
  • Exhausted inodes prevent creating new files even with free disk space, requiring quick audits via ncdu and find.
  • Docker containers generate heavy logs that bloat system directories and demand periodic cleanup to avoid failures.
  • Orphaned packages and package manager caches accumulate invisible gigabytes that can be safely removed.
  • Preventive audits on production servers prevent unexpected service outages caused by storage shortages.

Why does your Linux server disk suddenly fill up?

When a production server hits 100% storage usage, critical applications crash, databases corrupt transactions, and administrators panic. In practice, this means the operating system loses the ability to write temporary files, audit logs, and user sessions. Knowing exactly where the space went is the difference between a quick maintenance task and an entire night of downtime. Discovering storage culprits requires going beyond the traditional df command, which only reports the big picture, and diving into visual tools focused on directory hierarchy.

In corporate environments and dedicated servers, disk bloat is usually silent. Application logs that never rotated, old container images, and leftover packages from past updates pile up in hidden folders. For infrastructure managers, manual inspection with the classic du -sh * becomes unfeasible and extremely slow on large volumes. This is where the ncdu utility shines as the Swiss Army knife for system administrators, offering an interactive text-based interface right in the terminal.

What is ncdu and why does it outperform traditional du?

NCurses Disk Usage (ncdu) is a disk usage analyzer designed to run in command-line environments. In practice, it scans the file system's directory structure and displays results in an organized hierarchical list, allowing you to navigate folders using keyboard arrow keys. While the standard du command dumps hundreds of lines of cluttered text onto the screen, ncdu sorts everything from largest to smallest space consumer, enabling immediate decision-making.

Another critical advantage in production servers is scanning speed and the ability to export results for later or comparative analysis. Unlike heavy graphical interfaces that require X11 connections or complex web panels, ncdu consumes minimal CPU and memory resources. This ensures its execution does not degrade server performance while you investigate a storage emergency. Furthermore, if you have ever faced disk space exhaustion caused by Docker containers, ncdu lets you quickly spot which Docker daemon folder is eating up precious gigabytes.

How to install and run ncdu on your Linux server

Installing ncdu is quick on the vast majority of modern Linux distributions, as it is included in official package repositories. In practice, you can install it with a single command using your operating system's standard package manager, whether it is Debian, Ubuntu, CentOS, or Fedora. To ensure the scan covers the entire file system without access permission restrictions, it is essential to run it with administrative privileges using sudo.

To put the tool into action in your production environment, follow the steps below in the terminal:

  1. Install ncdu on Debian or Ubuntu by running the update and installation command:
    sudo apt update && sudo apt install ncdu -y
  2. Start the full root system scan from the root directory with elevated permissions:
    sudo ncdu /
  3. Navigate through folders using the up and down arrow keys, press d to delete an unwanted file or directory, and q to exit the interface.

Quick inode audits: when the disk says it has space but is full

One of the most frustrating riddles for Linux administrators is receiving a "no space left on device" error when trying to save a file, even when the df -h command indicates gigabytes of free space. In practice, this happens because the operating system has exhausted its inodes (internal data structures that store metadata for each file, such as permissions and location). Each file, directory, or symbolic link consumes exactly one inode, regardless of its physical size.

When an application generates millions of tiny files—such as expired web sessions, spool mail queues, or temporary cache files—the file system's inode limit is reached long before disk space runs out. To diagnose this situation with surgical precision, you should run the df -i command, which displays inode occupancy rates instead of data blocks. If the usage column hits 100%, you will need to locate directories with a high volume of small files using tools like ncdu or a scan with the find command.

Identifying and cleaning container logs and orphaned packages

Modern servers running containerized workloads frequently struggle with the uncontrolled growth of log files generated by the container engine. Although tools like ncdu help map these bloated directories—often located under /var/lib/docker—it is essential to establish structured maintenance policies. For those managing complex environments, it is worth checking additional strategies for managing container logs with logrotate on Linux to automate cleanup and avoid unwanted surprises during peak hours.

Another invisible space drain on Linux servers consists of orphaned packages and cache files accumulated by package managers over months of updates and builds. When you remove a program, automatically installed dependencies that are no longer needed continue to occupy precious disk space. In the Debian/Ubuntu ecosystem, the command sudo apt autoremove --purge removes orphaned packages and residual configuration files. Likewise, cleaning the manager cache with sudo apt clean immediately frees gigabytes of old locally stored installers (.deb). To explore these architectural concepts further in production, see our related technical analysis on How to test quartz crystal oscillator with oscilloscope.

Final thoughts on storage auditing and prevention

Maintaining storage health on Linux servers goes far beyond deleting files manually when a disk full alert triggers. Adopting efficient tools like ncdu turns a reactive, stressful task into a surgical process of rapid and secure auditing. Understanding inode behavior, monitoring log volumes, and regularly purging orphaned packages guarantee the operational stability of your infrastructure.

To safeguard your servers against future outages, the ideal approach is to integrate automated space and inode monitoring routines into your alerting system. By combining best cleaning practices with visual inspection tools, you protect your applications against catastrophic failures and keep the production environment running at maximum efficiency.