- Monitoring disk usage with `df` and `du` allows you to quickly locate the partitions and directories that consume the most space. Linux.
- Commandos Commands like apt-get autoremove, clean, and clearing caches and thumbnails free up gigabytes on Ubuntu, Linux Mint, and server systems.
- Managing legacy kernels, logsBackups and Snap versions prevent the system from filling up again and improve server stability.
- Overwriting free space with dd or similar tools increases security by making it harder to recover deleted files.

Over time, Any Linux installation eventually accumulates junk.Unused packages, old kernels, expired thumbnails, endless logs, old backups… and before you know it, the “low disk space” warning pops up just when you need it most. It doesn't matter if you're using Ubuntu, Linux Mint, a Plesk server, or an external drive: if you don't take care of it, it fills up.
The good news is that Freeing up disk space in Linux is much easier than it seems If you know where to look and what you can safely delete. In this guide, we'll gather, organize, and expand upon all the techniques found on top-ranking websites for this topic, and integrate them into a single, practical article, in Spanish (Spain), designed for both desktop computers and servers.
1. How to check free space in Linux
Before deleting anything, it is advisable to know exactly how much space you have occupied and whyIn Linux you can do this using either commands or graphical tools, depending on your preference. terminal or the desktop environment.
1.1. Using the graphical disk analysis tool (Ubuntu and derivatives)
On desktops like Ubuntu, Linux Mint, or elementary OS, you have a graphical disk usage analyzer (For example, “Disk Usage Analyzer”). You search for it in the applications menu, open it, and you'll see a graph showing the used and free space, as well as a breakdown by folder.
This type of tool allows you detect at a glance the routes that take up the most space (for example, /var, the home folder, etc.), something very useful if you don't want to struggle with the input terminal.
1.2. Check disk usage with df -h
The basic command to see how much space is available on each file system is df -hRun the following in the terminal:
df -h
With option -h You'll see the "human" sizes (K, M, L) and be able to locate them instantly. Which partition is at 90-100%If your root partition “/” or the mount point of an external disk appears almost full, it's time to clean up.
1.3. Find out which directories take up the most space with du
Once the problematic partition has been located, the next step is find out which folders are responsible for the messThat's what the command is used for. du, which shows how much space each route occupies.
For example, to see the size of the root system directories:
cd /
sudo du -sh *
The option -s summarized by directory and -h It displays legible sizes. That way you'll see lines like 4.0G /var, 15G /homeetc., which tells you where to continue investigatingIt is very common for the "black hole" to be in /var (logs, databases, backups) or in your user folder.
If you want to analyze a specific route, for example /var, you can use:
sudo du -sh /var/*
This way you go down levels until you find the specific directory that is eating up the space (for example, /var/log, /var/lib/mysql, /var/lib/psa/dumps on Plesk servers, etc.).
2. Clean up orphaned packages and dependencies that are no longer needed
On Debian/Ubuntu-based systems (Ubuntu, Linux Mint, many desktop and server distributions) the APT package manager It accumulates dependencies that are no longer needed.These are called orphan packages: they were installed because another package requested them, but that package is no longer available.
To delete all of that at once, simply use apt-get autoremove:
sudo apt-get autoremove
The system will show you the list of packages to remove and the space that will be freed up before requesting confirmation. In some real-world cases, only this command has managed to release several gigabytes (for example, 9 GB between old kernels and obsolete libraries).
Among the packages that usually appear you will see many linux-image-*, linux-headers-* and their corresponding modules, which are old kernels that you no longer use because you are booting with newer versions.
2.1. Remove software you no longer use
Besides orphaned dependencies, we all end up installing programs we tried once and never used againGames, editors, utilities, etc. Each one takes up its own space, and together they can fill your SSD without you noticing.
You can uninstall apps from the Software Center or with the terminal. For example:
sudo apt-get remove nombre-paquete1 nombre-paquete2
If you also want to clean up your configuration files, you can use purge instead of remove, so that You free up some more space and leave less of a trace in the system.
2.2. Clean up configuration files of deleted packages
APT has a habit of retain configuration files for packages you have already uninstalledThey don't usually take up as much space as a kernel, but if you've had the same installation for years, they can add up.
There is a common recipe that combines dpkg y gooseberry to erase all those traces marked with the status “rc” at once:
sudo dpkg --purge `COLUMNS=300 dpkg -l | egrep "^rc" | cut -d' ' -f3`
This command removes configurations associated with packages that have already been uninstalled, achieving a somewhat cleaner system and, in some cases, a few extra megabytes free..
3. Clean APT caches and other components
Another source of waste is... download caches and thumbnails which the system saves to speed things up. The problem is that they rarely clear themselves.
3.1. APT cache: autoclean and clean
APT stores in /var/cache/apt/archives all the .deb packages you downloadThis includes both current versions and older versions you no longer need. To see how much space they take up:
sudo du -sh /var/cache/apt
In various cases, caches have been seen 150 MB, 350 MB or morewhich, when you're short on space, can make all the difference.
You have two cleaning options:
- Remove only obsolete packages (those that can no longer be downloaded because there are newer versions):
sudo apt-get autoclean - Clear all APT cache (more space will be freed up, at the cost of having to download everything again in future installations):
sudo apt-get clean
Many users combine them regularly sudo apt-get autoremove y sudo apt-get clean to keep the system fairly clear without effort.
3.2. Image Thumbnail Cache
File explorers on desktops like Ubuntu or Linux Mint generate thumbnails of your photos, videos, and documents to display attractive icons when browsing through folders. These thumbnails are saved in ~/.cache/thumbnails.
With ThereThat folder can grow to hundreds of megabytes (153 MB, 300 MB, etc.), including thumbnails of files that no longer exist. To see how much space it occupies:
du -sh ~/.cache/thumbnails
And to clear the entire thumbnail cache:
rm -rf ~/.cache/thumbnails/*
The system will regenerate thumbnails when needed, so It's okay to empty it every now and then.It is a simple and relatively safe cleaning process.
4. Manage legacy kernels and system kernels
In many Ubuntu and derivative installations, especially if updated frequently, it is very common to accumulate dozens of old kernels with their corresponding headers and modules. Each set can be around 300 MB, so 20-30 obsolete versions represent several gigabytes lost.
As we have discussed, the command sudo apt-get autoremove usually takes care of deleting linux-image-*, linux-headers-* y linux-modules-* that are no longer in use. In one real-world example, cleaning up this collection of kernels freed up about 9 GB of space.
The golden rule is Keep at least the current kernel and, if you want, an older one for security.The rest can be safely removed, always letting APT handle it instead of manually deleting files in /boot.
5. Clean system logs (systemd logs and journal)
Linux logs absolutely everything: system messages, services, errors, kernel activityThis is fantastic for diagnosing problems, but logs can grow out of control if they are not rotated or compressed properly.
5.1. Systemd journal size
In systems with systemd, the binary journal records are usually stored in /var/log/journalTo check how much space they take up:
journalctl --disk-usage
There are cases in which the journal occupies 1,8 GB or morewhich in small discus is a good bite.
You can leave only those from the last few days with this command:
sudo journalctl --vacuum-time=3d
In a typical example, this operation freed 1,7 GB of archived recordsdrastically reducing consumption in /var/log/journal without running out of recent information for debugging.
5.2. Traditional logs in /var/log
In addition to the journal, many systems still have text log files in /var/log (for example, Apache logs, Nginx, mail, databases, etc.). On servers with Plesk this is even more evident.
In these types of environments, it is very common for routes like / var / log / They can accumulate huge files, especially if log rotation isn't configured correctly. Before deleting anything, it's a good idea to check what file it is, its size, and whether you can actually delete it without further ado.
For example, if you detect that /var/log/apache2/error.log o /var/log/httpd/error_log They have skyrocketed, you can:
- Empty or delete the current log (for example, with
sudo rm /var/log/apache2/error.logKnowing that the service will recreate it, or truncate it to zero. - Adjust the rotation policy at logrotate so that they will not grow without limit again.
On servers with high usage, a periodic review of /var/log helps Avoid disk fill-up surprises that could crash web or email services.
6. Clean up old versions of Snap packages
In distributions that use snap packages (like Ubuntu), each application is packaged with its dependencies, making the packages larger than traditional .deb files. Furthermore, Snap It maintains several older revisions of each application so you can do a rollback, and that shows on the disc.
To see how much space snaps take up on your system:
sudo du -h /var/lib/snapd/snaps
Some users have seen figures of more than 5 GB in snaps only, of which a good portion were older, deactivated versions.
There is a small script a well-known shell (created by part of the Snapcraft team) that scans all Snap applications and removes reviews disabled:
#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
snap list --all | awk '/desactivado/{print $1, $3}' | while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
The basic steps are: copy this content to a file (for example, limpia-snaps.sh), give it execution permissions with chmod +x limpia-snaps.sh and run it as root:
sudo ./limpia-snaps.sh
In one documented case, after the script passed the space occupied in /var/lib/snapd/snaps he went down 5,6 GB to 2,5 GBThat is, it gained more than half of the space occupied by Snap.
7. Clean up temporary files and typical directories on servers
On servers, especially with control panels like Plesk, there are a number of paths that They are usually the direct culprits behind the disk filling up.It's important to understand them in order to address them before requesting an expansion of space.
7.1. Directories that usually consume the most space
When analyzing with du-sh In the root directory and in /var, you'll see that the following directories are common suspects:
- / var / log /: system logs, web server logs, email logs, etc.
- /var/lib/psa/dumps/Plesk backups, which can accumulate gigabytes and gigabytes if not rotated.
- /usr/local/psa/PMM/tmp/: temporary files from the Plesk backup manager.
- / tmp /: Temporary files of the system and various applications.
- /var/www/vhosts/Websites hosted on the server, with their files, logs, and backups.
- /var/qmail/mailnames/: mailboxes of domains managed by Plesk.
- /var/lib/mysql/MySQL/MariaDB databases, which can grow significantly in active applications.
Once you have located the problematic directory, you need to decide what can be deleted, what can be archived, and what should be moved to another volumealways being careful not to take down services in production.
7.2. Clean temporary files and old backups
In many cases the problem boils down to old backups you no longer need and abandoned temporary files. For example:
- Delete very old backups of /var/lib/psa/dumps/ leaving only the last necessary ones.
- Empty / tmp / of files that have not been touched for a long time, taking care not to interfere with active processes.
- Review and clean cache and temporary directories on the vhosts of /var/www/vhosts/.
Combining these actions with the log cleanup we saw earlier, it is common Recover several gigabytes of space on overloaded servers without needing to resize disks.
8. Delete duplicate files
Another silent source of space consumption is the duplicate files scattered across different folders (photos, project copies, duplicate videos, etc.). On older desktops, this can add up to many gigabytes.
There are tools with a graphical interface such as FSlint or command-line utilities such as FDUPES that are responsible for scanning a set of directories, finding identical files and allowing you to delete them or keep only a copy.
The idea is to carefully choose the paths to analyze (for example, your home folder and data drives) and go reviewing the results before deletingto avoid accidentally damaging something important.
9. Graphical tools for cleaning Linux (Stacer and similar)
If you don't feel like remembering commands or managing them one by one, there are utilities with a graphical interface that They centralize a large part of the cleaning and maintenance tasks in a few clicks.
One of the best known in Ubuntu and derivatives is Stacerwhich brings together in a single window:
- Information of the Use of resources and disk space.
- Chronic Disease startup applications and services.
- cleaner of caches, logs, temporary files and more.
Although these types of programs make life easier, some people prefer Do not install any additional software to avoid consuming extra space.And it manages just with the terminal. This is where personal preference comes in: if you're short on space, you might want to learn the commands and save yourself from using extra applications.
10. Move applications and processes, and monitor space
In some desktop systems, one of the main reasons for lack of space is simply having too many applications installed on the same partition where you store your personal data.
One option is uninstall what you don't useBut if you don't want to do without certain programs, you can move them or redistribute large data to other partitions or disks (for example, mounting a second disk for /home, /var or a data folder).
On servers, reduce the number of unnecessary processes and services It also helps indirectly: fewer active services means fewer logs, fewer caches, and in some cases, less generated data.
11. Safely erase free space on Linux disks
There are situations where you don't just want to free up space—for example, free up empty swap space- but remove any recoverable traces of files you have already deletedThis is especially important if you are going to sell a computer, reuse a hard drive, or handle sensitive information.
If you have, for example, a 4 TB external hard drive with 3 TB occupied and 1 TB free, what you want is overwrite only the free space, without touching the current dataIn Linux, this can be done by creating a large file to fill that gap and then deleting it.
A typical way is to use dd to write zeros or random data to a temporary file within the external disk's file system:
cd /ruta/al/disco/externo
dd if=/dev/zero of=relleno bs=1M
The command will write data until the free space is filled. At that point you delete the file:
rm relleno
With this you have achieved stepping on free space with zerosThis makes recovering previously deleted files extremely difficult, but it keeps your 3 TB of data intact. If you prefer randomness, you can use if=/dev/urandomknowing that it will be slower.
Besides dd, there are utilities such as shred, whose classic objective is to repeatedly overwrite a file or device with patterns of random ones and zeros. In modern hard drives and SSDs There are technical nuances regarding the absolute effectiveness of these methods, but in practical terms they greatly increase the difficulty of recovery.
12. Backups and precautions before major cleanups
Before you start deleting things indiscriminately, especially on servers or production machines, it is highly recommended to have a recent backup of important data. Although the guide focuses on freeing up space, it's worth remembering that a poorly written command (for example, a rm -rf in the wrong place) can leave you without a system.
Some commercial suites, such as certain data recovery solutions for Linux, allow back up or recover files from problematic disksThey can be useful if you've already lost information, but the best strategy is always prevention.
In server environments, installing a disk usage monitor Having it notify you when you exceed a certain percentage (80%, 90%, etc.) is a good idea to anticipate problems and schedule cleanings or upgrades. storage with time.
With all these methods combined—from Autoremove, clean, and thumbnail cleaning From managing kernels, logs, snaps, Plesk backups, and securely wiping free space, you can keep your Linux system—whether desktop or server—in a healthy state, with enough space to work and without the dreaded "disk full" warnings appearing when you least need them.
Passionate writer about the world of bytes and technology in general. I love sharing my knowledge through writing, and that's what I'll do on this blog, show you all the most interesting things about gadgets, software, hardware, tech trends, and more. My goal is to help you navigate the digital world in a simple and entertaining way.