4

Lets say we have a default formatted ext3 filesystem, I run under the assumption that folders take 4K of space on the disk.

But, what does it mean when a folder is bigger than 4K?

Here is a pic of one such folder: http://datanethost.net/stuff/puttysh.png
The only file was an .htaccess file that was a couple of bytes. I created a new directory, moved the .htaccess file into the new folder and delete the other weird folder and everything is fine again...but I just find it weird.

Can anyone explain this?

1 Answer 1

6

A directory starts off at 4K, but grows as it needs to store more file names. I'm pretty sure that it never shrinks again as those files are deleted. Something called "cache" might very well contain a lot of files, either now or at some time in the past.

As Stephen pointed out in the comments, once your cache directory grows large enough to hold, say, 10 000 files, then if those files are deleted it still has room to store 10 000 files, so if a new 10 000 files are created, the directory isn't going to grow again.

4
  • If this was true then all my folder sizes should increase but they don't. Do you know how to recreate this behavior? Jan 4, 2010 at 2:37
  • 5
    The storage allocated for a directory is only returned to the filesystem when the directory is deleted, but that allocated storage is re-used by that directory if entries are deleted. To show this, create an empty test directory; it'll show up as 4K in size. Create 10000 files or so; the size of the directory will increase. Delete them all; the size won't decrease. Recreate the files; the size won't increase further. The size of a directory is related to the maximum number of names it has ever contained. Jan 4, 2010 at 3:02
  • Ok I was able to recreate this behavior, and it makes sense now. Does NTFS do the same thing? Jan 4, 2010 at 3:18
  • For NTFS, have a look at this detailed explanation: superuser.com/questions/682809/…
    – KIAaze
    Oct 15, 2023 at 22:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .