Linux df Shows More Disk Usage Than du? Find the Missing Space

Linux df Shows More Disk Usage Than du? Find the Missing Space

A Linux server can report that a filesystem is almost full even when the visible files do not appear large enough to explain the reported usage. You run df -h and see that the disk is using 90% of its capacity, but du reports significantly less storage consumption.

This situation is confusing, particularly when a server displays errors such as:

No space left on device

The difference usually comes from how Linux measures filesystem usage. The df command reports space used and available on an entire filesystem, while du estimates storage consumed by files and directories that it can access.

One of the most common reasons for a large discrepancy is a deleted file that a running process still has open. Other causes include insufficient permissions, exhausted inodes, mounted filesystems, reserved filesystem space, and snapshots.

This guide explains how to diagnose the difference between df and du, identify the actual source of disk usage, and recover storage safely without deleting important application or database files.

Why df and du Report Different Disk Usage

The two commands measure different aspects of storage usage.

What does df measure?

The df command reports filesystem-level information, including:

  • Total filesystem capacity
  • Used blocks
  • Available blocks
  • Filesystem usage percentage
  • Filesystem mount points

For example:

df -h

Example output:

Filesystem      Size  Used  Avail  Use%
/dev/sda2        50G   42G    5G    90%

This indicates that the filesystem has 50 GB of total capacity and approximately 42 GB of reported used space.

What does du measure?

The du command estimates the storage used by files and directories.

For example:

sudo du -sh /var

Example output:

/var    18G

If df reports 42 GB used while du reports only 18 GB for the directory you inspected, the numbers are not necessarily contradictory. You may have checked only one directory, or some allocated filesystem blocks may not be represented by visible files.

The GNU Coreutils documentation explains the separate purposes of df and du.

Compare the Same Linux Filesystem

Before investigating advanced causes, make sure both commands examine the same filesystem.

Start by checking filesystem types and mount points:

df -hT

Then inspect the filesystem containing the directory you are investigating:

df -hT /var

For a directory-level breakdown, use:

sudo du -x -h --max-depth=1 /var 2>/dev/null | sort -h

The options mean:

  • -x: Stay on the filesystem containing the starting directory.
  • -h: Display human-readable sizes.
  • --max-depth=1: Show immediate subdirectories.
  • sort -h: Sort sizes from smaller to larger.

You can investigate the largest directory further:

sudo du -x -h --max-depth=1 /var/log 2>/dev/null | sort -h

For a root filesystem investigation, use:

sudo du -x -h --max-depth=1 / 2>/dev/null | sort -h

The -x option is important when the system has several mounted filesystems. Without it, du may include directories from other filesystems, making the comparison misleading.

Running du with sudo also helps avoid undercounting directories that the current user cannot access.

Find Deleted Files Still Held Open

A deleted file can continue consuming disk space when a running process still has it open.

This is one of the most important causes of the Linux df and du mismatch.

How does this happen?

Consider a web server that writes application messages to a large log file.

An administrator deletes the log:

sudo rm /var/log/application.log

The directory entry disappears, but the web server still has an open file descriptor referencing the original file.

Linux does not release the file’s allocated storage until the final open reference is closed.

As a result:

  • ls no longer displays the file.
  • du cannot count it through the directory tree.
  • df continues reporting the allocated filesystem blocks.

This behavior is defined by the Linux unlink() system call. See the unlink(2) manual page.

1. Install lsof if necessary

The lsof utility lists files opened by running processes.

On Debian or Ubuntu:

sudo apt update
sudo apt install lsof

On RHEL-compatible distributions:

sudo dnf install lsof

2. Find deleted but open files

Run:

sudo lsof -nP +L1

The +L1 option tells lsof to display open files whose link count is less than one.

Example output:

COMMAND  PID   USER  FD  TYPE  SIZE/OFF  NLINK  NAME
nginx    1450  root  5w  REG   536870912  0     /var/log/nginx/access.log (deleted)

