LiveFire Labs: Online UNIX Training with Hands-on Internet Lab


"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







Custom Search



LiveFire Labs' UNIX Tip, Trick, or Shell Script of the Week

The UNIX du Command - Part II

UNIX Disk Usage - Tracking Down Disk Space "Hogs"

In last week's tip, the UNIX du command was used to quickly identify wilbur as the largest consumer of disk space within /home by glancing at the command's output:

# 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

We left off by stating that this works fine when there are only a handful of users on a system, but how could you quickly identify the disk usage "hogs" on a system with hundreds or thousands of users?

This can easily be accomplished by piping the output from the du command to the UNIX sort command:

# du /home | sort -nr
1276     /home
1144     /home/wilbur
1036     /home/wilbur/tmp
128       /home/jdoe
8          /home/jdoe/tmp
4          /home/wilbur/tmp/docs1
4          /home/wilbur/testdir3
4          /home/wilbur/testdir2
4          /home/wilbur/testdir1
4          /home/wilbur/docs
4          /home/jdoe/tmp/docs1
4          /home/jdoe/testdir3
4          /home/jdoe/testdir2
4          /home/jdoe/testdir1
4          /home/jdoe/docs

If you are not intimately familiar with the sort command, the -n option sorts the data by numeric field first, and the -r option will reverse the results.  If the number of users on your system requires you to sort the results, you will most likely also need to pipe the sorted results to the UNIX more command:

# du /home | sort -nr | more

In doing so, you will be able to view one screen of results at a time.

There are many options available for monitoring and managing disk space usage on a UNIX system, but the du command is one that should always be available for quickly identifying a system's heavy disk space consumers.
Read the PREV article in this series if you missed it - The UNIX du Command - Tracking Down Disk Space "Hogs" - Part I