Running out of disk space on your Ubuntu system can be a frustrating experience. This article provides a detailed guide to identify the source of the problem and reclaim your storage. We'll cover tools like Disk Usage Analyzer, command-line utilities, and common culprits behind disk space shortages.
When your Ubuntu system reports low disk space, the first step is to determine what's consuming the most storage. Ubuntu offers several tools to help you visualize and analyze disk usage.
Disk Usage Analyzer, also known as Baobab, is a graphical tool that provides a visual representation of disk usage. It allows you to easily identify large files and directories.
Installation (if needed): While it's typically pre-installed, ensure Disk Usage Analyzer is on your system:
sudo apt-get install baobab
Running as Root (Important): To ensure Disk Usage Analyzer has the necessary permissions to scan all directories, run it as root:
sudo baobab
Note: If sudo baobab
doesn't work directly
a. Install the tool gksudo
sudo apt-get install gksu
b. Then use the gksudo
to run baobab
gksudo baobab
Analyzing the Output: The Disk Usage Analyzer displays a treemap or ring chart, where the size of each rectangle or segment corresponds to the amount of disk space used by a file or directory. Navigate through the file system to pinpoint the largest consumers of space and what exactly filled the space up.
While Disk Usage Analyzer is a great tool, the command line offers powerful alternatives for analyzing disk usage, especially when working remotely or on servers.
df -h
(Disk Free): This command displays the disk space usage for all mounted file systems in a human-readable format. Check the root directory (/
) to see its overall usage:
df -h
du -sh
(Disk Usage Summarized): This command provides a summary of the disk space used by the current directory. Navigate to different directories and run this command to find out which ones consume the most space. For example, to check the usage of the /var/log
directory:
cd /var/log
du -sh
ncdu
(NCurses Disk Usage): ncdu
is an interactive, console-based disk usage analyzer. It provides a user-friendly interface within the terminal to navigate your file system and identify space hogs:
sudo apt-get install ncdu
sudo ncdu
Use the arrow keys to navigate. Press ?
for a help menu. ncdu
is excellent for use over SSH connections.
Once you've identified the areas consuming the most disk space, you can start addressing the problem. Here are some common culprits.
Log files, especially those in /var/log
, can grow excessively large over time, particularly if there are errors or verbose logging enabled.
du -sh /var/log
.logrotate
to automatically compress or delete older logs.Temporary files accumulate in directories like /tmp
or /var/tmp
.
sudo rm -rf /tmp/*
, sudo rm -rf /var/tmp/*
with the knowlodge of what you are removing.The APT package manager stores downloaded package files in a cache.
Clear the APT cache using:
sudo apt-get clean
This removes downloaded package files from /var/cache/apt/archives
. Using autoclean
will only remove the packages that can no longer be downloaded and are largely useless.
sudo apt-get autoclean
Over time, some packages installed may no longer be a dependency to any programs actively used
Remove packages that are no longer required using:
sudo apt autoremove
Here's how to handle a particular case of a rapidly growing log file.
.xsession-errors
Filling UpThe .xsession-errors
file in your home directory stores error messages from X sessions. If this file grows excessively large, it indicates a recurring issue:
Clearing the file (temporary fix):
cp /dev/null ~/.xsession-errors
Identifying the Root Cause: The critical step is to identify the source of the errors being logged to .xsession-errors
. Open the file and examine the recent entries to diagnose the problem. Once you resolve the underlying issue, the file will cease to grow uncontrollably.
/home
, /var
, and /tmp
to isolate the impact of space consumption in those areas.By following this guide, you can effectively troubleshoot and resolve disk space issues on your Ubuntu system, ensuring smooth and efficient operation.