0
0
Linux-cliDebug / FixBeginner · 4 min read

How to Fix 'No Space Left on Device' Error in Linux

The No space left on device error in Linux means your disk or partition is full. To fix it, delete unnecessary files or clear cache to free up space using commands like rm or sudo apt clean.
🔍

Why This Happens

This error occurs because the disk or partition where you want to save files is completely full. Linux cannot write new data when there is no free space left. This often happens when logs, caches, or large files accumulate over time.

bash
touch /full_disk/testfile
Output
touch: cannot touch '/full_disk/testfile': No space left on device
🔧

The Fix

To fix this, find and delete unnecessary files or clear package caches to free space. Use df -h to check disk usage and du -sh * to find large folders. Then remove files with rm or clean caches with sudo apt clean.

bash
df -h
sudo apt clean
rm -rf /var/log/*.log
rm -rf ~/Downloads/largefile.iso
Output
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 30G 20G 60% / Cleaning up package cache... Removed cached packages. Removed large log files and downloads to free space.
🛡️

Prevention

Regularly monitor disk space with df -h and clean caches often. Set up log rotation to avoid huge log files. Avoid storing unnecessary large files on your main partitions. Automate cleanup tasks with cron jobs to keep space free.

⚠️

Related Errors

Similar errors include Read-only file system caused by disk errors, and Disk quota exceeded when user limits are reached. Fix these by checking disk health with fsck or adjusting user quotas.

Key Takeaways

The 'No space left on device' error means your disk is full and cannot save more data.
Use commands like 'df -h' and 'du -sh *' to find where space is used.
Delete unnecessary files and clear caches to free up disk space.
Set up regular maintenance like log rotation and automated cleanup to prevent this error.
Check related errors like disk quota or file system issues if problems persist.