Subject: Re: bug#61884: add an option to du that allows to control which file types are counted

From: Christoph Anton Mitterer <[email-masked]>
Date: Fri, 03 Mar 2023 01:21:37 +0100

Hey Glenn

On Thu, 2023-03-02 at 10:20 -0700, Glenn Golden wrote:
> Would something like this work for you?
> 
>     ----------------------------------------------------------------
>     $ echo dir1_file1 > dir1/file1
>     $ echo dir1_file2 > dir1/file2
>     $ echo dir2_file1 > dir2/file1
>     $ echo dir2_file2 > dir2/file2
>     $ echo somefile > fileA
> 
>     $ find dir1 dir2 fileA -not -type d -print0 | xargs --null du -
> hsc
>     4.0K    dir1/file2
>     4.0K    dir1/file1
>     4.0K    dir2/file2
>     4.0K    dir2/file1
>     4.0K    fileA
>     20K     total
>     ----------------------------------------------------------------

TBH, I don't even understand how this should solve the "problem" I've
described above.

Your find would stil return any non-directory files beneath dir1 and
dir2.
Because of xargs, du would see each of them as an argument (and likely
produce undesired results if there are too many files), and
subsequently still print each of them as a -s "total".

But apart from that,... it's clear that one can get the desired results
*somehow*, e.g. I simply use a scrip like that right now:

total_size=0
for pathname in "$@"; do
        size="$(  find "${pathname}" \! -type d -print0  |  du --apparent-size -l -c --block-size=1 --files0-from=-  |  tail -n 1  |  cut -d '  ' -f 1 )"
        total_size="$((  ${size} + ${total_size}  ))"
        
        printf '%s\t%s\n' "${size}" "${pathname}"
done
printf '%s\ttotal\n' "${total_size}"

# (with the -d ' ' being a literal tabulator - $'…' quoting is not (yet) POSIX standardised)

That gets of course ugly if one would have really a lot arguments (many
forked processes).
And it's not something that one can expect to be there per default.

Anyway,... feel free to close the issue.

Cheers,
Chris.