When encountering the "no space left on device" error in Ubuntu, it indicates that either your disk storage or inode capacity is exhausted. Here’s how to diagnose and resolve this issue:
Step 1: Check Disk Space and Inode Usage
First, verify which resource is depleted. Open a terminal and run:
df -h

This command displays disk space usage in a human-readable format. Look for filesystems (like , /home
, /var
) that are at or near 100% usage.
Next, check inode usage:
df -i
This command shows inode usage. If a filesystem is near 100% IUse%, it means you've run out of inodes, even if disk space is available. This is common if you have a vast number of very small files.
Step 2: Identify Large Files and Directories
If disk space (not inodes) is the issue, find what's consuming it. A useful command is:

sudo du -sh / sort -rh head -n 10
This lists the top 10 largest directories in the root filesystem. You can then navigate into these directories and repeat the command (e.g., sudo du -sh /var/ sort -rh head -n 10
) to pinpoint large files or subdirectories.
Alternatively, install and use ncdu
for an interactive way to explore disk usage:
sudo apt update && sudo apt install ncdu
sudo ncdu /

Step 3: Clean System Caches and Unnecessary Packages
Clean APT Cache:
Package managers like APT store downloaded package files. Clean them with:
sudo apt clean
Remove Unused Packages and Dependencies:
sudo apt autoremove

This command removes packages that were automatically installed to satisfy dependencies for other packages and are no longer needed.
Step 4: Remove Old Kernels
Old Linux kernels can consume significant space in /boot
and /lib/modules
. Be cautious with this step.
First, identify your current kernel:
uname -r
Do not remove the currently running kernel. It's wise to keep one or two older kernels as well, just in case.

List installed kernels (Debian/Ubuntu):
dpkg --list grep 'linux-image'
dpkg --list grep 'linux-headers'
To remove a specific old kernel (replace VERSION-generic
with the actual version you want to remove):
sudo apt remove linux-image-VERSION-generic linux-headers-VERSION-generic

sudo apt autoremove
(to clean up related dependencies)
Finally, update GRUB:
sudo update-grub
Step 5: Check Log Files
Log files, especially in /var/log
, can grow very large.
Check the size of the log directory:

sudo du -sh /var/log/
You can manually delete older, rotated log files (e.g., .gz
, .1
suffixes) or clear specific large log files if you are certain they are not needed. For example, to clear a specific log file (use with caution):
sudo truncate -s 0 /var/log/syslog
(This empties the file without deleting it, preserving permissions.)
Consider configuring log rotation (e.g., via logrotate
) to manage log file sizes automatically.
Step 6: Check /tmp Directory
The /tmp
directory can sometimes fill up with temporary files that weren't properly cleaned.

sudo du -sh /tmp/
System reboots usually clear /tmp
, but you can manually remove old, unneeded files if necessary. Be careful not to remove files currently in use.
Step 7: Docker or Other Container Systems
If you use Docker or other containerization tools, they can consume a lot of space with images, volumes, and build caches.
For Docker:
- Prune unused Docker resources:
docker system prune -a --volumes
(This will remove all stopped containers, all unused networks, all dangling images, and all unused build cache, and all unused volumes. Use with caution.) - List and remove specific images:
docker images
, thendocker rmi IMAGE_ID
- List and remove specific volumes:
docker volume ls
, thendocker volume rm VOLUME_NAME
Step 8: Files Deleted but Still Held Open
Sometimes, a process might keep a deleted file open, preventing the space from being freed. You can identify such files using lsof
:

sudo lsof grep '(deleted)'
This will list processes holding open deleted files. Restarting the offending process or the system will usually release this space.
By systematically checking these areas, you should be able to identify the cause of the "no space left on device" error and reclaim disk space or inodes.