DF COMMAND
Introduction
In any OS, manage disk space is an important job. In this tutorial, we’ll take a look at how to do this with the df command.
The df command is a powerful utility that we used to see how much space do I have free on the disk. Can use to remember the df command is “Disk-Free”.
Basic Syntax
Let’s understand the basic syntax:
df [OPTION]... [FILE]...
The options parameters influence how the df
command interacts with the input. We’ll learn options most important in the upcoming sections.
The file parameters we set the files we want information or leave blank so we will analyze the entire disk.
2.1. Default Behavior
When using the only df, it shows all drives.
[root@lostrouter ~]# df
Filesystem Size Used Available Use% Mounted on
devtmpfs 237760 0 237760 0% /dev
tmpfs 249332 0 249332 0% /dev/shm
tmpfs 249332 4580 244752 2% /run
tmpfs 249332 0 249332 0% /sys/fs/cgroup
/dev/mapper/centos-root 52403200 5690220 46712980 11% /
/dev/sda1 1038336 170856 867480 17% /boot
/dev/mapper/centos-home 29337604 33076 29304528 1% /home
tmpfs 49868 0 49868 0% /run/user/0
By default, df shows values in 1-kilobyte blocks.
2.2 Understanding Output
The df command lists too many columns, but the columns name should be self-explanatory:
- Filesystem: The name of each drive. Can be hard drives, logical drives, and virtual drives.
- Size: The size of the filesystem.
- Used: The amount of space used on the filesystem.
- Available: The amount of space free on the filesystem.
- Use%: The percent of space used on the filesystem.
- Mounted on: Show the mount point. The directory where the filesystem is located.
Main Option
Among the available options, some use them very often in our daily. These we can mention:
df -h : Shows disk space in a human-readable format. Display in kilobytes(K), megabytes(M), and gigabytes(G).
[root@lostrouter ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 233M 0 233M 0% /dev
tmpfs 244M 0 244M 0% /dev/shm
tmpfs 244M 4.5M 240M 2% /run
tmpfs 244M 0 244M 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 5.5G 45G 11% /
/dev/sda1 1014M 167M 848M 17% /boot
/dev/mapper/centos-home 28G 33M 28G 1% /home
tmpfs 49M 0 49M 0% /run/user/0
df -T : Shows what filesystem type.
[root@lostrouter ~]# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
devtmpfs devtmpfs 237760 0 237760 0% /dev
tmpfs tmpfs 249332 0 249332 0% /dev/shm
tmpfs tmpfs 249332 4580 244752 2% /run
tmpfs tmpfs 249332 0 249332 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 52403200 5690368 46712832 11% /
/dev/sda1 xfs 1038336 170856 867480 17% /boot
/dev/mapper/centos-home xfs 29337604 33076 29304528 1% /home
tmpfs tmpfs 49868 0 49868 0% /run/user/0
df -i : Shows free and used inodes.
[root@lostrouter ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
devtmpfs 59440 335 59105 1% /dev
tmpfs 62333 1 62332 1% /dev/shm
tmpfs 62333 442 61891 1% /run
tmpfs 62333 16 62317 1% /sys/fs/cgroup
/dev/mapper/centos-root 26214400 65045 26149355 1% /
/dev/sda1 524288 332 523956 1% /boot
/dev/mapper/centos-home 14675968 13 14675955 1% /home
tmpfs 62333 1 62332 1% /run/user/0
Conclusion
The df command can be very useful for monitor drives usage and shows directories or files that are occupying amounts of space.