Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

Maybe this is a newbie question, but 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
/data/foo/bar/tmp
-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
...
share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

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.)

share|improve this answer
1  
Thanks, this seems to explain the phenomenon. Two questions just out of curiosity: When would the directory file shrink again? And is there a way to show the contents of that file? –  Martin Nov 21 '12 at 10:31
2  
(1) See also unix.stackexchange.com/questions/38639/… - short answer, delete the directory and recreate it. –  Bristol Nov 21 '12 at 10:41
2  
(2) Sadly, no longer. This used to be possible on old UNIX versions. –  Bristol Nov 21 '12 at 10:47
    
You can also run e2fsck -D on the filesystem, but that requires it be unmounted. –  psusi Nov 21 '12 at 19:52
add comment

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.