The df command reports the system's disk space usage. If you type the command df at a shell prompt, the output looks similar to the following:
Filesystem 1k-blocks Used Available Use% Mounted on /dev/hda2 10325716 2902060 6899140 30% / /dev/hda1 15554 8656 6095 59% /boot /dev/hda3 20722644 2664256 17005732 14% /home none 256796 0 256796 0% /dev/shm |
By default, this utility shows the partition size in 1 kilobyte blocks and the amount of used and available disk space in kilobytes. To view the information in megabytes and gigabytes, use the command df -h. The -h argument stands for human-readable format. The output looks similar to the following:
Filesystem Size Used Avail Use% Mounted on /dev/hda2 9.8G 2.8G 6.5G 30% / /dev/hda1 15M 8.5M 5.9M 59% /boot /dev/hda3 20G 2.6G 16G 14% /home none 251M 0 250M 0% /dev/shm |
In the list of partitions, there is an entry for /dev/shm. This entry represents the system's virtual memory file system.
The du command displays the estimated amount of space being used by files in a directory. If you type du at a shell prompt, the disk usage for each of the subdirectories will be displayed in a list. The grand total for the current directory and subdirectories will also be shown as the last line in the list. If you do not want to see the totals for all the subdirectories, use the command du -hs to see only the grand total for the directory in human-readable format. Use the du --help command to see more options.
To view the system's partitions and disk space usage in a graphical format, use the System Monitor tab as shown at the bottom of Figure 26-2.
Tip | |
---|---|
For information on implementing disk quotas, refer to Chapter 6 Implementing Disk Quotas. |
Red Hat Linux provides a utility called diskcheck that monitors the amount of free disk space on the system. Based on the configuration file, it will send email to the system administrator when one or more disk drives reach a specified capacity. To use this utility, you must have the diskcheck RPM package installed.
This utility is run as an hourly cron [1] task.
The following variables can be defined in /etc/diskcheck.conf:
defaultCutoff — When disk drives reach this percent capacity, it will be reported. For example, if defaultCutoff = 90, an email will be sent when the monitored disk drives reach 90% capacity.
cutoff[/dev/partition] — Override the defaultCutoff for the partition. For example, if cutoff['/dev/hda3'] = 50 is specified, diskcheck will alert the system administrator when the partition /dev/hda3 reaches 50% capacity.
cutoff[/mountpoint] — Override the defaultCutoff for the mount point. For example, if cutoff['/home'] = 50 is specified, diskcheck will alert the system administrator when the mount point /home reaches 50% capacity.
exclude — Specify one or more partitions for diskcheck to ignore. For example, if exclude = "/dev/sda2 /dev/sda4" is specified, diskcheck will not alert the system administrator if /dev/sda2 or /dev/sda4 reaches the specified cutoff percentage.
ignore — Specify one or more file system types to ignore in the format -x filesystem-type. For example, if ignore = "-x nfs -x iso9660" is specified, the system administrator will not be alerted about nfs or iso9660 file systems reaching capacity.
mailTo — Email address of the system administrator to alert when partitions and mount points reach the specified capacity. For example, if mailTo = "[email protected]" is specified, [email protected] will be emailed alerts.
mailFrom — Specify the identity of the email sender. This is useful if the system administrator wants to filter the mail from diskcheck. For example, if mailFrom = "Disk Usage Monitor" is specified, email will be sent to the system administrator with the sender Disk Usage Monitor.
mailProg — Specify the mail program to use to send email alerts. For example, if mailProg = "/usr/sbin/sendmail" is specified, Sendmail will be used as the mail program.
You do not have to restart a service if you change the configuration file because it is read each time the cron task is run. You must have the crond service running for cron tasks to be executed. To determine if the daemon is running, use the command /sbin/service crond status. It is recommended that you start the service at boot time. Refer to Chapter 14 Controlling Access to Services for details on starting the cron service automatically at boot time.
[1] | Refer to Chapter 28 Automated Tasks for more information on cron. |