GNU bug report logs -
#61884
add an option to du that allows to control which file types are counted
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your bug report
#61884: add an option to du that allows to control which file types are counted
which was filed against the coreutils package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 61884 <at> debbugs.gnu.org.
--
61884: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=61884
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
[Message part 3 (text/plain, inline)]
On 2023-03-04 15:33, Christoph Anton Mitterer wrote:
> But would symlinks (i.e. their length) count for it?
Sure, because you can read symlinks by using readlink, and that gives
you their lengths.
Come to think of it, POSIX specifies st_size only for regular files and
symlinks among the files you'll find in a directory. So du --apparent
should count st_size only for these file types; it should ignore st_size
for other file types unless we know somehow that those sizes make sense
(which for directories is problematic for the reasons you mention).
> What about hardlinked files, would they count once or n times?
That's an independent axis and is handled by -l. Hard links are not a
file type.
> b block (buffered) special
> c character (unbuffered) special
> d directory
> p named pipe (FIFO)
> f regular file
> l symbolic link
> s socket
> D door (Solaris)
I expect Coreutils's already-existing usable_st_function should tell us
which types have usable st_size. This will exclude directories, which
should be the right thing for your use case.
So I installed the attached patch to fix du --apparent to count sizes
only when st_size is well-defined. This should address your use case so
I'm boldly closing the bug report.
[0001-du-apparent-counts-only-symlinks-and-regular.patch (text/x-patch, attachment)]
[Message part 5 (message/rfc822, inline)]
Hey.
When I want to count the nominal sizes of the (usually regular) files
in a directory I do something like:
du --apparent-size --block-size=1
This however also counts in the sizes of the directories themselves
(and I guess also of symlinks, etc.).
The "problem" with that is in particular, that for the exact same
dir/file structure, the results differ e.g. between ext4 and btrfs,
because of different sizes for the directories (themselves).
It would be nice if there was a option that allowed to select which
file types are counted.
Yes I know that one can do something like:
find . -type f -print0 | du --apparent-size -l -c -s --block-size=1 --files0-from=- | tail -n
But that's rather cumbersome... also I cannot do something like
du path1 path2 path3
and get totals for each and a grand summary.
And even if I make an shell alias out of this, I cannot do bash completion on it.
Thanks,
Chris.
This bug report was last modified 2 years and 128 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.