20

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

2 Answers 2

33

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.

0
10

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