How to use df command?

Understanding the df Command in Linux

The df command, short for "disk free," is a powerful tool in the Linux operating system that allows you to view information about the file system and the available disk space on your system. This command is particularly useful when you need to monitor the disk usage and ensure that your file system has enough free space to accommodate your needs.

Syntax and Usage

The basic syntax for the df command is as follows:

df [options] [file or directory]

Here's a breakdown of the different components:

  • df: This is the command itself, which invokes the disk free utility.
  • [options]: These are the various flags and parameters that you can use to customize the output of the df command. Some common options include -h (human-readable format), -i (show inode information), and -T (show file system type).
  • [file or directory]: This is an optional parameter that allows you to specify a specific file or directory for which you want to view the disk usage information.

When you run the df command without any additional parameters, it will display the disk usage information for all mounted file systems on your system. Here's an example output:

$ df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1       50685756 44987340   3314416  90% /
tmpfs            1624860       12   1624848   1% /run
/dev/sda2      194690812 78983088 103326612  43% /home
tmpfs            8124288       0   8124288   0% /dev/shm
tmpfs               5120       0      5120   0% /run/lock

This output shows the file system, the total disk space, the used space, the available space, the percentage of used space, and the mount point for each file system on the system.

Interpreting the Output

The df command provides a wealth of information about the file system, and understanding how to interpret this output is crucial. Here's a breakdown of the different columns:

  1. Filesystem: This column shows the name of the file system or the device that the file system is mounted on.
  2. 1K-blocks: This column displays the total size of the file system in 1-kilobyte blocks.
  3. Used: This column shows the amount of disk space that has been used.
  4. Available: This column displays the amount of disk space that is available for use.
  5. Use%: This column shows the percentage of the file system that has been used.
  6. Mounted on: This column indicates the mount point, which is the directory where the file system is mounted.

By analyzing this information, you can quickly identify which file systems are running low on disk space and take appropriate actions to free up space or expand the file system as needed.

Filtering and Customizing the Output

The df command offers several options to customize the output and filter the information displayed. Some common use cases include:

  1. Showing human-readable sizes: Use the -h or --human-readable option to display the disk space in a more human-friendly format, such as megabytes (MB) or gigabytes (GB), instead of 1-kilobyte blocks.
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        49G   44G  3.2G  90% /
tmpfs           1.6G   12K  1.6G   1% /run
/dev/sda2       189G   77G  101G  43% /home
tmpfs           7.9G     0  7.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
  1. Showing inode information: Use the -i or --inodes option to display information about the inode usage of the file systems.
$ df -i
Filesystem      Inodes  IUsed   IFree IUse% Mounted on
/dev/sda1      3276800 2898866  377934   89% /
tmpfs          406215      41  406174    1% /run
/dev/sda2     12582912 1964411 10618501   16% /home
tmpfs          406215       1  406214    1% /dev/shm
tmpfs          406215       3  406212    1% /run/lock
  1. Showing specific file systems: Use the -t or --type option to display information only for the specified file system types.
$ df -t ext4
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1       50685756 44987340   3314416  90% /
/dev/sda2      194690812 78983088 103326612  43% /home
  1. Showing specific mount points: Provide a file or directory as an argument to the df command to display information only for the file system containing that file or directory.
$ df /home
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda2      194690812 78983088 103326612  43% /home

By using these options, you can tailor the output of the df command to suit your specific needs and gain a better understanding of the disk usage on your Linux system.

Conclusion

The df command is a valuable tool for monitoring and managing disk space in a Linux environment. By understanding how to use the df command and interpret its output, you can effectively identify and address any disk space issues on your system. Whether you need to check the overall disk usage, analyze inode information, or focus on specific file systems, the df command provides the necessary insights to help you maintain a healthy and well-managed file system.

0 Comments

no data
Be the first to share your comment!