The DU or the disk usage command is used for monitoring the disk space usage of each file or directory of your Linux system. By using this command, you can instantly get to know which files or directories of your system are consuming more storage resources so that you can manage them accordingly. This guide will tell you how to use the DU command effectively in Linux.
The DU Command in Linux
The DU command in Linux finds multiple uses that can be realized by executing the following command:
$ du -- help
From the output of this command shown in the following image, you can see all the different options that can be used with this command to serve different purposes:
Now, we will quickly share with you a few examples through which you will gain clarity regarding the usage of this command.
Example # 1: Using the DU Command Without any Options
Despite all the options available with the DU command, it can also be used independently without any of these options. This command simply lists down the disk usage of all the files and directories present on the system. This command can be used in the following manner:
The disk usage of our Linux system is shown in the following image:
Example # 2: Printing the Output of the DU Command in Human-Readable Format
In the previous example, we managed to print the disk usage, but it was not in human-readable format, i.e., without any measurement units. Therefore, to print the disk usage in human-readable format, you have to use the DU command in the following way:
$ du –h
The output of the DU command in human-readable format is shown in the image provided below:
Example # 3: Printing the Total Disk Usage With the DU Command
We can also use the DU command to print the total disk usage once it has printed the disk usage of the individual files and directories in the following manner:
$ du –c
You can see the total disk usage at the end of the output of this command, as shown in the following image:
Example # 4: Printing the Output of the DU Command up to a Certain Specified Level
The DU command prints the disk usage while going deep inside the directories of your system recursively. However, you can restrict this output to a certain specified level by using the following variant of the DU command in Linux:
$ du –d 1
This modified DU command will print the disk usage on the terminal only up to the first level, i.e., it will not go deep down beyond the first level, as shown in the following image. Depending upon your requirements, you can define any level of your choice over here:
With the help of this article, you can quickly learn the usage of the DU command in Linux. Moreover, by making use of the help manual of this command, you will also be able to learn the other usage scenarios of this command on your own.