Every so often, some application runs wild and fills a directory with a huge amount of files. Once we fix the bug and clean up the files, the directory stays big (>50MB) even though there's only 20-30 files in it.
Is there some command that compacts a directory without having to recreate it?
Bonus points: does a huge empty directory affect access performance of that directory? I'm assuming it does, but maybe it's not worth bothering. It seems slower to do ls
on such a directory.
fsck
? ext3'sfsck
has an "Optimizing directory" pass. I don't know what that does, but maybe it shrinks directories that are too big? Anyway, as a data point FWIW, xfs autoshrinks directories that have had files removed from them.