Linux Tips: The Misunderstood df Command

661

I call df, or disk free, the misunderstood command because new Linux users often expect it to tell the sizes of directories and files. But it doesn’t do that– it’s for displaying useful information on filesystems. When you invoke it with no arguments, it shows free and used space on all mounted filesystems, their partitions, and mountpoints:

$ df
Filesystem      1K-blocks       Used Available Use% Mounted on
/dev/sdb1        29222392   19353412   8404256  70% /
udev              1982916          4   1982912   1% /dev
tmpfs              809892       1072    808820   1% /run
none                 5120          0      5120   0% /run/lock
none              2024724       1388   2023336   1% /run/shm
/dev/sdb3       593262544  200333868 363234532  36% /home/carla/moarstuff
/dev/sda1      1730404792 1616359192  27442000  99% /home/carla/storage
/dev/sda2       221176480  160279584  49824796  77% /home/carla/1home

firecracker the dog is fascinated by Linux filesystemsFirecracker the dog is fascinated by Linux filesystems

 

 

 

 

 

 

 

 

 

 

 

Add the -h switch for human-readable format, and get rid of the virtual filesystems that exist only in memory, and display just the partitions on your hard drives with grep:

$ df -h |grep ^/
/dev/sdb1        28G   19G  8.1G  70% /
/dev/sdb3       566G  192G  347G  36% /home/carla/moarstuff
/dev/sda1       1.7T  1.6T   27G  99% /home/carla/storage
/dev/sda2       211G  153G   48G  77% /home/carla/1home

df does not operate on individual files or directories, but only filesystems. If you give it a file or directory name as an argument, it gives information for the filesystem the file is on:

$ df -h /var
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1        28G   19G  8.1G  70% /

I like it for quickly finding out which partitions files are on. It identifies the filesystem types with the -T option:

$ df -Th |grep ^/
/dev/sdb1  ext4    28G   19G  8.1G  70% /
/dev/sdb3  ext3   566G  192G  347G  36% /home/carla/moarstuff
/dev/sda1  btrfs  1.7T  1.6T   27G  99% /home/carla/storage
/dev/sda2  ext4   211G  153G   48G  77% /home/carla/1home

And you can hunt down specific filesystem types:

$ df -ht btrfs
/dev/sda1  btrfs  1.7T  1.6T   27G  99% /home/carla/storage

Consult man df and man grep to learn more about what these excellent commands can do. Both are non-destructive commands that only read information, so you can experiment safely.