On Fri, 4 Oct 2019 21:59:07 -0400 David T-G <davidtg-robot@justpickone.org> wrote:
Hi, all --
I know that this isn't SuSE-specific, but everyone here loves a puzzle :-) I have a collection of directories with varying contents; most but not all have files in them, and many of interest have subdirs in them. Here's a sample set:
davidtg@u17383850:/tmp/TEST> du -ka * 16404 2019-0203/file 32804 2019-0203/DIR-100/content 32808 2019-0203/DIR-100 32804 2019-0203/DIR-23W/content 32808 2019-0203/DIR-23W 32804 2019-0203/DIR-A05/content 32808 2019-0203/DIR-A05 114832 2019-0203 16404 2019-0312/file 16408 2019-0312 32804 2019-0416/DIR-209/content 32808 2019-0416/DIR-209 16404 2019-0416/file 16404 2019-0416/other 65620 2019-0416 4 2019-0611 32804 2019-0817/DIR-209/content 32808 2019-0817/DIR-209 16404 2019-0817/file 32804 2019-0817/DIR-941/content 32808 2019-0817/DIR-941 32804 2019-0817/DIR-PXD/content 32808 2019-0817/DIR-PXD 114832 2019-0817 16404 2019-0924/file 16404 2019-0924/other 32812 2019-0924
I want to get a du total for all of the DIR-* subdirs, grouped by parent, without throwing any errors. The simple version obviously doesn't work:
davidtg@u17383850:/tmp/TEST> for D in 2* ; do du -skhc $D/DIR-* ; done 33M 2019-0203/DIR-100 33M 2019-0203/DIR-23W 33M 2019-0203/DIR-A05 97M total du: cannot access `2019-0312/DIR-*': No such file or directory 0 total 33M 2019-0416/DIR-209 33M total du: cannot access `2019-0611/DIR-*': No such file or directory 0 total 33M 2019-0817/DIR-209 33M 2019-0817/DIR-941 33M 2019-0817/DIR-PXD 97M total du: cannot access `2019-0924/DIR-*': No such file or directory 0 total
The best I've found in ten minutes of thinking is to use case to test a globbing of the list to see if it's still the input, but that seems ... ugly :-)
davidtg@u17383850:/tmp/TEST> for D in 2* ; do DIRS=`echo $D/DIR-*` ; case "$DIRS" in *\* ) continue ;; esac ; du -skhc $D/DIR* ; done 33M 2019-0203/DIR-100 33M 2019-0203/DIR-23W 33M 2019-0203/DIR-A05 97M total 33M 2019-0416/DIR-209 33M total 33M 2019-0817/DIR-209 33M 2019-0817/DIR-941 33M 2019-0817/DIR-PXD 97M total
I'm not clear whether the two occurrences of DIR-209 are separate and to be counted twice, or refer to the same thing and should be counted once? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org