Why could the size of the "dot" file "." exceed 4096?

Today I found an “empty” directory with a size of 4MB.

It had no visible contents, so I tried ls -lah. This showed me some hidden files (not very large). Searching for the reason why the directory was so large I found that the dot file (.) had a size of 3.9MB.

What gets stored in that file? Isn’t that just a kind of link to the same directory?

Here is the shell output (anonymized):

-bash# more /proc/version
Linux version 2.6.18-8.1.15.el5 (mockbuild@builder6.centos.org) (gcc version 4.1.1 20070105 (Red Hat 4.1.1-52)) #1 SMP Mon Oct 22 08:32:04 EDT 2007
-bash# pwd
-bash# ls -lah
total 4.1M
drwxrwxrwx  3 nobody nobody 3.9M Nov 21 10:02 .
drwxrwxrwx 16 nobody nobody 4.0K Aug 27 17:26 ..
-rw-------  1 root   root    20K Oct 25 14:06 .bash_history
Asked By: Martin Hennings


The dot file, like every directory, contains a list of names for the files in this directory and their inode numbers. So if you once had lots of files in that directory (not unlikely for a “tmp” directory) that would have made the directory entry grow to this size.

After the files are gone, the file system doesn’t automatically shrink the directory file again.

You can experiment with this yourself by making a new empty directory, do ls -la in it to see the initial size (4096 on my machine) then touching a lot of files, which will make the directory size grow.

(Yes I know that I’m glossing over/being inaccurate about a lot of details here. But the OP didn’t ask for a full explanation of how EXT* file systems work.)

Answered By: user21105
Categories: Answers Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.