Skip to content

du: du -l doesn't count hardlinked files separately #9871

@ChrisDryden

Description

@ChrisDryden

The -l / --count-links option should count hardlinked files multiple times, but currently it produces the same output as without the flag.

mkdir test && cd test
dd if=/dev/zero of=file1 bs=1k count=64 2>/dev/null
ln file1 file1.1
dd if=/dev/zero of=file2 bs=1k count=16 2>/dev/null
$ du .
84	.
$ du -l .
84	.      # should be ~148 (64+64+16 + overhead)
$ /bin/du -l .
148	.      # GNU outputs correct value

The bug is in src/uu/du/src/du.rs around line 504:

if seen_inodes.contains(&inode) && (!options.count_links || !options.all) {

When count_links=true and all=false (default), this evaluates to (false || true) = true, so the file still gets skipped and its size isn't added. The -l flag only works when combined with -a.

This also corresponds to the busybox test: du-l-works

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions