How to Free Up Space in Linux with Effective Commands: A Complete Guide

Last update: 09/04/2025
Author Isaac
  • Know and use the commands df and du to identify what takes up the most space.
  • Remove packages, logs, old Snap versions, or orphaned dependencies.
  • Use automated scripts and tools like BleachBit or Stacer if you prefer a graphical interface.
  • Avoid disk overload to prevent performance issues, errors, and loss of services.

basic df and du commands

Your system Linux Is it slow or is it giving you low disk space warnings? Don't worry, you're not alone. With daily use, installing programs, updates and Temporary files, your system can become filled with digital junk.

In this comprehensive guide we compile the best methods and commands to free up space on Linux.Whether you're using Ubuntu, Debian, CentOS, or any other derivative distro, here are the steps you need to keep your system clean and free of space.

How to check disk space status

Before you start deleting anything, the first thing is to know where the space is goingFor this, we have two fundamental tools: df y du.

The df (disk free) command It shows you how much space is occupied and how much is free on each mounted file system. To get the information in a human-readable form, use:

df -h

This will display the data in kilobytes, megabytes, and gigabytes. You'll see columns like Size, Used, Available y use%.

With the du (disk usage) command You can see how much data specific directories and files are consuming. For example, to see the total size of the current directory:

du -sh

If you want to see which subdirectories are taking up the most space in /var, run:

du -sh /var/*

You can also sort them by size:

du -sh * | sort -rh | head -10

These tools allow you to identify which areas of the system are consuming the most storage, an essential step before you start freeing up space.

Remove unnecessary packages and dependencies

With There, Linux accumulates orphaned or no longer needed packages. You can remove them with:

sudo apt-get autoremove (for Debian/Ubuntu systems)

sudo yum autoremove (on CentOS/RHEL)

This removes installed libraries and components as dependencies of programs you've already uninstalled, as well as old kernels you no longer use.

  The way to Allow Do Not Disturb Mode On iPhone

It is also a good idea to clear the package cache:

sudo apt-get clean deletes all stored packages

sudo apt-get autoclean delete only obsolete ones

On Yum-based systems:

sudo yum clean all

With this you can save several hundred megabytes or even gigabytes, especially if you don't clean frequently.

Uninstall software you don't use

Check if you have installed software that you don't use regularlyMany programs are left taking up space "just in case." You can list what's installed with:

dpkg --get-selections (Ubuntu/Debian)

Uninstall what is not needed with:

sudo apt-get remove nombre_del_paquete

sudo apt-get purge nombre_del_paquete if you want to delete the configuration files as well

For CentOS or RedHat:

sudo yum remove nombre_del_paquete

Deleting that unused browser, duplicate editors, or tools you tried once can help you free up space immediately..

Remove old kernel versions

Linux distributions install new kernels, but they don't always remove old ones. If you don't need them, you can remove them:

First, identify the installed ones:

dpkg --get-selections | grep linux-image

uname -r will tell you your current kernel. Don't delete this one.

Now delete the ones that are not the current one:

sudo apt-get remove --purge linux-image-X.XX.X-XX-generic

This can free up several hundred MB quickly.The system remains cleaner and safer.

Delete temporary files and logs

Linux systems generate many system logs, temporary system files and backupsThe most common locations are:

  • /var/log/ – system logs
  • /tmp/ – temporary system files
  • /usr/local/psa/PMM/tmp/ – Plesk temporary
  • /var/lib/psa/dumps/ – Plesk backups

To find large files to delete:

find /var/log -type f -size +10M

And to delete them if you don't need them:

sudo rm /var/log/nombre_del_log

If you are using systemd, you can clean old logs with:

sudo journalctl --vacuum-time=7d

This will delete logs older than 7 days. You can adjust this period to your liking.

Remove old versions of Snap packages

Snap maintains several old versions of each app installed. Although useful for reverting changes, it can take up several gigabytes.

  Repair: iPhone Related to WiFi However No Web

To list the space used by Snap:

du -h /var/lib/snapd/snaps

To free up space, you can use this script provided by the Snap team:


#!/bin/bash
# Cierra todas las apps Snap antes
snap list --all | awk '/disabled/ { print $1, $3 }' | while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done

Give it execute permissions and run it with sudo. It removes disabled versions and usually frees up several GB.

Clear the thumbnail cache

When you use File Explorer, Linux generates image thumbnails to load them faster. These accumulate in:

~/.cache/thumbnails/

To see its size:

du -sh ~/.cache/thumbnails

And to empty it:

rm -rf ~/.cache/thumbnails/*

It is advisable to do this every few months to keep the system tidy..

Find duplicate files

Duplicate files waste valuable space. You can use tools like:

  • FSlint – graphical interface
  • FDUPES – command line tool

To install fdupes:

sudo apt install fdupes

And to search for duplicates in a folder:

fdupes -r /ruta/al/directorio

Clean up unused configuration files

When packages are removed, their configuration files are sometimes left behind. You can remove them with:

sudo dpkg –purge \\`COLUMNS=300 dpkg -l | egrep "^rc" | cut -d' ' -f3\\`

This safely removes remnants of long-deleted software..

Free up space reserved for root

By default, the system reserves a 5% of the space for rootYou can reduce that amount to 2% with:

sudo tune2fs -m 2 /dev/sda1

Of course, only do this if you're sure and have made a backup. This change can free up several hundred MB on large drives.

Graphic tools to free up space

If you prefer to avoid commands, there are very useful GUI tools:

Stacer

A system optimizer with a modern interface. Its features include:

  • Quick deletion of caches, logs and temporary files
  • Process and service control
  • Managing startup apps

You can install it with:

sudo apt install stacer

bleachbit

Inspired by CCleaner, cleans unnecessary data from apps like Firefox, LibreOffice, etc. It can also overwrite files to prevent recovery.

  The right way to Stop Spotify From Beginning Routinely

Install it with:

sudo apt install bleachbit

These programs are fast, secure, and quite effective for those who don't want to remember commands.

With all these methods you can recover valuable disk space and keep Linux in perfect condition.From simple commands to automations and visual tools, there are options for all experience levels. Apply the steps that best suit your system and habits, and be sure to periodically check disk usage to avoid any surprises. A clean system always works better.

How to Free Up Swap Space in Linux
Related article:
How to Free Up Swap Space in Linux

Leave a comment