"Taking a LiveFire Labs' course is an excellent way to learn
Linux/Unix. The lessons are well thought out, the material is
explained thoroughly, and you get to perform exercises on a real
Linux/Unix box. It was money well spent."
Ray S.
Pembrook Pines, Florida
LiveFire Labs' UNIX and Linux Operating System Fundamentals
course was very enjoyable. Although I regularly used UNIX systems
for 16 years, I haven't done so since 2000. This course was a
great refresher. The exercises were fun and helped me gain a real
feel for working with UNIX/Linux OS. Thanks very much!"
Ming Sabourin
Senior Technical Writer
Nuance Communications, Inc.
Montréal, Canada
Read
more student testimonials...
Receive UNIX Tips, Tricks, and Shell Scripts by Email
LiveFire Labs' UNIX Tip,
Trick, or Shell Script of the Week
The UNIX du Command - Part I
UNIX Disk Usage - Tracking Down Disk Space "Hogs"
To be successful at UNIX system
administration, there are a number of inherent tasks that MUST be
performed by the system administrator. One of the primary inherent
tasks is monitoring and managing disk space usage.
The system administrator needs to be proactive in regards to this
responsibility (e.g., by setting up automated monitoring and
notification programs), or may experience one or more of the following
if a key filesystem becomes full:
· system slow-down
· users unable to log in
· a system crash
Even with an automated monitoring or notification solution in place,
there may be times when the system administrator will have to be
reactive in identifying disk space "hogs." One of the most common
tools for handling this is the UNIX du command. (If it's not obvious,
du stands for disk usage.)
The syntax for the du command is:
du [OPTION...] [DIRECTORY...]
The command will report the amount of disk space used by all of the
files and sub-directories located beneath the directory specified with
the DIRECTORY command argument. The following example shows the du
output for one particular system's /home directory:
# du /home
4 /home/jdoe/tmp/docs1
8 /home/jdoe/tmp
4 /home/jdoe/testdir1
4 /home/jdoe/testdir2
4 /home/jdoe/testdir3
4 /home/jdoe/docs
128 /home/jdoe
4 /home/wilbur/tmp/docs1
1036 /home/wilbur/tmp
4 /home/wilbur/testdir1
4 /home/wilbur/testdir2
4 /home/wilbur/testdir3
4 /home/wilbur/docs
1144 /home/wilbur
1276 /home
Notice that the results are listed by sub-directory. Since there are
only two non-system users on this server, it is easy to identify that
wilbur is the largest consumer of disk space within the /home
directory. It can also be seen that files in wilbur's "tmp"
sub-directory are consuming the largest amount of space under his home
directory (/home/wilbur).
The total amount of space used by files and directories underneath
/home in this example is 1,276 blocks. The size of a block is
typically 512 or 1,024 bytes, but each system's documentation should
be consulted to determine the default size it uses.
Visually identifying heavy disk space users works fine if there are
only a handful of users on a system, but how would one quickly
accomplish this same task on a system with hundreds or thousands of
users?
Read the NEXT article in this series to find out
- The UNIX du Command -
Tracking Down Disk Space "Hogs" - Part II