Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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)?

share|improve this question

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

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

2 Answers 2

up vote 30 down vote accepted

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.

share|improve this answer

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>.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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