Today let’s talk about df, the command line utility providing information on disk space used and remaining on your file systems.
Unsurprisingly, df stands for disk free.
Besides listing how much disk space is used and how much is free, df also displays how the file systems are mounted on your Linux desktop or server.
With df, you get disk use information on your local system as well as external drives attached to it.
The basic syntax of df is:
df [OPTION]… [FILE]..
One caveat I must add here is that df will not provide you with the size of directories or files. The command for that is du and we’ll cover that in a separate article.
Here are a bunch of df commands that you can grasp in less than 10 minutes.
Should you not provide any file name while running df, the space available on all mounted file systems will be displayed.
1. Basic df Command
When you run the df command without any options, the output provides disk utilization in 1K blocks.
larry@tammypc ~ $ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 1918766120 157599888 1663675496 9% / none 4 0 4 0% /sys/fs/cgroup udev 1925276 4 1925272 1% /dev tmpfs 388172 1392 386780 1% /run none 5120 0 5120 0% /run/lock none 1940848 788 1940060 1% /run/shm none 102400 20 102380 1% /run/user /dev/sdb1 244137920 205701856 38436064 93% /media/larry/HITACHI
In the above example, sda1 is the local drive and sdb1 is an external drive.
Apart from physical hard drives, df will list mounted file systems such as udev for /dev and tmpfs filesystem for /run and its subdirectories. Those with a grounding in Linux will quickly recognize that these file systems run in memory and are part of Linux.
2. Include All File Systems
The df -a command will include all file systems including those that have a size of 0 blocks, which are omitted by default (such file systems are usually special-purpose pseudo-file systems like automounter entries).
$ df -a Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 1918766120 157529716 1663745668 9% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys none 4 0 4 0% /sys/fs/cgroup none 0 0 0 - /sys/fs/fuse/connections none 0 0 0 - /sys/kernel/debug none 0 0 0 - /sys/kernel/security udev 1925276 4 1925272 1% /dev devpts 0 0 0 - /dev/pts tmpfs 388172 1408 386764 1% /run none 5120 0 5120 0% /run/lock none 1940848 736 1940112 1% /run/shm none 102400 16 102384 1% /run/user none 0 0 0 - /sys/fs/pstore binfmt_misc 0 0 0 - /proc/sys/fs/binfmt_misc systemd 0 0 0 - /sys/fs/cgroup/systemd gvfsd-fuse 0 0 0 - /run/user/1000/gvfs
3. Display for Specific File System
We can narrow down space used for a file system with the below command.
$ df /dev/sda1 Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 1918766120 157541184 1663734200 9% /
4. Display in Human Readable Format
By default, df displays information in kilobytes.
Now in a world of gigabytes and terabytes hardly anybody uses kilobytes these days. So the df folks came up with the -h option.
Of all the df options, the most useful one is df -h because this gives the output in human readable format.
$ df -h Filesystem Size Used Avail Use% Mounted on Filesystem Size Used Avail Use% Mounted on /dev/sda1 1.8T 151G 1.6T 9% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 1.9G 4.0K 1.9G 1% /dev tmpfs 380M 1.4M 378M 1% /run none 5.0M 0 5.0M 0% /run/lock none 1.9G 736K 1.9G 1% /run/shm none 100M 16K 100M 1% /run/user
I wouldn’t be surprised if df –h is the most used among the various df options.
5. Ignore Virtual File Systems
More often than not, we don’t need space use pertaining to virtual file systems.
What we are interested is are the partitions on the hard drives.
Here’s an example of how we can remove information pertaining to virtual file systems that exist only in memory:
df -h |grep ^/ /dev/sda1 1.8T 151G 1.6T 9% / /dev/sdb1 233G 216G 18G 93% /media/larry/HITACHI