3

This question already has an answer here:

The command

du -b /home/user/directory

shows a completely different file size than displayed by a manual "right click" on the same directory and selecting "Properties" inside common file browsers like Nautilus, PCManFM, Windows Explorer or others.


Examples for requesting the file size:

  • Via file browser: "Right click" ⇨ "Properties" on a directory shows an apparent (real) file size of 8.141.120 bytes. On the other hand, the used disk space has 8.155.136 bytes and is a bit higher (because of fragmenting etc.).
  • Via du -b: Shows an inexplicable size of 8.145.216 bytes (which is neither the apparent size nor the used disk space of the previous method with file browser).

I already know that the du-command will display the used disk space instead of the apparent size of the directory. With du -b one can change that default behavior to display the apparent (real) size instead. Nevertheless, in "Properties", both the real size as well as the used disk space are completely different from the mentioned output of du -b.


What is the reason for that? Which CLI-command do I have to use if I want to show the real (apparent) file or directory size which has exactly the same value like displayed in file browsers via "Right click" ⇨ "Properties"?

I ask for that because I want to create some simple bash script to compare the real sizes of content on HDD1 and HDD2 after performing a backup. This should be compared within a high possible bit accuracy. A comparison of the used disk spaces won't make sense in that case, because they are very different on both drives.

marked as duplicate by Archemar, Stephen Rauch, GAD3R, Anthon, xhienne Sep 28 '17 at 10:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    Right click in what? You know, if I run ls in a terminal and I'm right-click on a directory I don't get any information about size. :) Please don't assume people reading your question can look over your shoulder to understand what you're doing. – Satō Katsura Sep 28 '17 at 5:20
  • Thank you very much Sato! You are right, I updated my description. Would be nice if you could remove your downvoting. :-) – Dave Sep 28 '17 at 5:27
  • Hello Archemar! Thanks a lot for your advice! Unfortunately not a duplicate, because I still don't know how to display the file size of a folder via du or ls to get the same (!) value like displayed in file browsers file properties... – Dave Sep 28 '17 at 5:36
  • @Dave 1. I didn't downvote your question. 2. I'm supposed to be SatōKatsura, Sato is somebody else (two people from a quick search? not sure how that's even possible). – Satō Katsura Sep 28 '17 at 5:38
  • The backup tool that you have should provide a way for you to verify the contents of the backup, if that's what you are trying to do. If it does not, then switch to one that does. Do provide more information about what it is you are actually intending to do. – Kusalananda Sep 28 '17 at 6:37
2

The difference between 8,145,216 bytes and 8,141,120 bytes is 4,096 bytes, exactly 4kB. Directories are stored in blocks of 4kB in ext4, which suggests the directory in your example has a relatively small number of files and no subdirectories.

du is including this 4kB in its output, whereas it seems from my own testing that file managers, like Nautilus, don't.

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