Important columns:

ColumnMeaning
COMMANDProcess holding the file open
PIDProcess identification number
FDFile descriptor
TYPEType of opened object
SIZE/OFFFile size or current offset
NLINKNumber of remaining hard links
NAMEFile name or reported path

In this example, the nginx process still holds a deleted log file that occupies approximately 512 MB.

Pay attention to the filesystem and file type. Not every deleted entry reported by lsof represents ordinary disk consumption; confirm that the entry is a regular file on the affected filesystem.

3. Identify the responsible process

Use the PID from the output:

ps -fp 1450

You can also inspect the corresponding systemd service if you know its name:

sudo systemctl status nginx

Do not assume that every deleted file belongs to a log service. Databases, application servers, and other processes can also hold deleted files open.

Check for Inode Exhaustion

Sometimes Linux reports that no space is available even when df -h shows free disk capacity.

This can happen when the filesystem runs out of inodes.

An inode stores metadata about a filesystem object, such as its owner, permissions, timestamps, and references to data blocks.

A filesystem can run out of inodes when it contains an enormous number of small files, even if those files consume relatively little storage.

1. Check inode usage

Run:

df -i

Example:

Filesystem     Inodes   IUsed   IFree  IUse%
/dev/sda2      3200000  3200000  0     100%

The filesystem has exhausted its available inodes.

2. Identify directories containing many files

GNU du supports inode counting:

sudo du --inodes -x --max-depth=1 /var 2>/dev/null | sort -n

This can help identify directories containing large numbers of filesystem objects.

Investigate the largest directories before removing anything.

Common sources include:

  • Application cache directories
  • Temporary files
  • Mail queues
  • Session files
  • Monitoring data
  • Application-generated small log files

Do not use broad deletion commands without understanding what creates the files and whether an application depends on them.

Investigate Mounted and Hidden Directories

A mounted filesystem can hide files that already existed underneath its mount point.

For example, suppose a directory /mnt/storage contains files on the root filesystem. Later, another filesystem is mounted at /mnt/storage.

The mounted filesystem becomes visible through that path, while the original directory contents underneath it are hidden from normal directory traversal.

This can produce a discrepancy when investigating the root filesystem.

1. Inspect mount points

Run:

findmnt -R /

To identify the filesystem associated with a particular path:

findmnt -T /mnt/storage

Review the output alongside:

df -hT

Check whether multiple filesystems, bind mounts, or nested mounts affect the directory structure.

2. Investigate before unmounting

Do not unmount a production filesystem simply to inspect the directory underneath it.

Unmounting can interrupt services, applications, databases, and users who depend on that mount.

Plan any deeper investigation during an approved maintenance window and verify which services use the filesystem first.

Understand Reserved Filesystem Space

Some Linux filesystems reserve part of their capacity for privileged system operations.

For example, ext4 filesystems can reserve a percentage of blocks for privileged processes.

This reserve can make the available space for ordinary users lower than expected.

Check the filesystem type:

df -hT /

For an ext4 filesystem, inspect its configuration with:

sudo tune2fs -l /dev/sda2

Replace /dev/sda2 with the actual ext4 device identified on your system.

Look for the reserved block count and percentage.

Reserved blocks primarily explain why the Avail column can be lower than expected. They should not automatically be treated as the cause of a large difference in the Used values reported by df and du.

Do not change reserved-block settings on a production filesystem without understanding the operating system’s recovery requirements.

How to Recover Disk Space Safely

Once you identify the cause, choose a solution appropriate to the affected process and filesystem.

1. Release deleted log files held by a process

The preferred approach is to make the responsible application close or reopen its old log file.

Depending on the application, this may involve:

  • Using its supported log-reopen signal.
  • Reloading the relevant service.
  • Restarting the service during an approved maintenance window.

For example, after confirming that nginx is holding a deleted log file:

