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 created a directory where I put ten files, each one with exactly 1,048,576 characters (1024^2). The size of each one of them should be exactly one megabyte, counting megabyte as 1024^2 bytes.

If I use ls -lh on that directory, this is the output

[ me: /home/me/test ] ls -lh the_directory
total 11M
-rw-r--r--  1 me we 1.0M Feb  1 17:11 f0
-rw-r--r--  1 me we 1.0M Feb  1 17:11 f1
-rw-r--r--  1 me we 1.0M Feb  1 17:11 f2
-rw-r--r--  1 me we 1.0M Feb  1 17:11 f3
-rw-r--r--  1 me we 1.0M Feb  1 17:11 f4
-rw-r--r--  1 me we 1.0M Feb  1 17:11 f5
-rw-r--r--  1 me we 1.0M Feb  1 17:11 f6
-rw-r--r--  1 me we 1.0M Feb  1 17:11 f7
-rw-r--r--  1 me we 1.0M Feb  1 17:11 f8
-rw-r--r--  1 me we 1.0M Feb  1 17:11 f9

Why does it add up to 11M if the sum of the colum is exactly 10.0M? If I do ls -lha, then I see that the directories . and .. account for 4KB each. There is NOTHING else in this directory.

Why is this so?

This was done in a Linux box.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

It is because there are two additional 4K entries (. and ..), a small 4K overhead on each file (it's the metadata block) and ls always rounds sizes up.

Try ls -lash (it will show the 'disk' size of files, i.e. with any additional non-user-data stored on disk):

total 11M
4.0K drwxr-xr-x  2 whitequark whitequark 4.0K 2010-02-02 06:15 .
4.0K drwxr-xr-x 85 whitequark whitequark 4.0K 2010-02-02 05:33 ..
1.1M -rw-r--r--  1 whitequark whitequark 1.0M 2010-02-02 06:15 f0
...
1.1M -rw-r--r--  1 whitequark whitequark 976K 2010-02-02 06:20 f9

If you'll request size in kilobytes with ls -las, you'll get:

total 10288
   4 drwxr-xr-x  2 whitequark whitequark    4096 2010-02-02 06:15 .
   4 drwxr-xr-x 85 whitequark whitequark    4096 2010-02-02 05:33 ..
1028 -rw-r--r--  1 whitequark whitequark 1048576 2010-02-02 06:15 f0
...
1028 -rw-r--r--  1 whitequark whitequark 1048576 2010-02-02 06:18 f9

Also, if you'll reduce size of last file by 48K (the overhead), you'll get a 10M (i.e. 10240K) directory:

total 10M
4.0K drwxr-xr-x  2 whitequark whitequark 4.0K 2010-02-02 06:15 .
4.0K drwxr-xr-x 85 whitequark whitequark 4.0K 2010-02-02 05:33 ..
1.1M -rw-r--r--  1 whitequark whitequark 1.0M 2010-02-02 06:15 f0
...
1.1M -rw-r--r--  1 whitequark whitequark 1.0M 2010-02-02 06:15 f8
980K -rw-r--r--  1 whitequark whitequark 976K 2010-02-02 06:20 f9
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.