Running out of space on a Linux system can block package upgrades, interrupt logging, and cause services to fail when they cannot write data. Keeping enough free space on the main file systems preserves system stability and reduces the risk of sudden interruptions during critical operations.

Disk usage on Linux is determined by how files are laid out on mounted file systems such as / , /home, and /var. Tools like df, du, and find report which mount points, directories, and individual files consume the most space, while package managers store downloaded packages and metadata under locations such as /var/cache and /var/lib.

Removing files with elevated privileges can permanently delete configuration or application data if the wrong paths are targeted. The procedure below focuses on common safe areas such as package caches, logs, and user data on systemd-based distributions like Ubuntu and Debian, with notes for other distributions. Administrative privileges via sudo are required for system-wide operations, and command lines should be double‑checked before execution.

Steps to clear disk space on Linux:

  1. Display disk usage for all mounted file systems.
    $ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    tmpfs           391M  1.9M  389M   1% /run
    /dev/sda3        20G   18G  1.2G  95% /
    /dev/sda1       512M  120M  393M  24% /boot
    ##### snipped #####

    Focus on entries where Use% is close to 100% to choose a cleanup target.

  2. Measure space usage of top-level directories on the most full file system, typically / .
    $ sudo du -h -x --max-depth=1 /
    2.0G    /var
    1.2G    /usr
    500M    /home
    ##### snipped #####

    The -x option keeps du on a single file system so usage from other mounted disks does not distort results.

  3. Inspect space usage inside the heaviest system directory, such as /var.
    $ sudo du -h --max-depth=1 /var | sort -h
    96M     /var/log
    420M    /var/cache
    1.3G    /var/lib
    ##### snipped #####

    Subdirectories like /var/log, /var/cache, and /var/tmp often contain data that can be pruned safely when not needed.

  4. Locate individual files larger than 500MB on the selected file system.
    $ sudo find / -xdev -type f -size +500M -printf '%p %s\n' | sort -h
    /var/lib/libvirt/images/vm-disk.qcow2 16106127360
    /var/log/biglog.log 1073741824
    ##### snipped #####

    Before deleting any large file, confirm that it is not part of an active database, virtual machine, or critical application.

  5. Clear cached package files managed by apt.
    $ sudo apt clean

    On Fedora or other dnf based systems, use sudo dnf clean all instead of apt.

  6. Remove packages that were installed as dependencies but are no longer required.
    $ sudo apt autoremove --purge
    Reading package lists... Done
    Building dependency tree... Done
    The following packages will be REMOVED:
      old-library* unused-kernel*
    ##### snipped #####

    Review the list shown by apt and abort with Ctrl+C if important packages appear unexpectedly.

    Removing packages with autoremove can uninstall tools that are still in occasional use, which may break scripts or workflows until they are reinstalled.

  7. Reduce journal size by removing entries older than seven days.
    $ sudo journalctl --vacuum-time=7d
    Vacuuming done, freed 512.0M of archived journals from /var/log/journal.

    journalctl manages binary logs under /var/log/journal on systemd systems and can limit usage by time or size.

    Discarding older logs makes post‑incident analysis harder if issues occurred before the retention window.

  8. Delete unneeded files from the current user's /Downloads directory and desktop trash.
    $ rm -rf ~/Downloads/*
    $ rm -rf ~/.local/share/Trash/files/*

    Temporary installers, archives, and media often accumulate in these locations after they are no longer required.

    The rm -rf command permanently removes files without a confirmation prompt, so incorrect paths can erase important data.

  9. Purge cached data in the current user's /.cache directory.
    $ du -sh ~/.cache
    500M    /home/user/.cache
    $ rm -rf ~/.cache/*
    $ du -sh ~/.cache
    4.0K    /home/user/.cache

    Most applications store only regenerable data in .cache, so space is reclaimed at the cost of slightly slower first launches while caches are rebuilt.

    Clearing caches may log out web sessions or remove thumbnails and temporary state for graphical applications.

  10. Remove home directories that belong to user accounts that no longer exist.
    $ sudo ls /home
    alice
    olduser
    $ sudo rm -rf /home/olduser

    Confirm that the corresponding account has been removed, for example with getent passwd olduser, before deleting its home directory.

    Using rm -rf on the wrong path under /home can erase active user data irreversibly.

  11. Confirm reclaimed disk space on the cleaned file system.
    $ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda3        20G   12G  7.0G  64% /
    ##### snipped #####

    Compare the Use% and available space values with those observed in the first step to verify that cleanup had the intended effect.

Discuss the article:

Comment anonymously. Login not required.