7

I would like to know why the directory sizes I get when I execute du -sh disagree from the ones the file manager shows. What do they do differently and how big is my data really? I am not so much interested in the size it takes on the disk (because of blocks and stuff), I just want to know how big the actual data is.

6

Short answer: The file manager calculates with units based on 1000, du calculates per default with units based on 1024. Because of this, the file manager views a file of 1024 bytes as "1.024 kB", while du views it as "1.000 kiB". This (literally) multiplies if you think of larger files, for example Megabyte (1000 * 1000) vs. Mibibyte (1024 * 1024) or Gigabyte (1000 * 1000 * 1000) vs. Gibibyte (1024 * 1024 * 1024).

Long answer: The difference stems from the different ways computers and humans count. Most current human societies do their math with the decimal system, on the base of 10. Not all cultures in history did, that's why, for example, we divide the day into 24 hours. But with most things, we use 10, or multiples of 10, or 10 to the n-th power. This is evident in the International system of Units (SI), which uses prefixes to mark 10 ^ 3 = 1000. 1000 gram equals 1 *kilo*gram, the 1000th part of 1 meter equals 1 *milli*meter and so fort. Technical, 1000 kilogram would be 1 "megagram", but traditionally, we use a different word for it, "ton". Still, it is based on 1000.

On the other hand, computers calculate not based on 10, but based on 2 - on/off, power/no power, true/false. Therefore, computers use multiplies and powers of 2 instead of multiplies of 10: 2, 4, 8, 16, 32, 64 and so fort. The power of 2 which is nearest to 1000 is 1024. Because of this, "1 kilobyte" was defined originally not as "1000 byte" as most other units would have been, but as "1024 byte". In the same way, "1 megabyte" originally was "1024 * 1024 byte", "1 gigabyte" originally was "1024 * 1024 * 1024 byte" and so forth.

"Back then", most people who used computers knew about this, and in the order of scales that were used in those days, it didn't make munch of a difference. Whether a file is 1000 bytes "large" or 1024 bytes, doesn't really matter in most cases. But time went on, computers became omnipresent, and the numbers became larger. Today, many computer users don't know about 1000 vs. 1024, or they don't care. It doesn't make too much sense to explain to "Joe Everbody", that with almost everything, "kilo" means "1000 of it", but with computers, it's different. Additionally, the difference starts to get significant. If you compare a "Gigabyte" based on 1000 to a "Gigabyte" based on 1024, the difference is roughly 10%. With "Terabyte" and larger, the difference is an even larger fraction.

Therefore, over the last years many countries decided to differentiate between those two calculation systems. The classical prefixes kilo-, mega-, giga-, tera- etc. are today almost always used based on 1000. So, a file with 1024 bytes would no longer be "1.000 kilobyte", but "1.024 kilobyte". The units based on 1024 got new prefixes, with the first syllable of the "old one" followed by "bi": Kilo -> kibi, mega -> mibi, tera -> tebi and so forth. The symbols are KiB, MiB, TiB and so forth.

Nautilus, Ubuntu's file manager, calculates based on 1000. So it shows your file sizes in kilobytes, megabytes etc. du on the other hand still calculates based on 1024. So with du you see your file sizes in kibibytes, mebibytes etc. And as said above, once we are in the tera- vs. tebi- range and up, it starts to show ;)

du offers the --si switch. It works like -h, but calculates with SI units instead of based on 1024. So

du --si -s my_files/

would give you a size in KB, MB, GB etc., while

du -sh my_files/

would give you a size in KiB, MiB, GiB etc.

0

The right way to find out the right disk space usage is using du command (du -sh). That's because your file manager (like Nautilus) doesn't take into account hidden files.

Or you can use the Disk Usage Analyzer. Use the following command to start it from terminal:

baobab

Disk Usage Analyzer

See also: How to find - Size of a directory & Free disk space.

  • ok, what kind of hidden files are going to be in directories where i don't expect them? Also, baobab and du -sh disagree slightly as well, is there any explanation why that is? – kutschkem Oct 2 '13 at 8:47
  • If i uncheck "allocated space" in baobab, it says the same thing as the file manager. Do i draw he right conclusion that du -sh actually shows me the "space occupied on disk" rather than "size of the actual data"? – kutschkem Oct 2 '13 at 8:58
  • If you use Nautilus, press Ctrl+H when you are in Nautilus and you will see what hidden files do you have. Also you can use ls -a command in terminal to see them. – Radu Rădeanu Oct 2 '13 at 8:58
  • du -sh return the result in MiB (mebibytes)/GiB/KiB and boabab show this values in MB (megabytes)/GB/KB. So, baobab and du -sh disagree only from this point of view. See here what's the differences: wiki.answers.com/Q/Difference_between_megabyte_mebibyte . If you want to see the same results, use: du -s --si instead of du -sh. See also man du. – Radu Rădeanu Oct 2 '13 at 9:17
0

I guess you use Nautilus as the file manager: hidden files are not taken into account. That's a known bug since 2006.

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.