2
ravbholua@ravbholua-Aspire-5315:~/CCPP/HelloWorld/das/das1$ ls ./control
amer  calls  q1  q2  q3  quit.c  RCS  SCCS
ravbholua@ravbholua-Aspire-5315:~/CCPP/HelloWorld/das/das1$ du ./control
20  ./control/calls
16  ./control/RCS
40  ./control/SCCS
96  ./control
ravbholua@ravbholua-Aspire-5315:~/CCPP/HelloWorld/das/das1$ du ./control/*
0   ./control/amer
20  ./control/calls
4   ./control/q1
4   ./control/q2
4   ./control/q3
4   ./control/quit.c
16  ./control/RCS
40  ./control/SCCS
ravbholua@ravbholua-Aspire-5315:~/CCPP/HelloWorld/das/das1$

Please note du reports that control directory occupies 96 bytes. Now when I add the bytes consumed by the individual files, it comes to be 92 bytes.

In the same way, for all reporting du shows 4 bytes more than the sum total of the contents.

What this extra 4 bytes from?

EDIT#1

ravbholua@ravbholua-Aspire-5315:~/CCPP/HelloWorld/das/das1$ ls -ld $_
drwxrwxr-x 5 ravbholua ravbholua 4096 Dec  8 21:39 control

du ( or linux) uses 1024-byte blocks (1KB) for reporting (1024 * 4 = 4096) a file.

ravbholua@ravbholua-Aspire-5315:~/CCPP/HelloWorld/das/das1/control$ ls
ame  amer  calls  q1  q2  q3  quit.c  RCS  SCCS
ravbholua@ravbholua-Aspire-5315:~/CCPP/HelloWorld/das/das1/control$ du ame
4   ame
ravbholua@ravbholua-Aspire-5315:~/CCPP/HelloWorld/das/das1/control$ cat ame
a
ravbholua@ravbholua-Aspire-5315:~/CCPP/HelloWorld/das/das1/control$ ll ame
-rw-rw-r-- 1 ravbholua ravbholua 2 Dec  8 21:39 ame

So the above file 'ame' which contains only letter 'a' and 'enter key' occupies 4 KBs of my disk space.

So that means for a file/directory linux is allocating 4KB of my disk space!!!! and it will allocate in multiples of 4KB.

Also adding one more thing: ls -l reports size in units of byte for a directory but not for a regular file. With ref. to the above file 'ame', its clear that for a regular file ls -l reports size as character count and not bytes.

  • 2
    Note that sizes are not in bytes. As you can read in du info page: Normally the disk space is printed in units of 1024 bytes, but this can be overridden – andcoz Dec 8 '13 at 16:13
  • @andcoz, the space is generally printed in 512 byte units. Only some implementations like GNU or busybox use kilo-bytes (actually kibibytes) unless in POSIX/Unix compatibility mode, such as when the POSIXLY_CORRECT environment variable is set). – Stéphane Chazelas Dec 8 '13 at 16:33
  • This is normal. Disks are handled a large number of sectors, not as an even larger number of bytes. – Thorbjørn Ravn Andersen Dec 9 '13 at 8:31
7

The control directory itself has size 4 and it is included in your first command. The second variant doesn't calculate the directory size because you're not passing it to du, but only its contents.

There is also the possibility that you have hidden files (dot-files) that are excluded when expanding the * glob so that du doesn't bother with them.

1

First, the number isn't in bytes. The unit is either kilobytes or half-kilobytes, depending on your implementation.

When you run du ./control/*, you get information for the files contained in the directory control, but not for the directory control itself. Directories have a size too — the information about the files they contain has to be stored somewhere. The size of control itself is 4 units.

  • I have edited my Q. Please give your confirmation on what I stated. – Ravi Dec 9 '13 at 3:37
  • @Ravi The output of ls -l shows that your du implementation uses units of 1kB. – Gilles Dec 9 '13 at 10:21

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.