df
This subchapter looks at df, a UNIX (and Linux) command.
df is used to display informaiton on disk usage.
human readable
Use the -h or -H option to see space used in human readable format (such as kilobytes, megabytes, gigabytes, terabytes, petabytes, etc.). Both options do the same thing.
$ df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/disk0s10 149Gi 117Gi 32Gi 79% /
devfs 111Ki 111Ki 0Bi 100% /dev
fdesc 1.0Ki 1.0Ki 0Bi 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% /net
map auto_home 0Bi 0Bi 0Bi 100% /home
/dev/disk1s2 498Gi 40Gi 457Gi 9% /Volumes/msdos
/dev/disk1s1 434Gi 81Gi 353Gi 19% /Volumes/Mac FreeAgent GoFlex Drive
$
The exact format of the human readable output will vary from system to system, but the columns are usually labelled (as in the Mac OS X example above). The file system path is a reference to a hard drive, storage device, network, or other location. The mount point is the location in the directory tree where you can find the file system.
Also note that adding the used and available space will not necessarily be an exact match with the total. One explanation is that a journaling system will account for up to 5% of the disk space.
type
Use the -T option to see the type of file system.
$ df -T
You can also provide specified filesystem types after the -T option to only show filesystems of the designated type. Use a comma separated list to provide multiple filesystem types. Pre-fix with no to show file systems other than the listed types.
As an example, the following command will display all file systems other than those of type NFS and MFS:
$ df -T nonfs,mfs
Use the lsvfs command to find out what types of filesystems are available on your computer or server.
differences between du and df
You may notice that du and df sometimes give very different numbers for the disk space on a production server. This rarely happens on a desktop or workstation. Usually df will output the bigger disk usage. This occurs when an inode is deallocated.
Some process has created a large temporary file and some other process has deleted it. The file remains in existence until the first process closes it, but the file system immediately removes access for any other process (to prevent all kinds of strange errors by accessing or manipulating non-existent files.
Running lsof | grep tmp or lsof | grep deleted will often reveal a large temporary file that accounts for the difference.
du and df should resolve back to the same results after the first process releases the file. If the problem persists, use fsck to fix it.
blocksize
Use the -b or -P option to see use the default of blocks. This may be needed to override a BLOCKSIZE specification from the environment. In the early days of UNIX and Linux, the default block size was normally 512-bytes. In more modern times the size of a block can be 1K, 8K, 32K, or even bigger.
$ df -b
result in 512 byte blocks
Use the -k option to see use 1023-byte blocks. This is 1-Kbyte blocks.
$ df -k
result in Kilo-byte blocks
Use the -m option to see use 1048576-byte blocks. This is 1-Mbyte blocks.
$ df -m
result in Mega-byte blocks
Use the -g option to see use 1073741824-byte blocks. This is 1-Gbyte blocks.
$ df -g
result in Giga-byte blocks
display inodes
Use the -i option to include statistics on the number of free inodes.
$ df -i
On Mac OS X, the additional columns are iused, ifree, and %iused.
local
Use the -l option to only display information about locally-mounted filesystems (no network fielsystems).
$ df -l
long delay filesystems
Use the -n option to display previously obtained statistics. This is used when one or more filesystems are in a state where there will be a long delay to provide statistics.
$ df -n
other
On November 8, 2010, Ramesh Natarajan named this the number 25 most frequently used UNIX/Linux command at this web page 50 Most Frequently Used UNIX / Linux Commands (With Examples).
In June 2009, Ken Milberg named this command as one of the Top 50 universal UNIX commands at this web page Top 50 Universal INIX commands. Note that this web page requires agreeing to be spammed before you can read it.
comments, suggestions, corrections, criticisms
free music player coding example
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
View music player in action: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.
Names and logos of various OSs are trademarks of their respective owners.