I can't understand why ls -l shows folder size less than block size.

For example:

[user@01 NEW]$ ls -l
total 4
drwxr-xr-x  5 root root   78 Apr 22 00:43 controllers
drwxr-xr-x 14 root root 4096 Apr 22 00:44 schemas
drwxr-xr-x  2 root root   38 Apr 22 00:44 spinner

"controllers" is a directory, and block size is 4096 bytes, so why size is 78 bytes?

[user@01 NEW]$ find controllers/ -type f | wc -l

Many files are inside. And du -hs shows that size of this folder is 840 K.

Another strange thing is that ls -s shows that for this two directories allocated 0 blocks:

[user@01 NEW]# ls -ls
total 4
0 drwxr-xr-x  5 root root   78 Apr 22 00:43 controllers
4 drwxr-xr-x 14 root root 4096 Apr 22 00:44 schemas
0 drwxr-xr-x  2 root root   38 Apr 22 00:44 skins


 xfs_info /
meta-data=/dev/disk/by-uuid/5d87d678-e4cc-445f-b770-4e4c0357faaa isize=256    agcount=4, agsize=393088 blks
         =                       sectsz=512   attr=2
data     =                       bsize=4096   blocks=1572352, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

In ext4 folders size is normal (i.e., equal to block size).


The size is 78 bytes because the directory is almost empty. With "directory" I mean the immediate descendant content of that folder, i.e., if you have


then "controllers" only has three entries (.., Class1 and Class2. I do not know exactly whether or how .. is actually stored).

Even if, on disk, the directory will occupy one whole block, therefore 4K (but see below...), the directory logical size remains 78 bytes, and in many ways it is treated as a file (the XFS white papers refers to it as a directory file). If you create a new object immediately under controllers, I expect that size to increment.


Also, very small directories can be stored inside inodes, thereby occupying zero actual blocks:

Very small files

Most symbolic links and directory files are small files. XFS allows these files to be stored in inodes for increased performance. XFS also uses delayed writes to wait to gather the entire small file in the buffer cache before writing to disk...

To recap, as far as I understand, you can have


The space available inside a XFS inode for a directory file seems to be around 156-157 bytes on my Linux system. When exceeded, a 4K block is used, but releasing space also releases the block, storing back the info into the inode.

mkdir temp

drwxr-xr-x   2 root   root               6 2013-04-22 08:59 temp

touch temp/x; ls -la temp

drwxr-xr-x   2 root   root              14 2013-04-22 09:00 temp

mv temp/x temp/{ 100 x's }

drwxr-xr-x   2 root   root             113 2013-04-22 09:01 temp

{ 130 x's }

drwxr-xr-x   2 root   root             143 2013-04-22 09:02 temp

{ 140 x's }    
drwxr-xr-x   2 root   root             153 2013-04-22 09:02 temp

{ 146 x's }
drwxr-xr-x   2 root   root            4096 2013-04-22 09:03 temp

{ 142 x's }
drwxr-xr-x   2 root   root             155 2013-04-22 09:03 temp
| improve this answer | |
  • Thanks, Redhat article says: "For the default inode size of 256 bytes, roughly 100 bytes of attribute space is available depending on the number of data extent pointers also stored in the inode." So, it mean that folder size can't be bigger than 100 b (if it stored in inode). But some directories has size 130 and more bytes (also 0 blocks are allocated for them). – loadaverage Apr 22 '13 at 0:41
  • Possibly, the literal area of a directory file inode is larger (inode core is 96 bytes, that leaves 160). You can experiment by creating a file with longer and longer name. – LSerni Apr 22 '13 at 6:57
  • I did that out of curiosity, the actual space seems to be between 155 and 159 bytes indeed. The part you quoted referred to a file with extended attributes and data extent pointers, but a small directory may do without either, and so have more space available. – LSerni Apr 22 '13 at 7:07
  • Yes, I've tested this, size is the same (~160 bytes). Thank you for helping. – loadaverage Apr 22 '13 at 16:01

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.