Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #269899

Re: tree with dir size

From Franco Martelli <martellif67@gmail.com>
Newsgroups linux.debian.user
Subject Re: tree with dir size
Date 2024-06-03 22:50 +0200
Message-ID <ILmMV-o6h-1@gated-at.bofh.it> (permalink)
References (4 earlier) <IJY9X-h0Cm-5@gated-at.bofh.it> <IKfXb-hhoO-1@gated-at.bofh.it> <IKgJz-hhTQ-25@gated-at.bofh.it> <ILgo9-kbf-1@gated-at.bofh.it> <ILh0R-kDd-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 03/06/24 at 16:32, Greg Wooledge wrote:
> duhs() {
>      shopt -s dotglob
>      printf '%s\0' "${1:-.}"/*/ | xargs -0 du -sh
>      shopt -u dotglob
> }
> 
> But this assumes that the option was*not*  already on when we entered
> the function.  If it was on, we've just turned it off.  Another way to
> do this, which doesn't permanently alter the option for the remainder
> of the shell's lifetime, would be to wrap the function body in a subshell:
> 
> 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:

duhs1() { IFS=$'\n\r' ; for d in $(/usr/bin/find $1 -maxdepth 1 -type d 
|/usr/bin/sort) ; do du -hs $d ; done }

~# duhs1 /usr/local/
88K     /usr/local/     ←←←
4,0K    /usr/local/bin
4,0K    /usr/local/etc
...

According to the very kind Greg's explanation I tried to change the 
function in this way:

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

the specified directory is shown, but the output has became messed up:

~# 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/
56K     /usr/local//share/
4,0K    /usr/local//src/

and worst the size of /usr/local/share isn't 56K:

~# du -hs /usr/local/share/
60K     /usr/local/share/

as it's shown by my original function:

~# duhs1 /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/sbin
60K     /usr/local/share
4,0K    /usr/local/src

the /usr/local/man/ isn't listed by the "find" command because it's a 
symlink:

~# ls -l /usr/local/man
lrwxrwxrwx 1 root root 9 21 giu  2023 /usr/local/man -> share/man

Is there a way to have duhs() function that it doesn't print a double 
"/" at the end of the specified directory?
The size mismatch of /usr/local/share could depend by /usr/local/man is 
a symlink of 4K's size to a directory embedded in /usr/local/share, am I 
right?

Cheers,
-- 
Franco Martelli

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

tree with dir size Northwind <nw@secubox.org> - 2024-05-31 00:30 +0200
  Re: tree with dir size eben@gmx.us - 2024-05-31 01:00 +0200
    Re: tree with dir size Greg Wooledge <greg@wooledge.org> - 2024-05-31 01:00 +0200
      Re: tree with dir size Northwind <nw@secubox.org> - 2024-05-31 01:00 +0200
        Re: tree with dir size Greg Wooledge <greg@wooledge.org> - 2024-05-31 01:10 +0200
      Re: tree with dir size eben@gmx.us - 2024-05-31 02:10 +0200
        Re: tree with dir size Greg Wooledge <greg@wooledge.org> - 2024-05-31 02:20 +0200
          Re: tree with dir size Franco Martelli <martellif67@gmail.com> - 2024-05-31 21:20 +0200
            Re: tree with dir size Greg Wooledge <greg@wooledge.org> - 2024-05-31 22:10 +0200
              Re: tree with dir size David Wright <deblis@lionunicorn.co.uk> - 2024-06-01 04:40 +0200
                Re: tree with dir size Greg Wooledge <greg@wooledge.org> - 2024-06-01 05:20 +0200
                Re: tree with dir size Lee <ler762@gmail.com> - 2024-06-01 16:20 +0200
              Re: tree with dir size Franco Martelli <martellif67@gmail.com> - 2024-06-03 16:00 +0200
                Re: tree with dir size Greg Wooledge <greg@wooledge.org> - 2024-06-03 16:40 +0200
                Re: tree with dir size Greg Wooledge <greg@wooledge.org> - 2024-06-03 21:10 +0200
                Re: tree with dir size David Wright <deblis@lionunicorn.co.uk> - 2024-06-04 02:40 +0200
                Re: tree with dir size Franco Martelli <martellif67@gmail.com> - 2024-06-03 22:50 +0200
                Re: tree with dir size Greg Wooledge <greg@wooledge.org> - 2024-06-04 00:30 +0200
                Re: tree with dir size Greg Wooledge <greg@wooledge.org> - 2024-06-04 03:50 +0200
                Re: tree with dir size Greg Wooledge <greg@wooledge.org> - 2024-06-04 16:50 +0200
                Re: tree with dir size Franco Martelli <martellif67@gmail.com> - 2024-06-04 16:50 +0200
                Re: tree with dir size Andy Smith <andy@strugglers.net> - 2024-06-03 16:40 +0200
                Re: tree with dir size <tomas@tuxteam.de> - 2024-06-03 19:10 +0200
                Re: tree with dir size Franco Martelli <martellif67@gmail.com> - 2024-06-03 23:00 +0200
                Re: tree with dir size <tomas@tuxteam.de> - 2024-06-03 16:40 +0200
  Re: tree with dir size Sridhar M A <alaymari@gmail.com> - 2024-05-31 02:50 +0200
  Re: tree with dir size Felix Miata <mrmazda@earthlink.net> - 2024-05-31 03:30 +0200

csiph-web