In Linux, the default output of disk usage commands often displays raw byte values, which can be difficult for users to interpret. To make disk usage information more user-friendly, Linux provides various tools that can display disk usage in a human-readable format.
The du
Command
The du
(disk usage) command is a powerful tool for analyzing disk usage on Linux systems. By default, du
displays the disk usage in bytes, which can be difficult to read. To view disk usage in a more human-readable format, you can use the following options:
du -h
The -h
(human-readable) option will display the disk usage in a more intuitive format, such as kilobytes (kB), megabytes (MB), or gigabytes (GB).
Example output:
$ du -h /var/log
4.0K /var/log/alternatives.log
12K /var/log/apt
4.0K /var/log/auth.log
...
You can also use the -d
(depth) option to specify the maximum depth of the directory tree to display:
du -h -d 1 /
This will show the disk usage for the root directory (/
) and its immediate subdirectories.
The df
Command
The df
(disk free) command is another useful tool for viewing disk usage. By default, df
displays the total, used, and available disk space for each file system.
To view the disk usage in a human-readable format, you can use the -h
option:
df -h
Example output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 20G 80G 20% /
tmpfs 16G 1.6M 16G 1% /run
/dev/sda2 500G 450G 51G 90% /home
This output shows the disk usage for each file system in a more readable format, making it easier to understand the available and used disk space.
Combining du
and df
You can combine the du
and df
commands to get a more comprehensive view of disk usage on your system. For example, you can use du
to analyze the disk usage of a specific directory, and then use df
to check the overall disk usage of the file system that the directory is located on.
By understanding how to view disk usage in a human-readable format, you can more effectively manage and optimize the storage resources on your Linux system.