sudo systemctl reload nginx

The exact procedure depends on the application and its logging configuration.

Verify the result:

sudo lsof -nP +L1
df -hT /var

A successful log reopen should release the old file once no process retains an open reference to it.

Important: Never blindly restart or terminate a process simply because it appears in lsof. Identify the service and its role first. Database files require particular care and must not be treated as ordinary disposable logs.

2. Fix the source of excessive log growth

If applications repeatedly generate large logs, fix the underlying issue rather than repeatedly deleting files.

Possible solutions include:

  • Configure log rotation.
  • Reduce unnecessary debug logging.
  • Correct recurring application errors.
  • Set appropriate retention periods.
  • Monitor filesystem usage.

For Docker environments, see our related guide on Docker Logs Taking Too Much Disk Space once that article is published.

3. Clean up inode-heavy directories carefully

If inode exhaustion is the problem, identify the application generating excessive files.

Use the application’s supported cleanup procedure or retention settings.

Avoid deleting unknown files from directories such as /var/lib, where databases and system services may store important state.

4. Review filesystem and storage architecture

If the storage usage is caused by legitimate application data, repeated cleanup may not solve the underlying capacity problem.

Consider:

  • Expanding the filesystem.
  • Extending an LVM logical volume.
  • Increasing the attached storage volume.
  • Reviewing backup and snapshot retention.
  • Moving appropriate application data to a separate filesystem.

For broader storage and filesystem administration, see Linux File System Explained and our Linux Server Administration Complete Guide.

Common Troubleshooting Mistakes

Assuming df and du must show identical numbers

They report different filesystem information. Small differences are normal, and large differences require investigation rather than immediate deletion.

Deleting a log file that is still open

Deleting the directory entry does not necessarily release the storage. Identify the process holding the file and use its supported log-reopen or restart procedure.

Ignoring inode usage

A filesystem can have available bytes but no free inodes. Always check df -i when applications report that no space is available.

Running du across multiple filesystems

Use -x when comparing a particular filesystem with df. Otherwise, directory totals may include mounted filesystems.

Deleting files from system directories without verification

Never remove files from /var/lib, database directories, or application storage simply because they appear large. Determine what owns the files and whether they are safe to remove.

Frequently Asked Questions

Why does df show more disk usage than du?

df reports filesystem-level block usage, while du estimates usage by traversing visible files and directories. Deleted files held open by running processes, mount points, permissions, filesystem metadata, and snapshots can cause differences.

How do I find deleted files still using disk space in Linux?

Run:

sudo lsof -nP +L1

Inspect the process, file size, link count, and filesystem. An open regular file with a link count of zero may still consume disk space.

Does deleting a file immediately free disk space in Linux?

Not always. If a process still has the file open, the filesystem retains its data until the final open reference is closed.

What is the difference between df -h and du -sh?

df -h reports filesystem capacity and usage in human-readable units. du -sh estimates the storage used by a specified directory or file tree.

Why does Linux report no space left when free disk space remains?

Possible reasons include inode exhaustion, filesystem quotas, reserved blocks, or a full filesystem different from the one you inspected. Check both df -h and df -i, and verify the filesystem used by the affected application.

Can restarting a service free deleted log files?

Yes, when that service is the last process holding the deleted file open. A supported log-reopen or reload operation may be sufficient; otherwise, a controlled restart may be necessary.

Conclusion

When Linux reports more disk usage through df than you can explain with du, the correct response is to investigate the filesystem rather than immediately delete more files.

Start by comparing the same mount point, then check for deleted files still held open with lsof, inode exhaustion with df -i, and unexpected mounted directories with findmnt.

Once the actual cause is identified, use the application’s supported cleanup or log-management procedure and verify the result with df.

Understanding how Linux manages file descriptors, inodes, and filesystem blocks makes disk-space troubleshooting safer and more predictable.

Leave a Reply

Your email address will not be published. Required fields are marked *