On Mon, Jun 03, 2024 at 10:45:28PM +0200, Franco Martelli wrote:
> On 03/06/24 at 16:32, Greg Wooledge wrote:
> > duhs() {
> >      (
> >        shopt -s dotglob
> >        printf '%s\0' "${1:-.}"/*/ | xargs -0 du -sh
> >      )
> > }
> 
> I've some issue with this function. It doesn't show the size of the
> directory specified as argument, it follows the output of my original
> function:

I started writing a response to this, because it seemed easy enough to
fix -- just add "${1:-.}" to the printf arguments, so it gets passed
along to du -sh, and included in the output.

But then I tested it.

hobbit:~$ du -sh /usr/local /usr/local/bin
684M    /usr/local

What?  Where's the second line?

hobbit:~$ du -sh /usr/local/bin /usr/local/etc
81M     /usr/local/bin
4.0K    /usr/local/etc

Multiple arguments are allowed....

hobbit:~$ du -sh /usr/local/bin /usr/local/etc /usr/local
81M     /usr/local/bin
4.0K    /usr/local/etc
603M    /usr/local

You're even allowed to have a parent directory after its children...

hobbit:~$ du -sh /usr/local /usr/local/bin /usr/local/etc
684M    /usr/local

... but if the parent is FIRST, the children get... swallowed up by
it?  Huh?  And if the parent is last, then the value shown for the
parent excludes the children that were already reported on?

Why the HELL is it like this?!

It doesn't even match its own documentation.  Here's what the info
page says:

‘-s’
‘--summarize’
     Display only a total for each argument.

There's supposed to be a total *FOR EACH ARGUMENT*.  There isn't.

OK, I officially wash my hands of ANY solution based on du -s.  If
you want to try to make it work sensibly, more power to you.  As far
as I'm concerned, though, this is broken.  Irreparably broken.

It looks like tree(1) is less broken, so it might be better to stick
with that, even if you have to pipe the output through grep to get what
you want.

*Sigh*.

Reply via email to