How to use df command to display disk usage in human-readable format?

0313

Understanding the df Command

The df command in Linux is a powerful tool used to display information about the file system, including the total size, used space, and available space of each mounted file system. By default, the df command displays the disk usage in a format that may not be easily readable for users, especially when dealing with large file systems.

To display the disk usage in a human-readable format, you can use the -h or --human-readable option with the df command.

Using the df Command with the -h Option

The -h option stands for "human-readable" and will display the disk usage in a format that is easier to understand. This format uses common size units such as kilobytes (kB), megabytes (MB), gigabytes (GB), and terabytes (TB), making the output more intuitive.

Here's an example of using the df command with the -h option:

df -h

This will output something similar to the following:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       100G   50G   45G  53% /
tmpfs           16G  1.6M   16G   1% /run
/dev/sda2       500G  450G   50G  90% /home

In this example, the file system /dev/sda1 has a total size of 100 GB, with 50 GB used and 45 GB available, and is mounted on the root directory /. The file system /dev/sda2 has a total size of 500 GB, with 450 GB used and 50 GB available, and is mounted on the /home directory.

Customizing the Output Format

If you want to further customize the output format, you can use the --block-size option. This option allows you to specify the unit of measurement for the output, such as bytes, kilobytes, or megabytes.

For example, to display the disk usage in kilobytes, you can use the following command:

df --block-size=1024

This will output the disk usage in kilobytes, which can be useful if you need to perform calculations or compare the sizes of different file systems.

Mermaid Diagram: Understanding the df Command

Here's a Mermaid diagram that explains the core concepts of the df command:

graph TD A[df command] --> B[Display file system information] B --> C[Total size of file system] B --> D[Used space] B --> E[Available space] C --> F[Displayed in human-readable format] D --> F E --> F F --> G[Easy to understand]

This diagram shows that the df command is used to display information about the file system, including the total size, used space, and available space. By using the -h or --human-readable option, the output is displayed in a format that is easy to understand, using common size units like kilobytes, megabytes, and gigabytes.

Conclusion

The df command is a essential tool for Linux users to quickly and easily understand the disk usage of their file systems. By using the -h or --human-readable option, you can display the disk usage in a format that is more intuitive and easier to read. Additionally, you can further customize the output format using the --block-size option to suit your specific needs.

0 Comments

no data
Be the first to share your comment!