Linux df command


The df command in Linux is used to display the amount of disk space available and used on the file systems. It shows the available and used space on mounted filesystems, helping users monitor disk usage.

Basic Syntax:

df [options] [filesystem]

Commonly Used Options:

  • -h: Human-readable format (displays sizes in KB, MB, GB, etc.).
  • -T: Show the filesystem type.
  • -a: Include all file systems, even ones that are 0 bytes in size.
  • -t <type>: Show only filesystems of the specified type.
  • -l: Show only local filesystems (exclude network-mounted file systems).
  • -i: Show inode information (useful for checking inode usage).

Basic Usage:

df

Example Output:

Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 1024000 512000 512000 50% / /dev/sdb1 2048000 1024000 1024000 50% /mnt/data tmpfs 1024000 1000 1023000 1% /run

Explanation of Output:

  • Filesystem: The name of the filesystem or device (e.g., /dev/sda1, /dev/sdb1, tmpfs).
  • 1K-blocks: The total size of the filesystem in 1K blocks.
  • Used: The amount of space used on the filesystem.
  • Available: The amount of available space left on the filesystem.
  • Use%: The percentage of used space on the filesystem.
  • Mounted on: The mount point (directory where the filesystem is mounted) in the system (e.g., /, /mnt/data).

Example with -h (Human-readable format):

df -h

Sample Output:

Filesystem Size Used Avail Use% Mounted on /dev/sda1 1000M 500M 500M 50% / /dev/sdb1 2000M 1000M 1000M 50% /mnt/data tmpfs 1000M 1M 999M 1% /run
  • The output is now in human-readable format (MB, GB) instead of 1K blocks, making it easier to understand the disk usage.

Example with -T (Filesystem type):

df -T

Sample Output:

Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sda1 ext4 1024000 512000 512000 50% / /dev/sdb1 ext4 2048000 1024000 1024000 50% /mnt/data tmpfs tmpfs 1024000 1000 1023000 1% /run
  • The -T option shows the type of each filesystem (e.g., ext4, tmpfs).

Example with -i (Inode information):

df -i

Sample Output:

Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda1 256000 1024 254976 1% / /dev/sdb1 512000 2048 509952 1% /mnt/data tmpfs 256000 20 255980 1% /run
  • Inodes: Filesystem inodes represent individual files and directories.
  • IUsed: Number of inodes in use.
  • IFree: Number of free inodes available.
  • IUse%: Percentage of used inodes on the filesystem.

Example with -a (Include all filesystems):

df -a

Sample Output:

Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 1024000 512000 512000 50% / /dev/sdb1 2048000 1024000 1024000 50% /mnt/data tmpfs 1024000 1000 1023000 1% /run /dev/sr0 700000 700000 0 100% /mnt/cdrom
  • The -a option includes all filesystems, including the CD-ROM (/dev/sr0), even if their space is fully used (100%).

Example with -t <type> (Filter by filesystem type):

df -t ext4

Sample Output:

Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 1024000 512000 512000 50% / /dev/sdb1 2048000 1024000 1024000 50% /mnt/data
  • The -t ext4 option filters the output to show only filesystems of type ext4.

Example with -l (Local filesystems only):

df -l

Sample Output:

Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 1024000 512000 512000 50% / /dev/sdb1 2048000 1024000 1024000 50% /mnt/data
  • The -l option filters out network-mounted file systems (such as NFS, CIFS, etc.) and only shows local filesystems.

Conclusion:

The df command provides an overview of disk space usage, which is essential for monitoring storage on a Linux system. By using options like -h, -T, -i, and others, you can customize the output to get more detailed information or to filter specific types of filesystems. It's a very useful tool for ensuring you have enough disk space and for troubleshooting disk space issues.