Directory Sizes

Each directory in UNIX is just another file in UNIX like any other. Directories contain information about the names of files and their locations on disk. As more and more files are added to a directory, the directory itself grows larger and larger. However, the directory does not shrink when files are removed.

For example:

# ls -ld /tmp
drwxrwxrwt 14 root root 4096 2007-10-29 11:14 /tmp

This directory is 4096 bytes (4k) in size. There is no way to actually shrink this directory. To reduce its size, the directory must be moved (renamed) and its contents copied into a new directory.

This could be done this way:

# mv /tmp /tmp.old
# mkdir /tmp
# chmod 1777 /tmp

The chmod will change the /tmp directory permissions to the appropriate ones. Note that the “sticky” bit is set, which means that files may be created, accessed, and deleted by anyone, but that files may be deleted only by their owner.

In the case of the /tmp directory, it may be best to reboot before deleting the old directory to avoid problems with programs using /tmp.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: