The Command df “disk file system” is one of the very powerful tools every system admin should know. when mastering this command you should understand a lot of information about your local and remote file system details like mount point, disk utilization, partitions etc. In this post, we will find out some of the very common and useful ways to use “df” to monitor your file system. The df command read it’s output from /proc/mounts file and a kernel function statfs(2). This file /proc/mounts give you where block files are mounted and statfs(2) will help you query kernel to get present disk sizes. The df command will combine these two and print some meaningful information for a Linux user.
Syntax of df command in Linux
df [OPTION]... [FILE]...
I am firm believer of learning stuff with examples. Below are some examples you should know.
Usage of the df command in Linux
Example 1: Using the “df” without any options. If you use the df command without any arguments, it will show you something like below. You will get columns of File system, number of blocks in 1K each, number of used blocks, number of available blocks, used percentage and finally the mount point for each file system. As you will get to know this command better, you will come to know that it is handier to mix it with some options, we will get to that later. You should know about what is block size in Linux before proceeding.
root@linuxnix:/proc# df Filesystem 1K-blocks Used Available Use% Mounted on udev 3961912 4 3961908 1% /dev tmpfs 794540 1372 793168 1% /run /dev/sdb1 22951396 14653116 7109368 68% / none 4 0 4 0% /sys/fs/cgroup none 5120 0 5120 0% /run/lock none 3972696 385424 3587272 10% /run/shm none 102400 64 102336 1% /run/user /dev/sda1 99800 3440 96361 4% /boot/efi /dev/sda4 849698404 239254192 567258908 30% /opt /dev/sda2 95990540 73446284 17645084 81% /home /dev/mmcblk0p1 3871744 1880480 1991264 49% /media/surendra/9016-4EF8
Before going in to examples, we will try to decode some of the above lines.
Example 2: Understanding normal mount mappings
/dev/sdb1 22G 14G 6.8G 68% /
/dev/sdb1 partition is mounted on / whose size is 22G, used is 14Gb and available is 6.8Gb.
Example 3: Understanding special mount mappings.
udev 3.8G 4.0K 3.8G 1% /dev
Some times, We have to mount some folders in special partitions which are virtual in nature. This will help in preventing accidental deletion of important data for system to work properly. The above example /dev folder which contain device file information and may vary with every reboot is actually mounted with a virtual file system.
Example 4: Understanding below line
tmpfs 794540 1372 793168 1% /run
The /run folder is recent implementation which contain process related information and which should not be deleted by any one until next reboot.
Example 5: If you observe below line, the virtual partition is none and mounted on /run/user. In other words this is tactfully virtual file system with the virtual file system, because /run is using tmpfs virtual partition.
none 102400 64 102336 1% /run/user
Understanding remote mounts in Linux df command output
Example 6: Do you know we can mount remote file systems like Samba, NFS, SSH and FTP? Below are example lines you may see in df command output.
Mounting FTP locally
Example “df -T” output line for ftp mount/share
curlftpfs#ftp://surendra_a:redhat@ftp2.linuxnix.com/ 7.5T 0 7.5T 0% /ftpmount
Mounting SSH locally
Example “df -T” output line for SSH mount/share
root@192.34.60.23:/root fuse.sshfs 20G 4.0G 15G 22% /mnt
Mounting NFS locally
Example “df -T” output line for NFS mount/share
abc.linuxnix.com:/home nfs 100G 1G 99G 1% /mnt/nfs/home
Mounting Samba locally
Example “df -T” output line for samba mount/share
//surtr/Files smbfs 254G 140G 115G 55% /mnt/Files
Example 7: Let us start exploring df command with options. The first in the list is -h option. As you can see, using the df command without any options can list you the file system usage, however it lists the size for
each file system in number of blocks. A better way to look at it, is to print the size in a more human readable format, and this is what the -h option does. As you notice below, the -h option changed the way
the size column looks like. It is most likely that you will be using the df -h “then combine it with more options” than using just df.
root@linuxnix:/proc# df -h Filesystem Size Used Avail Use% Mounted on udev 3.8G 4.0K 3.8G 1% /dev tmpfs 776M 1.4M 775M 1% /run /dev/sdb1 22G 14G 6.8G 68% / none 4.0K 0 4.0K 0% /sys/fs/cgroup none 5.0M 0 5.0M 0% /run/lock none 3.8G 349M 3.5G 9% /run/shm none 100M 64K 100M 1% /run/user /dev/sda1 98M 3.4M 95M 4% /boot/efi /dev/sda4 811G 229G 541G 30% /opt /dev/sda2 92G 71G 17G 81% /home /dev/mmcblk0p1 3.7G 1.8G 1.9G 49% /media/surendra/9016-4EF8 root@192.34.60.236:/root 20G 4.0G 15G 22% /mnt
Example 8: Using the “df” with -T option. Moving on now, the -T options, which prints the type of each file system, and by that it means the format of each file system. As you can notice below, adding the -T option, will add a new column which is the file system type.
root@linuxnix:/proc# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on udev devtmpfs 3961912 4 3961908 1% /dev tmpfs tmpfs 794540 1368 793172 1% /run /dev/sdb1 ext4 22951396 14653560 7108924 68% / none tmpfs 4 0 4 0% /sys/fs/cgroup none tmpfs 5120 0 5120 0% /run/lock none tmpfs 3972696 356728 3615968 9% /run/shm none tmpfs 102400 64 102336 1% /run/user /dev/sda1 vfat 99800 3440 96361 4% /boot/efi /dev/sda4 ext4 849698404 239254192 567258908 30% /opt /dev/sda2 ext4 95990540 73456020 17635348 81% /home /dev/mmcblk0p1 vfat 3871744 1880480 1991264 49% /media/surendra/9016-4EF8 root@192.34.60.236:/root fuse.sshfs 20511356 4181644 15264756 22% /mnt
Example 9: Using the “df” with -t option. Notice that Linux is case sensitive, the -t options will only list file system with the type you specified in the arguments. This will not print any other file systems which are mounted at present.
root@linuxnix:/proc# df -t fuse.sshfs Filesystem 1K-blocks Used Available Use% Mounted on root@192.34.60.236:/root 20511356 4181672 15264728 22% /mnt
Example 10: Note that you can combine the -t with -h for a human readable view, however, make sure that the -t option is the last
option facing the argument “the file system type”. In other words, it should be “df -ht ext3” and not “df -th ext3”.
root@linuxnix:/proc# df -ht vfat Filesystem Size Used Avail Use% Mounted on /dev/sda1 98M 3.4M 95M 4% /boot/efi /dev/mmcblk0p1 3.7G 1.8G 1.9G 49% /media/surendra/9016-4EF8
Example 11: Using the “df” with -x option. The -x option, excludes any file system with the given type in the arguments, in other words, it will print all file systems, that do not match the file system type you mentioned. This is very neat when you want to focus on file systems and the
one you are mentioning is not interesting for you. The below example shows how to view all file system that are not tmpfs type.
root@linuxnix:/proc# df -hTx tmpfs Filesystem Type Size Used Avail Use% Mounted on udev devtmpfs 3.8G 4.0K 3.8G 1% /dev /dev/sdb1 ext4 22G 14G 6.8G 68% / /dev/sda1 vfat 98M 3.4M 95M 4% /boot/efi /dev/sda4 ext4 811G 229G 541G 30% /opt /dev/sda2 ext4 92G 71G 17G 81% /home /dev/mmcblk0p1 vfat 3.7G 1.8G 1.9G 49% /media/surendra/9016-4EF8 root@192.34.60.236:/root fuse.sshfs 20G 4.0G 15G 22% /mnt
As you are getting now, we have to make the -x option facing the “tmpfs” which is the argument. “df -Thx tmpfs” will also work in the same fashion, however “df -xhT tmpfs” will not work.
Example 12: Using the “df” with -i option to print inode details. Another way to view the utilization of your system is to check the number of inodes utilized by each file system. A side note is that for each file system type, file system might become full even if there is still space left, and that is because it reached the maximum number of inodes the inode table can take. This is depending on the file system type. So in some cases, it is handy to know the number of inodes utilized by each file system.
root@linuxnix:/proc# df -i Filesystem Inodes IUsed IFree IUse% Mounted on udev 990478 567 989911 1% /dev tmpfs 993174 642 992532 1% /run /dev/sdb1 1466368 698227 768141 48% / none 993174 11 993163 1% /sys/fs/cgroup none 993174 3 993171 1% /run/lock none 993174 342 992832 1% /run/shm none 993174 32 993142 1% /run/user /dev/sda1 0 0 0 - /boot/efi /dev/sda4 53968896 11752 53957144 1% /opt /dev/sda2 6111232 46688 6064544 1% /home /dev/mmcblk0p1 0 0 0 - /media/surendra/9016-4EF8 root@192.34.60.236:/root 1310720 124303 1186417 10% /mnt
Note: Now columns represent different stuff. Second column represents total number of Inodes, third used, fourth free inodes and fifth shows % used inodes.
Example 13: Using the “df” with a certain directory in the arguments. One final thing to mention about df , is that you can use it on a specific directory. Although it will not show the directory utilization “other commands can do this”, but it will show you which file system this directory is part of, and the utilization for the file system to which the directory belongs. it is still handy to have a big picture of how much space left you can fill up this directory.
root@linuxnix:/proc# df -hT /home Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext4 92G 71G 17G 81% /home
Example 14: List only local partitions and mount points.
root@linuxnix:/proc# df -l Filesystem 1K-blocks Used Available Use% Mounted on udev 3961912 4 3961908 1% /dev tmpfs 794540 1332 793208 1% /run /dev/sdb1 22951396 14653660 7108824 68% / none 4 0 4 0% /sys/fs/cgroup none 5120 0 5120 0% /run/lock none 3972696 342676 3630020 9% /run/shm none 102400 64 102336 1% /run/user /dev/sda1 99800 3440 96361 4% /boot/efi /dev/sda4 849698404 239254192 567258908 30% /opt /dev/sda2 95990540 73449484 17641884 81% /home /dev/mmcblk0p1 3871744 1880480 1991264 49% /media/surendra/9016-4EF8
Example 15: Display all available mount points.
root@linuxnix:/proc# df -a Filesystem 1K-blocks Used Available Use% Mounted on sysfs 0 0 0 - /sys proc 0 0 0 - /proc udev 3961912 4 3961908 1% /dev devpts 0 0 0 - /dev/pts tmpfs 794540 1332 793208 1% /run /dev/sdb1 22951396 14653652 7108832 68% / 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 cgroup 0 0 0 - /sys/fs/cgroup/cpuset cgroup 0 0 0 - /sys/fs/cgroup/cpu cgroup 0 0 0 - /sys/fs/cgroup/cpuacct cgroup 0 0 0 - /sys/fs/cgroup/memory cgroup 0 0 0 - /sys/fs/cgroup/devices cgroup 0 0 0 - /sys/fs/cgroup/freezer cgroup 0 0 0 - /sys/fs/cgroup/blkio cgroup 0 0 0 - /sys/fs/cgroup/perf_event cgroup 0 0 0 - /sys/fs/cgroup/hugetlb none 0 0 0 - /sys/firmware/efi/efivars none 5120 0 5120 0% /run/lock none 3972696 342776 3629920 9% /run/shm none 102400 64 102336 1% /run/user none 0 0 0 - /sys/fs/pstore /dev/sda1 99800 3440 96361 4% /boot/efi /dev/sda4 849698404 239254192 567258908 30% /opt /dev/sda2 95990540 73449556 17641812 81% /home systemd 0 0 0 - /sys/fs/cgroup/systemd /dev/sdb1 22951396 14653652 7108832 68% /var/lib/docker/aufs gvfsd-fuse 0 0 0 - /run/user/1000/gvfs /dev/mmcblk0p1 3871744 1880480 1991264 49% /media/surendra/9016-4EF8 root@192.34.60.236:/root 20511356 4183856 15262544 22% /mnt
Example 16: Display POSIX standard format which is useful when writing shell scripts.
df -P
Output:
root@linuxnix:/proc# df -P Filesystem 1024-blocks Used Available Capacity Mounted on udev 3961912 4 3961908 1% /dev tmpfs 794540 1332 793208 1% /run /dev/sdb1 22951396 14653672 7108812 68% / none 4 0 4 0% /sys/fs/cgroup none 5120 0 5120 0% /run/lock none 3972696 342772 3629924 9% /run/shm none 102400 64 102336 1% /run/user /dev/sda1 99800 3440 96361 4% /boot/efi /dev/sda4 849698404 239254192 567258908 30% /opt /dev/sda2 95990540 73449112 17642256 81% /home /dev/mmcblk0p1 3871744 1880480 1991264 49% /media/surendra/9016-4EF8 root@192.34.60.236:/root 20511356 4183936 15262464 22% /mnt
Example 17: Did not like any of the formats and want your own format? Do not worry, df have –output option which support below fields.
Valid field names are: ‘source’, ‘fstype’, ‘itotal’, ‘iused’, ‘iavail’, ‘ipcent’,
‘size’, ‘used’, ‘avail’, ‘pcent’ and ‘target’
Suppose, I want to see partition and just mount point, use below example.
root@linuxnix:/proc# df --output=source,target Filesystem Mounted on udev /dev tmpfs /run /dev/sdb1 / none /sys/fs/cgroup none /run/lock none /run/shm none /run/user /dev/sda1 /boot/efi /dev/sda4 /opt /dev/sda2 /home /dev/mmcblk0p1 /media/surendra/9016-4EF8 root@192.34.60.236:/root /mnt
In our next post we will see about dd command.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018