How to Clean up Disk Space on Ubuntu

Clean up Disk Space on Ubuntu

As an Ubuntu user, you may have encountered the frustrating experience of running low on disk space. Whether you‘re a developer working with large files, a content creator with an extensive media library, or simply someone who has been using the same system for an extended period, managing disk space is crucial to maintain optimal performance and avoid storage-related issues. In this comprehensive guide, we’ll explore various methods to clean up and optimize your Ubuntu system‘s disk usage, helping you reclaim valuable storage space and keep your system running smoothly.

Analyze Current Disk Usage

Before we dive into the cleaning process, it’s essential to understand how your disk space is being utilized. Ubuntu provides several tools to analyze your current disk usage, allowing you to identify the largest directories and files consuming the most space.

Using Disk Usage Analyzer (Baobab)

Ubuntu comes with a handy graphical tool called Disk Usage Analyzer, also known as Baobab. To access it, follow these steps:

  1. Open the Applications menu and search for “Disk Usage Analyzer.”
  2. Click on the Disk Usage Analyzer icon to launch the application.
  3. Select the disk or directory you want to analyze and click “Scan.”
  4. Baobab will display a visual representation of your disk usage, with larger sections indicating directories or files occupying more space.

This tool provides an intuitive way to explore your file system and pinpoint areas that may require attention.

Checking Disk Space and Usage from the Command Line

For those who prefer the command line, Ubuntu offers powerful utilities to check disk space and usage:

  • Open the Terminal application.
  • To view the disk space usage of your file system, use the df command:
df -h

This command displays the disk usage in a human-readable format, showing the total size, used space, available space, and percentage of use for each file system.

  • To view the disk usage of specific directories, use the du command:
du -sh /path/to/directory

Replace /path/to/directory with the actual path of the directory you want to analyze. The -s option provides a summary of the total disk usage, while -h displays the sizes in a human-readable format.

By using these command-line tools, you can quickly assess your disk usage and identify directories that may require further investigation.

Remove Unnecessary Packages and Dependencies

One common reason for disk space consumption on Ubuntu systems is the accumulation of unnecessary packages and dependencies. Over time, you may have installed applications that are no longer in use, or your system may have retained old dependencies that are no longer required. Removing these unnecessary packages can free up significant disk space.

Using apt autoremove

The apt package manager in Ubuntu provides a convenient way to remove unneeded packages:

  • Open the Terminal application.
  • Run the following command:
sudo apt autoremove

Clearing Out the apt Cache

When you install packages using apt, it retrieves package files and stores them in a local cache. Over time, this cache can grow in size. To clear out the apt cache and reclaim disk space, follow these steps:

  • Open the Terminal application.
  • Run the following command:
sudo apt clean

Removing Old Kernel Versions

Ubuntu keeps old kernel versions as a fallback in case of issues with newer versions. However, if you have been using Ubuntu for a while and have successfully upgraded your kernel multiple times, you can remove the old kernel versions to save disk space:

  • Open the Terminal application.
  • Run the following command to list the installed kernel versions:
dpkg --list | grep linux-image
  • To remove an old kernel version, run the following command:
sudo apt remove linux-image-VERSION
  • After removing the old kernels, run the following command to update the GRUB bootloader:
sudo update-grub

Uninstalling Applications You No Longer Use

Another effective way to reclaim disk space is by uninstalling applications that you no longer use. To uninstall an application using apt, follow these steps:

  • Open the Terminal application.
  • Run the following command to remove an application:
sudo apt remove PACKAGE_NAME
  • To completely remove the application along with its configuration files, use the purge option instead of remove:
sudo apt purge PACKAGE_NAME

Clean Up Logs and Temporary Files

Ubuntu systems generate various log files and temporary files during normal operation. These files can accumulate over time and consume disk space. Regularly cleaning up these files can help optimize your disk usage.

Clearing Out Old Log Files

Log files are essential for troubleshooting and monitoring system activity, but they can grow large if not managed properly. To clear out old log files, follow these steps:

  • Open the Terminal application.
  • Navigate to the log directory:
cd /var/log

List the log files and directories:

ls -lh
  • Identify the log files or directories that you want to clean up. Common log files include syslog, auth.log, and kern.log.
  • To clear the contents of a log file, use the following command:
sudo truncate -s 0 LOGFILE
  • Alternatively, you can compress old log files to save space:
sudo gzip LOGFILE

Note: Be cautious when clearing log files, as they may contain important information for troubleshooting. It’s recommended to compress old log files instead of deleting them entirely.

Emptying the Thumbnail Cache

Ubuntu’s file manager, Nautilus, generates thumbnail previews for images and other media files. These thumbnails are stored in a cache directory and can consume disk space over time. To empty the thumbnail cache, follow these steps:

  • Open the Terminal application.
  • Run the following command to remove the thumbnail cache:
rm -rf ~/.cache/thumbnails/*

Removing Temporary Files

Temporary files are created by various applications and system processes. These files are usually stored in the /tmp directory and can be safely removed to free up disk space. To remove temporary files, follow these steps:

  • Open the Terminal application.
  • Run the following command to remove files in the /tmp directory:
sudo rm -rf /tmp/*

Use Disk Cleaning Utilities

Ubuntu offers several disk cleaning utilities that simplify the process of removing unnecessary files and freeing up disk space. These tools provide a user-friendly interface and automate various cleaning tasks.


Bleachbit is a powerful open-source disk cleaner and privacy tool for Ubuntu. It can remove cache files, delete temporary files, and clean up various application-specific data.

Ubuntu Cleaner

Ubuntu Cleaner is a user-friendly tool that helps you clean cache files, remove old packages, and delete unnecessary files. It provides a simple interface for performing common cleaning tasks.


Stacer is a Linux system optimizer and monitoring tool that includes disk-cleaning features. It provides a sleek and intuitive interface for managing your Ubuntu system.


Sweeper is a disk cleaner specifically designed for KDE desktops. If you are using Kubuntu or have the KDE desktop environment installed on your Ubuntu system, Sweeper can be a handy tool for cleaning up disk space.

Other Tips to Free Up Space

In addition to the methods mentioned above, there are a few other tips and techniques you can use to free up disk space on your Ubuntu system:

Moving Personal Files to an External Drive or Cloud Storage

If you have a large collection of personal files, such as documents, photos, or videos, consider moving them to an external hard drive or cloud storage service. This approach allows you to free up significant disk space on your Ubuntu system while still keeping your files accessible. Popular

Marshall Anthony is a professional Linux DevOps writer with a passion for technology and innovation. With over 8 years of experience in the industry, he has become a go-to expert for anyone looking to learn more about Linux.

Related Posts