Skip to content

du: double-counting hard links when multiple arguments specified #10241

Closed

Description

@BAMF0

(Forwarded from Launchpad Bug #2132245)

Summary

If a number of directories share hard links (such as backups), du will count these twice if these directories are specified as multiple arguments. In the GNU implementation, du would consider hard links only once if multiple arguments that shared them were supplied.

Reproduce

  1. Create two directories backup_1 and backup_2
mkdir backup_1 backup_2
  1. Populate backup_1 with a file
dd if=/dev/urandom count=256 of=backup_1/file
  1. Create a hard-link of file in backup_2
ln backup_1/file backup_2/
  1. Verify directory sizes individually
# Both directories should be of size 132K when measured individually, depending on directory block size
# - Directory Block Size: 4K
# - Size of file: 128K (default dd block size is 512 -> 256 * 512 = 128K)

$ du -h backup_1
132K    backup_1

$ du -h backup_2
132K    backup_2
  1. Verify directory sizes together
# When measured together we would expect these sizes, depending on directory block size
# - backup_1: 132K (4K + 128K)
# - backup_2: 4K (file is accounted for in backup_1)

$ du -h backup_1 backup_2
132K    backup_1
132K    backup_2 # <- file got measured twice here

$ gnudu -h backup_1 backup_2
132K    backup_1
4.0K    backup_2 # <- GNU implementation accounts for this

System

  • OS release: Ubuntu 26.04 (Development branch)
  • uutils coreutils version: 0.5.0 (built from main commit: 1d6bd99)

Activity

  1. ChrisDryden commented on Jan 15, 2026

    @ChrisDryden
    Collaborator

    Very trivial fix here, need to add an integration test. The vec for tracking the files that have been seen was being overwritten every loop and just needs to be instantiated outside of the loop.

  2. ChrisDryden commented on Jan 19, 2026

    @ChrisDryden
    Collaborator

    Fixed with #10313

  3. Flimm commented on Feb 25, 2026

    @Flimm

    The pull request #10313 with the fix was merged in commit 8d02762 in 19 Jan 2026. It seems this fix was included in the release 0.6.0, based on the output of this command:

    $ git describe --contains 8d027624b29a46d7dc1a864a85b2be5060477df6
    0.6.0~130
    

    However, the version of du shipped by Ubuntu 25.10 seems to be 0.2.2, so this fix has not yet been released in Ubuntu 25.10:

    $ du --version
    du (uutils coreutils) 0.2.2
    

    This matches my experience using du (uutils) on Ubuntu 25.10. I still experience this bug, despite updating all my packages on Ubuntu 25.10. I'm leaving this comment here, for anyone else experiecing this bug. I will comment on the Launchpad bug, and I will ask that the bug report be reopened in Launchpad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions