GNU bug report logs - #61884
add an option to du that allows to control which file types are counted

Previous Next

Package: coreutils;

Reported by: Christoph Anton Mitterer <calestyo <at> scientia.org>

Date: Wed, 1 Mar 2023 03:20:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


Message #17 received at 61884 <at> debbugs.gnu.org (full text, mbox):

From: Christoph Anton Mitterer <calestyo <at> scientia.org>
To: gdg <at> zplane.com
Cc: 61884 <at> debbugs.gnu.org, Pádraig Brady <P <at> draigbrady.com>
Subject: Re: bug#61884: add an option to du that allows to control which
 file types are counted
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.




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.