As the subject says; I want to know why is every directory having a size equals to 4K even if they contain files with sizes greater than 4K.
Please have a look at the following:-
$ ls -lh
total 2.0M
drwxr-xr-x 4 ankit ankit 4.0K Sep 11 07:28 Desktop
$ ls -lrh Desktop/
-rw-rw-r-- 1 ankit ankit 9.1M Aug 4 11:15 sophosthreatsaurusaz.pdf
-rw------- 1 ankit ankit 107K Dec 27 2010 KP 3 0.pdf
drwxrwsr-x 9 ankit ankit 4.0K Sep 10 19:26 eclipse
PS: I am aware of du -sh
command line utility.
Edit: I am assuming directory as a container for files.
ls
shows you the size of that link, not the total space occupied by the contents of the directory.To understand this, you'd better have some basic knowledge of the following (file system):
On typical
ext4
file system (what most people use), the defaultinode
size is 256 bytes, block size is 4096 bytes.A directory is just a special file which contains an array of filenames and inode numbers. When the directory was created, the file system allocated 1 inode to the directory with a "filename" (dir name in fact). The inode points to a single data block (minimum overhead), which is 4096 bytes. That's why you see 4096 / 4.0K when using
ls
.You can get the details by using
tune2fs
&dumpe2fs
.Example
Source