Linux Disk Space Full? Here's How to Find What's Actually Eating It

Your Linux server is running out of disk space. Learn how to find large files, investigate hidden storage usage, diagnose inode exhaustion, and safely recover storage without breaking production services.

Share
Linux disk space troubleshooting guide

Your Linux server is running out of disk space. Applications are throwing errors, logs are failing to write, and your monitoring system is sending alerts.

You SSH into the server and run:

df -h

The result confirms your suspicion: the root filesystem is almost full.

Your first instinct might be to delete old logs, clear temporary files, or remove unused Docker images. But deleting files without understanding what's consuming storage can make things worse, especially on production systems.

The real question isn't how to free up disk space. It's what is consuming it, why is it happening, and how do you fix it without breaking anything?

Let's investigate.

1. Identify which filesystem is running out of space

Start with:

df -hT

This displays filesystem capacity, used space, available space, filesystem type, and mount points.

Example output:

Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/vda1      ext4   80G   76G  1.2G  99% /
/dev/vda2      ext4  200G   45G  145G  24% /data

Here, the root filesystem (/) is almost full, while /data still has plenty of available space.

This distinction matters. A directory consuming 50 GB on /data isn't necessarily responsible for the root filesystem running out of space.

Pay attention to the Mounted on column. It tells you exactly which filesystem needs investigation.

2. Check for inode exhaustion

Sometimes Linux reports that a filesystem is full even when it appears to have available disk space.

The problem might be inode exhaustion.

Every file and directory requires an inode. A system containing millions of small files can run out of inodes before exhausting its actual storage capacity.

Check inode usage:

df -i

Look at the IUse% column.

If inode usage is at 100%, applications may be unable to create new files even when df -h reports free space.

Common causes include:

  • Applications generating excessive cache files.
  • Mail servers storing millions of small messages.
  • Container environments accumulating temporary files.
  • Applications creating files without proper cleanup.

When investigating inode exhaustion, focus on directories containing unusually large numbers of files rather than looking only for large files.

3. Find which directories are consuming storage

Now identify the largest directories on the affected filesystem.

For the root filesystem:

sudo du -xhd1 / 2>/dev/null | sort -h

Here's what the command does:

  • du calculates directory disk usage.
  • -x stays on the same filesystem.
  • -h displays human-readable sizes.
  • -d1 limits the output to one directory level.
  • sort -h sorts the results by size.

Example:

1.2G    /usr
2.4G    /opt
8.7G    /var
12G     /home

Here, /var and /home deserve further investigation.

Drill down into the suspicious directory:

sudo du -xhd1 /var 2>/dev/null | sort -h

You might discover that /var/log, /var/lib/docker, or /var/cache is consuming significantly more storage than expected.

Repeat the process until you identify the directory responsible.

4. Find unusually large files

Sometimes a single enormous file is responsible for most of the storage consumption.

Find files larger than 1 GB on the root filesystem:

sudo find / -xdev -type f -size +1G \
  -printf '%s %p\n' 2>/dev/null | sort -nr | head -20

This lists the 20 largest matching files, with their sizes in bytes.

Common offenders include:

  • Database dumps and backup archives.
  • Uncompressed application logs.
  • Old database binary logs.
  • Large temporary files.
  • Application-generated archives.

Before deleting anything, identify which application owns the file and whether it is still required.

A large file isn't automatically an unnecessary file.

5. Investigate deleted files that still consume disk space

This is one of the most confusing Linux storage problems.

You delete a large log file, but df -h shows no improvement.

Why?

On Linux, deleting a file removes its directory entry. However, if a running process still has that file open, its storage blocks cannot be released until the process closes the file descriptor.

Find these files using:

sudo lsof +L1

Look for entries marked as deleted, particularly those with large file sizes.

For example, an application might still be writing to a deleted 15 GB log file.

The solution is generally to make the responsible process close the file descriptor. Depending on the application, this might require a service reload or restart.

Identify the process first. Avoid killing random processes or restarting critical services without understanding the impact.

6. Check Docker storage consumption

If you run Docker, its storage can quietly grow through unused images, stopped containers, build cache, and volumes.

Start with:

docker system df

For a more detailed breakdown:

docker system df -v

This helps identify which Docker resources are consuming storage.

You can remove unused build cache with:

docker builder prune

To remove unused images:

docker image prune -a

However, understand what these commands remove before executing them.

In particular, Docker volumes can contain persistent application data, including databases. Never assume an unused volume is disposable.

Avoid blindly running aggressive cleanup commands on production servers.

7. Check systemd journal logs

System logs can grow significantly, especially when an application or service repeatedly generates errors.

Check journal storage:

journalctl --disk-usage

If journal storage is excessive, you can limit archived journal storage:

sudo journalctl --vacuum-size=500M

This removes archived journal files until their total size is within the specified limit. Active journal files are not necessarily removed.

For long-term prevention, configure persistent journal limits in:

/etc/systemd/journald.conf

This helps prevent system logs from consuming an unreasonable amount of storage over time.

8. Clean up safely and prevent recurrence

Once you identify the actual culprit, choose a cleanup strategy based on what you discovered.

Problem Recommended approach
Old application logs Configure logrotate
Excessive journal logs Configure journald retention
Docker build cache Use docker builder prune
Unused Docker images Review and prune unused images
Old backups Verify retention and backup integrity
Temporary files Check ownership and application requirements
Deleted files still open Reload or restart the responsible service

Never blindly delete files from /var/lib, database directories, or application data directories. These locations often contain critical application state.

Freeing a few gigabytes is not worth losing a database or breaking a production application.

For long-term prevention, implement:

  • Disk usage monitoring with alerts at 80%, 90%, and 95%.
  • Inode usage monitoring.
  • Log rotation and retention policies.
  • Automated backup retention.
  • Docker image and build-cache maintenance.
  • Application-level log limits.
  • Separate storage for databases, backups, and application data where appropriate.

Monitoring both disk capacity and inode consumption is important. Checking only one leaves a blind spot.

Final thoughts

When a Linux server runs out of disk space, deleting random files is rarely the best first move.

Start with df -hT to identify the affected filesystem, check inodes with df -i, investigate directories using du, and look for hidden storage consumers such as deleted-but-open files, Docker resources, and system logs.

A disciplined investigation is safer and more effective than running random cleanup commands.

The goal isn't simply to free up disk space. It's to understand where the storage went, recover it safely, and prevent the same incident from happening again.

Read more

Authentication vs. Authorization: Understanding the Differences, Importance, and Role of AI in Modern Application Security

Authentication vs. Authorization: Understanding the Differences, Importance, and Role of AI in Modern Application Security

Introduction Security is one of the most important aspects of modern software development. Whether you are building a simple web application, a mobile application, an enterprise platform, or a large-scale SaaS product, protecting user information and controlling access to resources should always be a priority. Two fundamental concepts behind

By Farindra Bahadur Bhandari