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
6. Display inode Usage
The below command will display inode information instead of blocks in the second column.
df -i Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda1 121847808 261110 121586698 1% / none 485212 2 485210 1% /sys/fs/cgroup udev 481319 549 480770 1% /dev tmpfs 485212 579 484633 1% /run none 485212 1 485211 1% /run/lock none 485212 5 485207 1% /run/shm none 485212 22 485190 1% /run/user
7. Display Grand Total
df --total Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 1918766120 157532132 1663743252 9% / none 4 0 4 0% /sys/fs/cgroup udev 1925276 4 1925272 1% /dev tmpfs 388172 1404 386768 1% /run none 5120 0 5120 0% /run/lock none 1940848 984 1939864 1% /run/shm none 102400 20 102380 1% /run/user total 1923127940 157534544 1668102660 9% -
You can get a more user-friendly output by running the following command:
$ df --total -h 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 984K 1.9G 1% /run/shm none 100M 20K 100M 1% /run/user total 1.8T 151G 1.6T 9% -
8. Display File System Types
The difference between the plain df command and df -T is that the df -T will display the type of file system too in the output. You may find this useful in certain situations.
See example below:
$df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sda1 ext4 1918766120 157526952 1663748432 9% / none tmpfs 4 0 4 0% /sys/fs/cgroup udev devtmpfs 1925276 4 1925272 1% /dev tmpfs tmpfs 388172 1404 386768 1% /run none tmpfs 5120 0 5120 0% /run/lock none tmpfs 1940848 1172 1939676 1% /run/shm none tmpfs 102400 16 102384 1% /run/user
9. Display Disk Usage of a Specific Mount Point
df / Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 1918766120 157600360 1663675024 9% /
10. List Information for /home File System
Should you wish to see information only of the /home file system in human readable format run the below command:
$ df -hT /home Filesystem Type Size Used Avail Use% Mounted on /dev/sda1 ext4 1.8T 151G 1.6T 9% /
11. Include Certain File System Types
The df command lets you display file systems that belong only to a certain type.
In the following example, I have specified ext4 to be included:
$ df -t ext4 Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 1918766120 157529968 1663745416 9% /
12. Exclude Certain File System Types
You can also use df with the -x option to remove certain file systems.
In the following example, I wanted the tmpfs virtual file system to be excluded in the output.
df -x tmpfs Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 1918766120 157530172 1663745212 9% / udev 1925276 4 1925272 1% /dev
13. Stuck with df, Seek Help
With Linux commands, even the best of us can occasionally be stumped.
Should you encounter an issue with df, run the following command for help:
$ df --help Usage: df [OPTION]... [FILE]... Show information about the file system on which each FILE resides, or all file systems by default. Mandatory arguments to long options are mandatory for short options too. -a, --all include dummy file systems -B, --block-size=SIZE scale sizes by SIZE before printing them. E.g., '-BM' prints sizes in units of 1,048,576 bytes. See SIZE format below. --total produce a grand total -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) -H, --si likewise, but use powers of 1000 not 1024 -i, --inodes list inode information instead of block usage -k like --block-size=1K -l, --local limit listing to local file systems --no-sync do not invoke sync before getting usage info (default) --output[=FIELD_LIST] use the output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted. -P, --portability use the POSIX output format --sync invoke sync before getting usage info -t, --type=TYPE limit listing to file systems of type TYPE -T, --print-type print file system type -x, --exclude-type=TYPE limit listing to file systems not of type TYPE -v (ignored) --help display this help and exit --version output version information and exit
Getting the hang of df is no sweat.
Fortunately, df is not like fail2ban or iptables, which are more complex command line tools.
Go ahead, take df for a spin on your terminal now.
Sorry, the comment form is closed at this time.