Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Possible Duplicate:
Directory size calculation difference

I don't understand how the du command under Linux works. I wanted to count the overall size of a few hundred, small files and du -sh returned something along the lines of 150MB. I didn't question it until I realized my file manager displayed only around 50MB for the same set of data and I got confused.

Here's what I then tried:

fkochem@WK-6:~/temp$ cat test 
a
fkochem@WK-6:~/temp$ du -sh test 
4.0K    test

So, now this must be a mistake? I looked at du -sh * of my original data and found the following:

4.0K    NCO-0.9.9.9.json
4.0K    NCO-0.99.9.json
4.0K    NCO-0.9.9.json
8.0K    NCO-0.99.json
8.0K    NCO-0.9.json

Why does du seem to count in 4KB steps? What am I missing here?

share|improve this question
    
4k is the size of a single disk block. Disk space is allocated in blocks, so even the smallest disk takes up one block (4k) on your disk. –  Paul Tomblin Mar 16 '12 at 12:40
add comment

marked as duplicate by manatwork, Ignacio Vazquez-Abrams, Mat, Michael Mrozek Mar 16 '12 at 13:55

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.

1 Answer

up vote 3 down vote accepted

du is disk usage, and it counts that amount of disk allocated to the file. The minimum "block size" (i.e. the minimum chunk allocated to a file) is usually 4k. So the file-system counts in 4k chunks, not du.

It would count in 1k chunks if you formatted a drive as follows:

mke2fs -b 1024 /dev/XXX
share|improve this answer
add comment

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