Discrepancy in Disk Usage Between du and ls Commands in Linux: Possible Explanations

Abstract: Explains why du reports higher disk usage than ls due to block allocation, sparse files, and directory overhead.

Created: 2026-10-20 by

The discrepancy between du and ls disk usage reports stems from their fundamental differences in measurement: ls -l displays the logical file size stored in the inode metadata, while du calculates the actual physical blocks allocated on the filesystem. This difference is normal and occurs because du accounts for block alignment padding, sparse files, hard links, and directory overhead that ls ignores entirely.

Understanding Logical vs. Physical Size

To resolve confusion about storage consumption, you must distinguish between the data content and the storage allocation. The ls command, specifically when using the -l flag to list details, reads the file's metadata. It reports the number of bytes contained within the file itself. If you create a 10-megabyte text file, ls will report exactly 10,485,760 bytes. This number represents the logical size, which is what applications see when they open and read the file. In contrast, the du (disk usage) command interacts with the filesystem driver to determine how much space the file actually consumes on the disk. Modern Linux filesystems like ext4 or XFS allocate space in fixed-size blocks, typically 4 kilobytes. The filesystem cannot allocate partial blocks; it must round up to the nearest block boundary. Therefore, even a tiny file containing a single byte might consume one full 4-kilobyte block. When du sums these allocations, it often yields a larger number than the sum of logical sizes reported by ls. This distinction becomes critical when dealing with large directories. While ls simply lists individual file sizes, du traverses the directory tree recursively. It adds up every block used by every file and subdirectory. Consequently, du provides an accurate picture of how much free space remains on your partition, whereas ls only tells you how much data is inside the files.

Block Allocation and Padding

The most common cause of the discrepancy is block alignment. Consider a scenario where you have multiple small files. Each file requires at least one block. If you have ten 1-byte files, ls shows a total of 10 bytes. However, du sees ten blocks, resulting in approximately 40 kilobytes of usage. This padding effect scales with the number of files. In environments with millions of small objects, such as package managers or git repositories, the difference between logical and physical size can be substantial. Furthermore, directory entries themselves take up space. Directories are special files that contain mappings of filenames to inodes. du includes the space consumed by these directory structures in its calculation. ls, when listing a directory, does not include the size of the directory entry itself in the output for the files inside it. This means du always reflects the true cost of storing the directory structure, while ls focuses solely on the payload data.

Sparse Files and Hole Punching

A more complex factor involves sparse files. A sparse file is one where the filesystem allocates blocks for written data but leaves gaps (holes) unallocated. These holes appear as zeros when read but consume no physical disk space. The ls command reports the apparent size, including the holes. If you create a 1-terabyte sparse file, ls will show 1TB. However, if the file contains only 1 megabyte of actual data, du will report approximately 1MB. This behavior is intentional and beneficial for virtual machine images, database files, and backup archives. It allows applications to pre-allocate large files without immediately consuming the corresponding disk capacity. Understanding this mechanism prevents panic when du reports significantly less space than ls suggests. It indicates that the file is sparse and has "holes" that do not occupy physical sectors on the drive.

Hard Links and Shared Data

Hard links further complicate the comparison. A hard link is another name for the same inode. Multiple filenames can point to the exact same data blocks. ls treats each filename as a separate entity and reports its full size independently. If you have five hard links to a 1GB file, ls might make it seem like there are 5GB of data if you manually sum them up incorrectly. du, however, tracks inode usage. By default, du counts the data only once per inode, regardless of how many hard links exist. To see the impact of hard links on directory traversal, you can use the --inodes flag or refer to our guide on Understanding the Hardlinks Field of a Directory. This helps clarify why du might report less space than expected when many symlinks or hard links are present. Note that symbolic links are different; du typically follows them or skips them depending on flags, while ls shows the link target size.

Interpreting the Results Correctly

When troubleshooting storage issues, always trust du` over ls. If your disk is full, du identifies the culprits accurately. ls is useful for auditing file contents and permissions but misleading for capacity planning. Use du -sh to get a human-readable summary of a specific directory. For detailed breakdowns, du --max-depth=1 reveals which subdirectories are consuming the most blocks. If you suspect hidden files or permissions are affecting visibility, ensure you are running commands with appropriate privileges. Sometimes du cannot access certain directories due to permission errors, leading to underreported sizes. Using sudo du ensures a complete count. Additionally, remember that deleted files still hold blocks until the process holding them closes. du will continue to report their usage until the file descriptor is released, a nuance often missed when relying on ls output.

Frequently Asked Questions

Why does du show more space used than ls?

du reports the physical blocks allocated on the disk, which includes block alignment padding and directory overhead. ls only shows the logical file size stored in the metadata. The extra space reported by du is the inevitable waste from rounding file sizes up to the filesystem's block size.

Can du and ls ever show the exact same number?

Yes, if a file's size is an exact multiple of the filesystem block size and there is no directory overhead to consider, the numbers may align closely. However, du usually includes the size of the directory entry itself, making it slightly larger than the sum of file sizes shown by ls in most practical scenarios.

How do I handle sparse files when checking disk usage?

Use du -h to see the actual physical usage, which ignores the holes in sparse files. If you need to know the apparent size for application compatibility, rely on ls -lh. Be aware that creating sparse files can lead to a situation where du shows low usage while ls suggests high usage, which is normal behavior.

Does du follow symbolic links by default?

By default, du does not follow symbolic links to avoid infinite loops and double-counting. It reports the size of the link itself, which is negligible. To include the size of linked targets, use the -L flag, though this can lead to inaccurate totals if circular links exist.

What should I do if du reports zero for a directory?

If du reports zero but ls shows files, you likely lack read permissions for those files. Run the command with sudo to bypass permission restrictions. Alternatively, check if the files are mounted via a network filesystem that is currently unreachable, causing du to fail silently.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More