Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Softpanorama Search

df Command

News See also Books Recommended Links  

Reference

    Admin Horror Stories Unix History Humor

Etc

The df command is used to show the amount of disk space that is free on file systems. In the examples, df is first called with no arguments. This default action is to display used and free file space in blocks.

In example below the block size is 1024 bytes ( -k option used) as is indicated in the output.:

# df -k

Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c0t0d0s0    4032504  104381 3887798     3%    /
/dev/dsk/c0t0d0s4    4032504  992890 2999289    25%    /usr
/proc                      0       0       0     0%    /proc
fd                         0       0       0     0%    /dev/fd
mnttab                     0       0       0     0%    /etc/mnttab
/dev/dsk/c0t0d0s3    4032504  657034 3335145    17%    /var
swap                 4095176       8 4095168     1%    /var/run
swap                 4095192      24 4095168     1%    /tmp
/dev/dsk/c0t0d0s5    1984564  195871 1729157    11%    /opt
/dev/dsk/c0t0d0s7   14843673 1619568 13075669   12%    /helpdesk
/dev/oradg/u02vol   12582912 8717924 3744252    70%    /u02
/dev/oradg/u01vol    8796160 5562586 3132548    64%    /u01
/dev/oradg/u04vol   10035200 1247888 8519534    13%    /u04
/dev/oradg/u03vol   12582912 2524060 9744542    21%    /u03
/dev/dsk/c0t0d0s6    1984564  931591  993437    49%    /export/home
/vol/c0t/orcl901_3    270364  270364       0   100%    /cdrom/orcl901_3

The first column show the name of the disk partition as it appears in the /dev directory. Subsequent columns show total space, blocks allocated and blocks available. The capacity column indicates the amount used as a percentage of total file system capacity.

The final column show the mount point of the file system. This is the directory where the file system is mounted within the file system tree. Note that the root partition will always show a mount point of /. Other file systems can be mounted in any directory of a previously mounted file system. In the example, there are two other file systems, the first in mounted as /home and the second is mounted as /p4.

If df is invoked with the -i option it displays information about inodes rather that file blocks. An inode is what the Linux file system uses to identify each file. When a file system is created (using the mkfs command), the file system is created with a fixed number of inodes. If all these inodes become used, a file system cannot store any more files even though there may be free disk space. The df -i command can be used to check for such a problem.

Often you need a subset of all filesystem, for example just Oracle file systems.  Common convention is that Oracle filesystems begin with /u0. 

# df -k | grep /u0

/dev/vx/dsk/oradg/u02vol 12582912 8717924 3744252    70%    /u02
/dev/vx/dsk/oradg/u01vol  8796160 5563610 3131556    64%    /u01
/dev/vx/dsk/oradg/u04vol 10035200 1247888 8519534    13%    /u04

/dev/vx/dsk/oradg/u03vol 12582912 2524060 9744542    21%    /u03

we can use cut, Perl of awk to extract the fourth column, which is the available space in the filesystem.

$ df -k | grep /u0|awk '{ print $4 }'

3744252
3132546
8519534
9744542

Create the script to check space in all file systems

Now that we see the command, we can place this command inside a loop to evaluate the free space for each filesystem.  Note that our command is placed inside the Korn shell for loop, and the command is enclosed in back-ticks (the key immediately above the tab key).

check_filesystem_size.ksh
#!/bin/ksh

for i in `df -k | grep /u0 `
do
  
# If any filesystem has less than 100k, issue an alert

   freespace=echo $i | awk '{ print $4 }'
   if [ $freespace -lt 100 ]
   then
      mail -s "On server $HOSTNAME filesystem $i has less then 100K of free space ($freespace)" joe.user@company.com < df -k | grep "/u0" 
   fi
done

We can execute this script each 10 minutes from crontab (Linux cron capability to specify increment is used):

#****************************************************************
# Filesystem free space below 100K alert
#****************************************************************
1/10 * * * * /home/oracle/check_filesystem_size.ksh > dev/null >&1

Old News

[Mar 14, 2010]  CertCities.com Column A System Monitoring Tool Primer

Checking Disk Performance and Disk Usage

Linux comes with the /sbin/hdparm program that can be used to control IDE or ATAPI hard drives that are common on most PCs. One feature of the hdparm program is to use the -t option to determine the rate at which data is read from the disk into a buffer in memory. For example, here's the result of typing /sbin/hdparm -t /dev/hda on one system:
/dev/hda:

/dev/hda:
 Timing buffered disk reads: 178 MB in  3.03 seconds = 58.81 MB/sec
The command requires the IDE drive's device name (/dev/hda for the first hard drive and /dev/hdb for the second hard drive) as an argument. If you have an IDE hard drive, you can try this command to see how fast data is read from your system's disk drive.
To display the space available in the currently mounted file systems, use the df command. If you want a more readable output from df, type the following command:
df -h
Here's a typical output from this command:
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda5             7.1G  3.9G  2.9G  59% /
/dev/hda3              99M   18M   77M  19% /boot
none                  125M     0  125M   0% /dev/shm
/dev/scd0             2.6G  2.6G     0 100% /media/cdrecorder
As As this example shows, the -h option causes the df command to show the sizes in gigabytes (G) and megabytes (M).

To check the disk space being used by a specific directory, use the du command and specify the -h option to view the output in kilobytes (K) and megabytes (M), as shown in the following example:

du -h /var/log
Here's a typical output of that command:

152K    /var/log/cups
4.0K    /var/log/vbox
4.0K    /var/log/httpd
508K    /var/log/gdm
4.0K    /var/log/samba
8.0K    /var/log/mail
4.0K    /var/log/news/OLD
8.0K    /var/log/news
4.0K    /var/log/squid
2.2M    /var/log
The du command displays the disk space used by each directory, and the last line shows the total disk space used by that directory. If you want to see only the total space used by a directory, use the -s option. For example, type du -sh /home to see the space used by the /home directory. The command produces an output that looks like this:
89M     

Recommended Links

df (Unix) - Wikipedia, the free encyclopedia

The DF Command | Linux Journal

Why command df and du reports different output-

How to use the df command, by The Linux Information Project