I create a file named file.o, i want to check the size of the file.o file.

du -h file.o ====> 4.0K

du -b file.o ====> 1120

according to du -b file.o, i get to know file.o is 1120bytes large. But why du -h file.o outputs 4.0K (means 4*1024 bytes)?

migrated from stackoverflow.com Jan 20 '11 at 11:16

This question came from our site for professional and enthusiast programmers.


The file is smaller, but it takes one whole 4.0K block on the disk (you can have only one file in one block). If its byte size were (for example) 5678 Bytes, it would occupy two 4.0K blocks, i.e. 8.0K.

du -b prints sizes in bytes, overriding the default block size.


To add to eumiro's answer, the block size can be different for each filesystem/partition.

You can find a filesystem's block size using tune2fs -l /dev/<disk> | grep '^Block size' or stat -c "%o" <file on the disk>.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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