The df command displays the disk space usage for the Linux filesystems. It displays the amount of total and free disk space available on the mounted file systems. Using the command, we can also find used blocks and inodes in the file system. In this article, we will explain various options of df command with examples.
1) Display Filesystem Disk Space Usage
By default, df command displays all mounted filesystems. Display partition size in 1 kilobyte blocks and the amount of used and available disk space in kilobytes.
Filesystem
- Filesystem path
1K-blocks
- Partition size in 1 kilobyte blocks
Used
- used blocks (in KB, MB,GB)
Available
- unused blocks (in KB, MB,GB)
Mounted on
- display filesystem mount point path
Use%
- percentage of used blocks against total number of blocks in a filesystem
$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda7 10079084 6468104 3098980 68% / udev 1521232 4 1521228 1% /dev tmpfs 613188 1164 612024 1% /run none 5120 0 5120 0% /run/lock none 1532964 304 1532660 1% /run/shm none 102400 8 102392 1% /run/user /dev/sda8 5039616 2948248 1835368 62% /home /dev/sda2 209715196 203404612 6310584 97% /media/Data
2) Display Disk Usage in Readable Format ( KB, MB, GB)
With -h
options, instead of printing the number of blocks, the data is printed in KB ,MB and GB. The '1K-block' column is replaced with 'Size' column.
# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 7.6G 1.9G 5.4G 26% / tmpfs 478M 0 478M 0% /dev/shm
# df -h /dev/sda{7,8} Filesystem Size Used Avail Use% Mounted on /dev/sda7 9.7G 6.2G 3.0G 68% / /dev/sda8 4.9G 2.9G 1.8G 62% /home
# df -h /dev/xvd{b,c} Filesystem Size Used Avail Use% Mounted on /dev/xvdb 976M 2.6M 907M 1% /backup /dev/xvdc 2.0G 6.0M 1.8G 1% /oracledb
The -H
or --si
option is similar to -h, but is uses powers of 1024 and not 1000(as with -h).
# df -H /dev/sda{7,8} Filesystem Size Used Avail Use% Mounted on /dev/sda7 11G 6.7G 3.2G 68% / /dev/sda8 5.2G 3.1G 1.9G 62% /home
3) Display Disk Usage in KiloByte (KB)
You can use -B
or --block-size=SIZE
option to provide custom format of sizes. SIZE could be (or may be an integer optionally followed by) one of following KB (1000) or K (1024).
# df -BK Filesystem 1K-blocks Used Available Use% Mounted on /dev/xvda2 10473452K 1001728K 9471724K 10% / /dev/xvdb 999320K 2564K 927944K 1% /backup /dev/xvdc 1998672K 6144K 1871288K 1% /oracledb
# df -BKB Filesystem 1kB-blocks Used Available Use% Mounted on /dev/xvda2 10724815kB 1025770kB 9699046kB 10% / /dev/xvdb 1023304kB 2626kB 950215kB 1% /backup /dev/xvdc 2046641kB 6292kB 1916199kB 1% /oracledb
The -k
option is similar to --block-size=1k
# df -k Filesystem 1K-blocks Used Available Use% Mounted on /dev/xvda2 10473452 1001728 9471724 10% / /dev/xvdb 999320 2564 927944 1% /backup /dev/xvdc 1998672 6144 1871288 1% /oracledb
4) Display Disk Usage in MegaByte (MB)
Same as above, df could display space utilization in MB (1000*1000) and M (1024*1024).
# df -BM Filesystem 1M-blocks Used Available Use% Mounted on /dev/xvda2 10228M 979M 9250M 10% / /dev/xvdb 976M 3M 907M 1% /backup /dev/xvdc 1952M 6M 1828M 1% /oracledb
# df -m Filesystem 1M-blocks Used Available Use% Mounted on /dev/xvda2 10228 979 9250 10% / /dev/xvdb 976 3 907 1% /backup /dev/xvdc 1952 6 1828 1% /oracledb
# df -BMB Filesystem 1MB-blocks Used Available Use% Mounted on /dev/xvda2 10725MB 1026MB 9700MB 10% / /dev/xvdb 1024MB 3MB 951MB 1% /backup /dev/xvdc 2047MB 7MB 1917MB 1% /oracledb
5) Display Disk Usage in GigaByte ( GB)
You can either use -BG
or human readable -h
option to display space in Giga Byte.
# df -BG Filesystem 1G-blocks Used Available Use% Mounted on /dev/xvda2 10G 1G 10G 10% / /dev/xvdb 1G 1G 1G 1% /backup /dev/xvdc 2G 1G 2G 1% /oracledb
But human readable will display in GB, MB and KB based of filesystem size.
# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda2 10G 979M 9.1G 10% / /dev/xvdb 976M 2.6M 907M 1% /backup /dev/xvdc 2.0G 6.0M 1.8G 1% /oracledb
6) Display Filesystem Belong to File
If a file name is provided as the argument to df command, the filesystem on which the file resides is displayed.
# df file1.txt Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda8 5039616 2945900 1837716 62% /home
7) Display Selective Filesystem
You can filter display by passing specific argument to display the particular filesystems.
# df /dev/sda{7,8} Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda7 10079084 6468104 3098980 68% / /dev/sda8 5039616 2948336 1835280 62% /home
# df -h /dev/xvd{b,c} Filesystem Size Used Avail Use% Mounted on /dev/xvdb 976M 2.6M 907M 1% /backup /dev/xvdc 2.0G 6.0M 1.8G 1% /oracledb
8) Display Grand Total Disk Usage
The --total
option produces a grand total of all filesystems.
# df --total Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda7 10079084 6468104 3098980 68% / udev 1521232 4 1521228 1% /dev tmpfs 613188 1164 612024 1% /run none 5120 0 5120 0% /run/lock none 1532964 304 1532660 1% /run/shm none 102400 8 102392 1% /run/user /dev/sda8 5039616 2948336 1835280 62% /home /dev/sda2 209715196 203407688 6307508 97% /media/Data total 228608800 212825608 15015192 94%
Note: Last line displays total space usage.
9) Display All Filesystem Including dummy
df command followed by -a
or --all
option includes dummy filesystems (virtual fs like proc, sys etc).
# df -a Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda7 10079084 6468104 3098980 68% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys none 0 0 0 - /sys/kernel/debug none 0 0 0 - /sys/kernel/security udev 1521232 4 1521228 1% /dev devpts 0 0 0 - /dev/pts tmpfs 613188 1164 612024 1% /run none 102400 8 102392 1% /run/user /dev/sda8 5039616 2948312 1835304 62% /home /dev/sda2 209715196 203406664 6308532 97% /media/Data binfmt_misc 0 0 0 - /proc/sys/fs/binfmt_misc gvfsd-fuse 0 0 0 - /run/user/gvfs
10) Display Inodes Information
The inodes can be printed with -i
or --inodes
option. Here, total number of inodes, used, free and %age of used inodes are shown respectively.
$ df -i /dev/sda{7,8} Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda7 640848 288304 352544 45% / /dev/sda8 320000 50760 269240 16% /home
11) Display Filesystem Type
If you want to print file system types as well, -T
or --print-type
switch is used
$ df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sda7 ext4 10079084 6468168 3098916 68% / udev devtmpfs 1521232 4 1521228 1% /dev tmpfs tmpfs 613188 1164 612024 1% /run none tmpfs 5120 0 5120 0% /run/lock none tmpfs 1532964 304 1532660 1% /run/shm none tmpfs 102400 8 102392 1% /run/user /dev/sda8 ext4 5039616 2948128 1835488 62% /home /dev/sda2 fuseblk 209715196 203427116 6288080 98% /media/Data
12) Display Filesystem using specific Type
Now, suppose you want to print filesystems of a particular type, say ext4 only. The -t
or --type=TYPE
(ext4 here) option will do this for you.
# df -t ext4 Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda7 10079084 6468168 3098916 68% / /dev/sda8 5039616 2948128 1835488 62% /home
# df -t tmpfs Filesystem 1K-blocks Used Available Use% Mounted on tmpfs 613188 1164 612024 1% /run none 5120 0 5120 0% /run/lock none 1532964 304 1532660 1% /run/shm none 102400 8 102392 1% /run/user
Similarly, for excluding a particular type of filesystem, use -x
or --exclude-type=TYPE
.
# df -x tmpfs Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda7 10079084 6468168 3098916 68% / udev 1521232 4 1521228 1% /dev /dev/sda8 5039616 2948164 1835452 62% /home /dev/sda2 209715196 203433404 6281792 98% /media/Data
ie You use this trick to display all nfs mount points using df command.
# df -HP -t nfs
13) Display Limiting To Local Filesystem
By default, df command displays remote mounted filesystems as well. The -l option limits the listing to local filesystems only.
In order to check usage of this option, first we will mount a remote nfs filesystem.
Now we execute the df command:
$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda7 10079084 6533664 3033420 69% / udev 1521232 4 1521228 1% /dev tmpfs 613188 1172 612016 1% /run none 5120 0 5120 0% /run/lock none 1532964 304 1532660 1% /run/shm none 102400 12 102388 1% /run/user /dev/sda8 5039616 2948364 1835252 62% /home /dev/sda2 209715196 203556460 6158736 98% /media/Data 192.168.1.14:/nfs 9547136 3640576 5421568 41% /home/nfs
And with -l option:
$ df -l Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda7 10079084 6533664 3033420 69% / udev 1521232 4 1521228 1% /dev tmpfs 613188 1172 612016 1% /run none 5120 0 5120 0% /run/lock none 1532964 304 1532660 1% /run/shm none 102400 12 102388 1% /run/user /dev/sda8 5039616 2948388 1835228 62% /home /dev/sda2 209715196 203565068 6150128 98% /media/Data
We have gone through almost all options of df command with examples. From the above all options we could understand the power of df command even we have lots of new tools available. Let us know if you find anything interesting in the comment section.