Disk space errors can stop services, break updates, and cause systems to behave in unpredictable ways. The good news is that these problems are usually straightforward to diagnose and fix when you approach them step by step.
This guide walks through a calm, practical process for identifying what is filling your disk and safely reclaiming space. Every command and example below comes directly from the provided script and reflects how disk space issues are handled in real IT environments .
Step 1: Confirm the Disk Is Actually Full
Before making changes, always verify the problem.
df -h
You will see output similar to:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 48G 1.2G 98% /
This command shows disk usage for each filesystem. The Use% column is what matters most. Anything above 90 percent is a warning sign. In this example, the root filesystem is nearly full.
In real IT work, this is always the first check when someone reports errors like “no space left on device.”
Step 2: Find Which Directory Is Using Space
Once you know the disk is full, the next step is narrowing down where the space is going.
du -h –max-depth=1 /
You will see size totals for top-level directories, such as:
4.0K /bin
1.2G /var
15G /home
The du command shows disk usage, and –max-depth=1 keeps the output readable. At this stage, you are simply looking for the largest directory so you know where to focus.
This saves time and avoids guessing.
Step 3: Drill Into the Largest Directory
If /var stands out as large, look inside it.
du -h –max-depth=1 /var
Example output:
900M /var/log
200M /var/cache
This tells you which subdirectory is growing. Disk space problems are commonly caused by log files, package caches, or temporary data.
Step 4: Check Log File Sizes
Log files are one of the most frequent causes of disk space issues.
ls -lh /var/log
You may see something like:
-rw-r–r– 1 root root 800M syslog
The -lh options make file sizes easy to read. Large log files often grow quietly over time. This does not mean logs are bad, only that they need occasional management.
Servers that run for months without maintenance often fail for this reason.
Step 5: Safely Clear Old Log Files
Instead of deleting log files, it is safer to empty them while keeping the file in place.
sudo truncate -s 0 /var/log/syslog
There is no output when this succeeds. The file still exists, and services continue writing to it normally. This approach avoids unexpected behavior from applications that expect the log file to be present.
Step 6: Clear the Package Cache
Package managers store downloaded files that are no longer needed.
On Debian or Ubuntu systems, you can clear this cache with:
sudo apt clean
This removes cached packages without uninstalling any software. It is safe to run at any time and is often a quick way to free space on smaller systems.
Step 7: Recheck Disk Space
Always confirm that your changes worked.
df -h
You should now see significantly more free space, for example:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 30G 20G 60% /
Never assume the problem is fixed. Verification is part of the process.
Common Beginner Mistakes to Avoid
One common mistake is deleting random files just to free space. Always identify what is safe to remove first.
Another is forgetting to use sudo. Many disk issues involve system directories, and permission errors are a sign you need elevated access.
Finally, beginners often focus only on /home. In practice, most disk emergencies happen in /var or on the root filesystem itself.
A Real-World IT Scenario
A server suddenly stops accepting SSH connections. You access it through the console and see disk-related errors. Running df -h shows the root disk is full.
By checking /var/log, truncating oversized logs, and cleaning the package cache, you restore disk space. Services recover without a reboot. This exact workflow happens every day in production environments.
A Small Next Step
Once you are comfortable fixing disk space issues, the next improvement is preventing them. Linux includes tools for automatic log rotation so logs do not grow unchecked.
That can wait. First, make sure these basics feel natural.
Conclusion
Disk space errors feel stressful, but they are predictable and fixable. When you slow down, verify each step, and make targeted changes, these problems become routine maintenance instead of emergencies.
Work through this process a few times. With repetition, it will feel straightforward and reliable.