How does df command work internally in Linux?

The df command in Linux is used to report the amount of disk space used and available on file systems. It stands for "disk filesystem". Internally, the df command gathers file system statistics by accessing the kernel's virtual filesystems, particularly the /proc and /sys filesystems, which contain real-time information about various system metrics.

When invoked, df retrieves data such as total disk space, used space, available space, and the filesystem type of each mounted file system. This information is formatted into a human-readable form and displayed to the user.

Here is an example of how to use the df command:

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   30G   20G  60% /
tmpfs           1.9G  1.1M  1.9G   1% /dev/shm
/dev/sda2        100G  75G   25G  75% /home

df command Linux disk usage file system statistics Linux commands