Most Linux users are forced to return to their native operating system due to storage issues. The error message Linux no space left on device pokes a knife through your heart because no one wants to part with their important data. So even if you are running an installation command or trying to configure something on the OS, computing errors are bound to occur.
This article will walk you through the how, what, and why of Linux “no space left on device” error!
How To Fix the Linux No Space Left on Device Error?
Here is how you can fix the Linux no space left on device error:
Check Disk Usage
Before you start freeing up space, it is essential to identify the things that are consuming your storage space.
Using df -h to Check Disk Space
The df (disk free) command helps identify all the available and the used disk spaces on the mounted filesystems.
df -h
Get exclusive access to all things tech-savvy, and be the first to receive
the latest updates directly in your inbox.
- The -h flag makes the output human-readable (e.g., showing sizes in MB/GB instead of blocks).
- Look for the % Used column to see if any partition is near 100%.
To check space on a specific partition (e.g., /), run:
df -h /
Using du -sh /* to Find Large Files and Directories
The du (disk usage) command helps identify the directories that are taking up most of the space.
du -sh /*
- -s: Summarizes total size instead of showing each file.
- -h: Displays sizes in human-readable format (MB, GB).
To sort results into a more detailed analysis, you can run this command:
du -ah / | sort -rh | head -20
This command will list the 20 largest files and directories in descending order.
Check Inode Usage
So, now that you know where your disk storage stands, you need to check the inode because even if you have adequate space, running out of inode can still cause a no space left on device error.
Inodes are responsible for storing metadata for files.
Using df -i to Check Available Inodes
Run the command below to check inode usage on your system:

df -i
- The % Iused column in the output shows the percentage of used inodes.
- If you identify an inode-heavy directory, check it with:
find / -xdev -type f | wc -l
If your inode count is too high, it is mainly due to excessive small files, such as cache files.
Freeing Up Space
- Deleting Unnecessary Log Files (/var/log/)
Log files can grow crowded over time. Here is how you can keep a check.
sudo journalctl –vacuum-time=7d
sudo rm -rf /var/log/*.gz /var/log/*.1 /var/log/syslog.*
For systems using logrotate, you can force cleanup:
sudo logrotate -f /etc/logrotate.conf
- Removing Old Packages and Dependencies (apt autoremove)
Unneeded dependencies can also take up space.
sudo apt autoremove -y
sudo dnf autoremove -y
sudo pacman -Rns $(pacman -Qdtq)
- Cleaning Temporary Files (/tmp/, /var/tmp/)
Temporary directories can also accumulate old files.
sudo rm -rf /tmp/*
sudo rm -rf /var/tmp/*
To automatically clean /tmp on reboot, add this line to /etc/fstab:
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
- Clearing Package Manager Caches
Package managers cache old package versions, consuming space.
sudo apt clean
sudo dnf clean all
sudo pacman -Sc
For a more aggressive cleanup in Arch:
sudo pacman -Scc
- Finding and Deleting Large Files Manually
To locate large files consuming space, use:
find / -type f -size +500M -exec ls -lh {} + | awk ‘{ print $9 “: ” $5 }’
To remove unwanted large files:
sudo rm -rf /path/to/large/file
Handling Docker and Snap Issues
Docker and snap packages can consume a lot of unwanted space over time and cause Linux no space left on device error.
- Cleaning Up Docker Storage
Check Docker disk usage:
docker system df
Remove unwanted objects:
docker system prune -a
PS: I didn’t proceed to yes “Y” because i don’t to remove anything at the moment.
To remove all unused volumes as well:
docker volume prune
- Cleaning Up Snap Packages
Snap saves all the older versions of packages, taking up necessary space.
Check Snap disk usage:
du -sh /var/lib/snapd
Remove old Snap revisions:
Set a limit on package retention:
sudo snap set system refresh.retain=2
Automating Disk Cleanup
Regular maintenance can prevent storage issues. Here are some ways to automate disk cleanup:
- Using Cron Jobs
Schedule cleanup tasks with cron:
crontab -e
Example: Clear /tmp/ every 6 hours:
- Using a systemd Timer
Create a service to clear logs:
sudo nano /etc/systemd/system/cleanup.service
Add:
[Unit]
Description=Periodic log cleanup
[Service]
ExecStart=/usr/bin/find /var/log -type f -name “*.log” -mtime +7 -delete
Create a timer:
sudo nano /etc/systemd/system/cleanup.timer
Add:
[Unit]
Description=Run cleanup weekly
[Timer]
OnCalendar=weekly
Persistent=true
[Install]
WantedBy=timers.target
Enable and start the timer:
sudo systemctl enable –now cleanup.timer
Disk Clean-up Automation Tools
That being said, you can use automation tools for disk cleanup, here are our top picks:
- Cron Jobs
Schedule periodic cleanup tasks (e.g., clear /tmp/ daily):
crontab -e
Add:
0 3 * * * rm -rf /tmp/*
- tmpreaper
Automatically delete old temporary files:
sudo apt install tmpreaper
sudo tmpreaper 7d /tmp # Remove files older than 7 days
- logrotate
Manage log file rotation and cleanup:
sudo nano /etc/logrotate.conf
Example rule to keep logs for 7 days:
/var/log/*.log {
daily
rotate 7
compress
missingok
}
- BleachBit
GUI tool for clearing junk files:
sudo apt install bleachbit
bleachbit –clean system.*
- ncdu
Interactive disk usage analyzer:
sudo apt install ncdu
ncdu /
Wrapping Up – Linux No Space Left On Device
If you are seeing the Linux “no space left on device” error on your system, it generally means that the storage is full. To fix this issue, you can consider deleting some files or folders that are taking up too much space.
Frequently Asked Questions
1. What causes the “No space left on device” error in Linux?
This error occurs when your disk is full, inodes are exhausted, or there are issues with temporary files and logs consuming excessive space.
2. What if my disk has space but I still get the error?
If df -h
shows free space, but df -i
indicates no free inodes, you need to remove small, unnecessary files that are consuming inodes.
3. Can a reboot fix the “No space left on device” error?
Sometimes, rebooting clears temporary files and resolves the issue. However, it’s better to investigate and manually clear space to prevent recurrence.