[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: tree with dir size



On 04/06/24 at 03:48, Greg Wooledge wrote:
On Mon, Jun 03, 2024 at 07:42:17PM -0500, David Wright wrote:
On Mon 03 Jun 2024 at 18:29:17 (-0400), Greg Wooledge wrote:
‘-s’
‘--summarize’
      Display only a total for each argument.

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

Try adding -l. The idea is that du is trying to avoid double-counting,
so when the subdirectories come first, those ones are "used up" by
the time it reaches the parent. When the parent is first, it's (all)
the subdirectories instead that have been "used up".

‘-l’
‘--count-links’
      Count the size of all files, even if they have appeared already (as
      a hard link).

This documentation leaves a lot to be desired.

Anyway, you are correct about the result, even if the documentation gives
no realistic way to conclude such a result.

hobbit:~$ printf '%s\0' "${1:-.}" "${1:-.}"/*/ | xargs -0 du -shl
684M    /usr/local
81M     /usr/local/bin/
4.0K    /usr/local/etc/
4.0K    /usr/local/games/
136K    /usr/local/include/
45M     /usr/local/lib/
29M     /usr/local/man/
8.0K    /usr/local/sbin/
31M     /usr/local/share/
484M    /usr/local/src/
44M     /usr/local/tcl8.6/


FYI the revision of duhs() I adopt is:

duhs() { ( shopt -s dotglob; printf '%s\0' "${1:-.}" "${1:-.}"*/ | xargs -0 du -shl ) } ↑

Please note that I dropped a "/" in the "${1:-.}"/*/ block because the directories listed had a double "//" in their names:

~# duhs /usr/local/
88K     /usr/local/
4,0K    /usr/local//bin/
4,0K    /usr/local//etc/
4,0K    /usr/local//games/
4,0K    /usr/local//include/
4,0K    /usr/local//man/
4,0K    /usr/local//sbin/
60K     /usr/local//share/
4,0K    /usr/local//src/

Thank again,
Cheers,
--
Franco Martelli


Reply to: