6

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.

Dave
  • 1,036
  • 4
    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 05: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 05: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 05: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 05: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 06:37
  • Thank you very much for your comment Kusalananda! The mentioned backup is performed by fresh formatting the whole target device and copying all files completely new to avoid fragmenting. Therefore after finishing the backup, I want to check if the destination-device has exactly the same amount of data like the source-device has, based on a simple comparison of the file sizes. I just wonder about the difference between the value displayed via du -b and via common file browsers. I don't understand the reason about those differences and want to unify that behaviour to an equal system. – Dave Sep 28 '17 at 06:57
  • @Dave Do you not trust your backup procedure? As long as you count the real file sizes the same way on the source as on the backup, you should be good (as far as the sum of file sizes goes). – Kusalananda Sep 28 '17 at 10:25

1 Answers1

3

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.