Directory Sizes

31 October 2007

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.

Entry Filed under: UNIX. .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


David Douthitt

David is an experienced UNIX and Linux system administrator, a former Linux distribution maintainer, and author of two books ("Advanced Topics in System Administration" and "GNU Screen: A Comprehensive Manual"). View David Douthitt's profile on LinkedIn

Recent Posts

Top Posts

RSS Sharky's Column!

Calendar

October 2007
M T W T F S S
« Sep   Nov »
1234567
891011121314
15161718192021
22232425262728
293031  

Recent Comments

bharat on The Demise of the HP-UX System…
H4mm3r on Avoiding catastrophe!
Vladimir on Argument list too long?
ddouthitt on The UNIX find command and…
Mihir G joshi on The UNIX find command and…

Category Cloud

BSD Career Debian Debugging Fedora FreeBSD HPUX Learning Linux MacOS X Mind Hacks Mobile Computing NetBSD Networking OpenBSD OpenSolaris Open Source OpenVMS Personal Notes Portable Presentations Red Hat Scripting Security Solaris Tips Ubuntu UNIX Wheel Group Windows

Archives

Feeds

Links