[NTLUG:Discuss] huge file/directory size in ..

Wayne Walker wwalker at solid-constructs.com
Tue Apr 3 12:50:29 CDT 2012


On Tue, Apr 03, 2012 at 11:51:31AM -0500, Patrick R. Michaud wrote:
> It can also be that the parent directory once had a lot
> of files/directories in it, even if it now does not.
> Directories often don't shrink in size on the filesystem;
> once a directory file holds thousands of file entries, it remains
> large enough to hold thousand of file entries, even if there
> are far fewer (or even zero).
> 
> One way to "fix" it might be to create a new directory for the
> parent, move the remaining files from the existing parent
> directory into the new one, remove the (now-empty) parent
> directory, and then rename the new directory to the parent.
> The new parent directory should then be smaller (i.e., only
> large enough to hold the needed entries).
> 
> Be extra careful if any of the directories or files
> involved are mountpoints or symlinks or the like, or if
> there are any processes potentially holding links to the
> files (i.e., don't follow the above suggestion blindly).
> 
> Pm

If you do not understand hardlinks, and reference counts, and file
reaping, and the implication of cwd/pwd, then I would not try to fix the
problem you have, especially the way I describe below.

Really, one should never take any corrective action that one doesn't
understand.  However...

While all of Patrick's warnings about mount points,etc. are still valid,
if there are no mount points, but you are concerned about unexpected
file access by applications:

cp -al original new; mv original original.old; mv new original

This create a tree of directories containing hard links for the files
and identical soft links for the softlinks.  A process can grab either
a file in original or a file in new and it has the same file.

Then, after a while, you run:

lsof original.old

to see if any of the files/directories in the original tree are in use.

When they are finally not in use, you can delete the original.old
directory.


-- 

Wayne Walker
wwalker at solid-constructs.com
(512) 633-8076
Senior Consultant
Solid Constructs, LLC



More information about the Discuss mailing list