du -sh : I don't get why these two results are different

0

I need to know the size of a folder and some of its sub folders. So I'm trying to use the du command.

I cd into the right directory and then try (in bash) :

[xxx@yyy TEST]$ du -sh .
4.1G    .

[xxx@yyy TEST]$ du -sh *AAA
3.2G    123_AAA

[xxx@yyy TEST]$ du -sh . *A
4.1G    .
2.7G    123_AAA

How is it possible that I get different results for the size of 123_AAA (3,2GB then 2,7GB) with my second and my third command ?

Thank you in advance

Maxx

Posted 2015-03-30T14:03:29.357

Reputation: 113

Just to double check, this is GNU du, with no aliasing or funny folder names that start with dashes? – Tobu – 2015-03-30T16:53:34.080

Answers

1

I think du is aware of hardlinks. Try du -shl . *A .

Kamil Maciorowski

Posted 2015-03-30T14:03:29.357

Reputation: 38 429

Thank you, this seems to be it ! Do you know how I find which files are refering to the same inode ? – Maxx – 2015-03-31T12:17:54.600

@Maxx find ./ -xdev -type f -exec ls -i {} \; | sort -n | sed 's/%/%%/g' | awk 'BEGIN {n=-1} {if (n!=$1) printf "\n"; printf $1-n" "$0"\n"; n=$1}' | grep -B 1 ^0 | cut -d \ -f 3- – Kamil Maciorowski – 2015-03-31T17:20:00.653

0

du processes arguments in order and keeps track of inodes so that they are only counted once (or twice if you use -c). I don't see how 123_AAA gets counted when it is listed after ., however. The first explanation I thought of is that symlinks could be treated differently when listed on the command line, but that is with option -D, not the default. Not crossing filesystem borders could be another candidate, but -x isn't enabled by default either.

Tobu

Posted 2015-03-30T14:03:29.357

Reputation: 2 584

-1

I couldn't replicate this error, however, when checking the man pages:

SYNOPSIS
       du [OPTION]... [FILE]...

So I think that you can only have one file argument at a time. Don't know why you're even getting a result for the last command:

wilhelm@server ~ $ du -sh .
2.1G    .
wilhelm@server ~ $ du -h wa
4.0K    wa
wilhelm@server ~ $ du -sh wa
4.0K    wa
wilhelm@server ~ $ du -sh . wa
2.1G    .

Wilhelm Erasmus

Posted 2015-03-30T14:03:29.357

Reputation: 151

2You can give more than one argument. From man du: (du) "Summarize disk usage of each FILE, recursively for directories." Try to do su -sh wa . instead and you should see the two lines one for wa and one for .. The size seems to be divided. Check it with du -hsc wa . and the total should be the same of du -hs .. – Hastur – 2015-03-30T15:10:34.640

That may be correct, but in this specific scenario, the file wa is of neglible size @Hastur – Wilhelm Erasmus – 2015-03-30T18:01:25.697

Even if the file is of a negligible size du will show it to you. It has to be underlined that If you write du -hsc . wa you will see only the line relative to .. If you will instead write su -hsc wa . you will see a line for . and a line for wa. In both cases -c option will give you the (same) grand total below. Btw: This comment are to little and in the previous command I want to write du -sh wa . and not su ... missprint. – Hastur – 2015-03-30T18:17:19.027

@Hastur read it that way facepalm "[xxx@yyy TEST]$ du -sh . *A" does seem to be in the format "du -hsc . wa" though – Wilhelm Erasmus – 2015-03-30T18:58:45.033