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

  • Just to double check, this is GNU du, with no aliasing or funny folder names that start with dashes? – Tobu Mar 30 '15 at 16:53

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

  • Thank you, this seems to be it ! Do you know how I find which files are refering to the same inode ? – Maxx Mar 31 '15 at 12:17
  • @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 Mar 31 '15 at 17:20

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.


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

       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    .
  • 2
    You 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 Mar 30 '15 at 15:10
  • That may be correct, but in this specific scenario, the file wa is of neglible size @Hastur – Wilhelm Erasmus Mar 30 '15 at 18:01
  • 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 Mar 30 '15 at 18:17
  • @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 Mar 30 '15 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.