How to make use of du command in Linux

1

The du command is used to control the space for storing in Linux, for instance, to test how a lot house is utilized by the information and what sort of is unfastened to retailer new information and to put in new applications. With the assistance of the du command, we will in finding out the distance occupied through the information and directories in Linux, and on this write-up, we can be informed the usage of the du command on Linux with the assistance of other examples.

How to make use of the du command in Linux

The du command is used to learn the way a lot machine reminiscence is utilized by other directories or subdirectories. The common syntax of the du command in Linux is:

$ du [options] listing/subdirectory

There are other choices that can be utilized with the du command for various functions:

Options Purposes
h To show the devices
a To show the disk house used by the entire information to be had of the desired listing
s To show the whole of each and every listing
c It combines the entire sizes of the information and shows them one after the other within the phase of the whole
–apparent-size It shows absolutely the length of the information within the listing
–max-depth It is used to specify the command to which folder pass inside the listing
–exclude It is used to exclude some specified information
–time It shows the time of the closing amendment made within the report

Before the use of those choices, we can show the disk length utilized by the directories within the Home listing the use of the command:

In the output, the sizes are displayed however with out the devices, it’s tough for us to acknowledge whether or not those are in GBs, MBs, or in KBs, to show the sizes with devices, we execute the above command the use of the “-h” choice:

The sizes used by the information within the listing are comprehensible because the devices are discussed with them; to show the entire information found in any listing or sub-directory, we will use the “-a” flag:

$ du -ha /house/hammad/Documents

In the above output, if we need to show the abstract of the dimensions of “new_directory” most effective we will exchange the “-s” flag with the “-a” flag within the choices:

$ du -hs /house/hammad/Documents/new_directory

To show the dimensions of all information of the listing of Documents, and show their mixed end result below the identify of “Total” we use the “-c” flag:

$ du -hc /house/hammad/Documents

If we wish to show the plain length of the information to be had within the listing, we can use the choice of the “–apparent-size”:

$ du –apparent-size /house/hammad/Documents

Similarly, we will prohibit the terminal to visit the desired subfolders through the use of the choice of “–max-depth”, for instance, we specify “1” to visit the one first subfolders:

$ du –max-depth=1 /house/hammad

We can see from the output, the dimensions has been calculated and displayed just for the primary folder, now if we need to calculate and show as much as the primary two folders, run the command:

$ du –max-depth=2 /house/hammad

We can exclude information through the use of the choice of “–exclude”. For instance, we will exclude the entire hidden information from the house listing, through the use of the “./.” for hidden information:

The closing choice we’re discussing on this write-up is the time choice which is used to show the adjustments made within the closing report:

Conclusion

The du command may be very useful in managing the disk house because it tells how a lot house has been occupied through the information and applications, so we will calculate how a lot house is left unfastened within the disk for brand spanking new information and applications. In this write-up, we have now mentioned the alternative ways of the use of the du command with its quite a lot of choices.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More