Skip to content
System

Full disk under Linux: useful commands before deleting anything

Avatar illustré de Julien Macé 4 min read
Tux inquiet devant un disque Linux saturé et des dossiers à nettoyer
Tux inquiet devant un disque Linux saturé et des dossiers à nettoyer

A full disk under Linux often happens at the worst possible time: blocked updates, databases refusing to write, services crashing, SSH connections still open but servers partially paralyzed. The dangerous reflex is to launch a rm -rf on the first major case found.

Before deleting anything, you need to know which partition is fullThis determines what’s actually occupying the space, and whether the problem originates from the files, logs, or sometimes the inodes. Here are the commands I use for proper diagnosis.

Start by identifying the full partition

The first command to run is dfIt shows the space used per file system, not per folder.

df -h

Look especially at the columns Worn% And Mounted on. If / is at 100%, the entire system can be affected. If it is /varThe problem often comes from logs, caches, Docker, a database, or a service that writes too much.

I like to add the file system type when I don’t know the machine:

df -hT

You might also encounter a more subtle case: there’s still space available in GB, but not enough inodes. In this case, many small files can block file creation.

df -i

If the inodes are at 100%, simply searching for large files won’t be enough. You’ll need to find folders containing a huge number of small files.

Find the folders that take up the most space

Once the partition is identified, use of to measure the folders. On a full root directory, I often start with this:

sudo du -xh --max-depth=1 / | sort -h

The option -x avoids traversing other mounted file systems. This is important on a server with separate volumes; otherwise, you risk confusing the diagnostics of /, /home, /mnt Or /var.

If /var It appears as the main folder, go down one level:

sudo du -xh --max-depth=1 /var | sort -h

Then proceed only within the suspect folder. Avoid running random broad scans on a busy server. of can do a lot of disk input/output, especially on large volumes.

Use ncdu if you want to explore faster

ncdu is very handy when you want to explore disk space in a text interface. It scans a folder, then lets you navigate the directory tree without restarting. of at each level.

sudo apt install ncdu
sudo ncdu -x /

On Fedora or a similar distribution:

sudo dnf install ncdu
sudo ncdu -x /

However, be aware: ncdu It can delete files from its interface. I advise you to use it first as a reading tool, then delete manually with a clear command when you are sure of the folder.

Check the systemd logs before touching sensitive folders.

On many modern machines, the newspapers systemd They can take up space, especially after a looping error. Start by measuring their weight:

journalctl --disk-usage

If the volume is clearly too high, you can reduce the history without abruptly deleting the files in /var/log/journal.

sudo journalctl --vacuum-time=14d

Or set a maximum size:

sudo journalctl --vacuum-size=1G

If the logs immediately swell again, cleaning them up isn’t the real solution. You need to identify the service that’s writing in a loop. journalctl -p warning..alert or with the logs of the service in question. If you modify a systemd unit during diagnostics, also keep in mind the difference with systemctl daemon-reload.

Cleaning methods are generally less risky.

There are some areas where cleaning is often safer, provided you understand what you are doing.

  • APT cache on Debian or Ubuntu: sudo apt clean ;
  • old, useless packages: sudo apt autoremove after verification;
  • systemd logs too large: journalctl --vacuum-time Or --vacuum-size ;
  • temporary files of a known application, only if the service can recreate them;
  • Unused Docker images, containers or volumes, if Docker is indeed the cause.

For Docker, do not perform a global purge without checking what is already present. On a production server, a Docker volume may contain application data.

docker system df

The command already gives you an idea before deleting images, stopped containers or volumes.

Time-wasting traps

First pitfall: deleting a large file opened by a process. In this case, the space may not return immediately, because the process still has the file in memory. To check this:

sudo lsof +L1

If you see an old deleted log file that is still open, you will often need to restart or reload the service in question properly.

Second pitfall: confusing a mounted folder with a local folder. If a disk is mounted on /datathe space displayed for /data does not necessarily correspond to the root partition. That’s why df -h must always come first of.

Third trap: deleting in /var/lib Without knowing which application is using the folder. Databases, containers, repositories, queues: this folder could contain critical data. If you’re unsure, back up your data first and check the owning service.

Check after cleaning

After deleting or cleaning, return to the initial settings:

df -h
df -i

If the space hasn’t moved, look for open files with lsof +L1 Or check if you cleaned the wrong partition. If the space returns but fills up again within minutes, the problem is still active: logs looping, backup writing to the wrong place, forgotten export, container too verbose.

The best method remains simple: df to determine which part of the score is affected, of Or ncdu to find the file, then a targeted and understandable deletion. It’s less spectacular than a big rm -rf, but much safer.

To learn more, see the manual pages of df, of And journalctl detail the useful options.

Share Facebook X WhatsApp LinkedIn Pinterest Reddit Email