Hi Sorin,
On 2023-04-28 you wrote:
> When specifying multiple entries on the command line if one of the file
> folders is a subfolder of a previous parameter it will not show any
> information about it. This is relevant when using max-depth.
> Ex:
> du -sh folder folder/subfolder
> Will only show one entry which is the size of folder. If order is reversed
> du -sh folder/subfolder folder will work as expected.
> Another example:
> du -sh .*
> This will only show sizes for . and .. everything else being in the current
> folder being a subfolder will not work.
Apologies for being 3 years late. Someone on the GitHub mirror linked
this bug report. I went into more detail there, but I will try to
explain a bit here as well [1].
You are using the '-s' option which means only command line arguments
are listed. In your second invocation:
du -sh .*
This means that only the directory entries matching the glob are listed,
not their children. Here is an example:
$ mkdir -p tmp/dir{1..3}/subdir{1..3}
$ cd tmp
$ du -sh *
0 dir1
0 dir2
0 dir3
If you remove the '-s' option all of the children will also be listed:
$ du -h * | tee >(wc -l)
0 dir1/subdir1
0 dir1/subdir2
0 dir1/subdir3
0 dir1
[...]
12
The other command is a bit of a gotcha. Looking at this command:
$ du -sh dir1/subdir1 dir1
0 dir1/subdir1
0 dir1
In this case 'du' visits dir1/subdir1 first and prints it since it has
not been visited before.
However, looking at this command:
$ du -sh dir1 dir1/subdir1
0 dir1
In this case 'du' visits dir1 and all of its children, including
dir1/subdir1. Since dir1/subdir1 is visited as a child of dir1 and we
are using '-s', it is not printed. After finishing dir and its children,
'du' tries to visit dir1/subdir1 as given by the command line. However,
since it has already been seen it does not get visited again, and is
never printed.
Collin
[1] https://github.com/coreutils/coreutils/issues/257#issuecomment-4357575747