Linux

Disk Cleanup in Ubuntu: How to Free Up Space in 10 Minutes

In this guide, you'll learn how to safely clean your disk in Ubuntu by removing system caches, old kernel versions, and temporary files to quickly free up space and speed up your system.

Updated at February 15, 2026
10-15 min
Easy
FixPedia Team
Применимо к:Ubuntu 20.04Ubuntu 22.04Ubuntu 24.04

Introduction

Over time, Ubuntu accumulates temporary files, package caches, old kernel versions, and logs that can occupy dozens of gigabytes. This guide will help you safely clean your disk, reclaim space, and keep your system tidy. We will cover built-in utilities and proven methods that work on current Ubuntu versions (20.04, 22.04, 24.04).

Requirements

  • Access to a terminal (Ctrl+Alt+T or SSH).
  • Superuser privileges (sudo) for most commands.
  • Recommendation: Back up important data before performing mass deletions.

Step 1: Check Current Disk Usage

Before cleaning, identify which partitions are full. Run:

df -h

Example output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       50G   45G  3.1G  94% /
/dev/sda2      100G   12G   88G  12% /home
  • Use% shows fill level. If the value is close to 100%, cleaning is urgently needed.
  • To analyze specific folders (e.g., /var or /home), use:
    sudo du -sh /var/* | sort -rh | head -20
    
    This will show the 20 largest subdirectories in /var.

Step 2: Clean APT Cache

APT stores downloaded packages in /var/cache/apt/archives/. They often occupy hundreds of megabytes.

Clean the entire cache:

sudo apt-get clean

Deletes all package files from the cache.

Clean only obsolete packages (without removing current ones):

sudo apt-get autoclean

Additionally: Remove automatically installed dependencies that are no longer needed:

sudo apt-get autoremove --purge

⚠️ Important: autoremove can remove packages you installed manually if they were installed as dependencies. Review the list before confirming.

Step 3: Remove Old Kernel Versions

Each kernel update leaves an old image (200–500 MB each). Keep at least two kernels: the current one and one fallback.

  1. Find the current kernel:
    uname -r
    

    Example: 5.15.0-86-generic.
  2. List installed kernels:
    dpkg --list 'linux-image*' | grep ^ii
    
  3. Remove old kernels (e.g., 5.15.0-78-generic):
    sudo apt-get remove --purge linux-image-5.15.0-78-generic linux-headers-5.15.0-78-generic
    

    💡 Tip: Do not remove the kernel matching uname -r. You can leave one additional old kernel for rollback.

  4. Update the bootloader (if GRUB did not update automatically):
    sudo update-grub
    

Step 4: Clean System Logs

Systemd stores logs in /var/log/journal/. They can grow significantly.

Clean old journals (keep last 3 days):

sudo journalctl --vacuum-time=3d

Clean by size (keep no more than 100 MB):

sudo journalctl --vacuum-size=100M

Permanent limit: Edit /etc/systemd/journald.conf:

[Journal]
SystemMaxUse=100M

Then restart the service:

sudo systemctl restart systemd-journald

Step 5: Clean Temporary Files

5.1. System temporary files (/tmp)

# Delete files in /tmp not accessed in 10 days
sudo find /tmp -type f -atime +10 -delete
# Delete empty directories (optional)
sudo find /tmp -type d -empty -delete

5.2. User application caches

  • Flatpak: flatpak uninstall --unused
  • Snap: sudo snap set system refresh.retain=2 (keep 2 latest versions) and sudo snap remove <old-snap>
  • Browsers: Clear cache via browser settings or delete folders ~/.cache/chromium/, ~/.cache/mozilla/.

Step 6: Find and Delete Large Files

6.1. Using find

Find files larger than 100 MB system-wide (may take time):

sudo find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null | awk '{print $5, $9}'

Review the list and manually delete unnecessary files.

Install the interactive analyzer:

sudo apt-get install ncdu

Run to analyze your home folder:

ncdu ~

Or for root (requires sudo):

sudo ncdu /

Navigation: arrows to select, d to delete file/folder, q to exit.

Verify Results

  1. Run df -h again and compare Use% values with the initial ones.
  2. For a quick check of free space:
    free -h
    
    (Note: free shows RAM, not disk; for disk use df).
  3. If space is not fully freed, check if deleted files are still held open by processes (rare but possible):
    sudo lsof | grep deleted
    
    Restart the relevant processes or reboot the system.

Potential Issues

❌ "No space left on device" when running commands

  • Cause: Not enough space for operation temporary files.
  • Solution: Manually delete the largest file (e.g., an old log or dump) from /var/log or your home folder. Use ncdu to locate it.

❌ Deleting an important file/kernel

  • Cause: Manual error or autoremove removed a needed package.
  • Solution: Restore from backup or reinstall the package (sudo apt-get install linux-image-<current>). For kernels, you can boot into an old kernel from GRUB and restore.

❌ Access errors when cleaning /tmp or caches

  • Cause: Running without sudo or files locked by processes.
  • Solution: Use sudo for system folders. For user caches, operate as your user without sudo.

❌ Cleaning did not have the expected effect

  • Cause: Large files hidden elsewhere (e.g., in /var/lib/docker for Docker, ~/snap for Snap).
  • Solution: Analyze specific subdirectories with ncdu or du. For Docker: docker system prune -a (caution: removes all unused images and containers).

❌ System fails to boot after kernel removal

  • Cause: Deleted the current and only working kernel.
  • Solution: Boot into Recovery Mode via GRUB and reinstall the kernel:
    sudo apt-get install linux-image-generic
    sudo update-grub
    

F.A.Q.

How to check disk space usage in Ubuntu?
Is it safe to manually delete files from /tmp?
What to do if space isn't freed after cleaning the APT cache?
How to automate disk cleanup in Ubuntu?

Hints

Check current disk usage
Clean APT cache
Remove old kernel versions
Clean system logs
Clean temporary files
Find and delete large files
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community