“du” stands for disk usage, and as the name implies, this command is very useful in getting disk-related information in Linux. This is a very flexible command that can be combined with different parameters to get the desired output.

In today’s tutorial, we will be guiding you on the method of sorting the output of the “du” command in descending order, i.e., largest to smallest in Linux.

Note: We have used a Linux Mint 20 machine to demonstrate this method. However, you can also perform the very same method on a Ubuntu 20.04 system or a Debian 10 system.

Method of Sorting the “du” Command Output by Size (Largest to Smallest)

For sorting the output of the “du” command by size (largest to smallest), i.e., in descending order, you will have to perform the following steps:

Step 1: Check the Help Manual of the “du” Command (Optional)

Before using any command in Linux, it is always good to check its help manual so that you may get good knowledge about its correct usage. For checking the help manual of the “du” command, you will have to execute the command shown below in your terminal:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/sort-du-command-by-size-01.png" data-lazy- height="29" src="data:image/svg xml,” width=”400″>

The help manual of the “du” command in a Linux Mint 20 system is shown in the following image:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/sort-du-command-by-size-02.png" data-lazy- height="512" src="data:image/svg xml,” width=”806″>

Step 2: Sort the Output of the “du” Command by Size (Largest to Smallest)

For sorting the output of the “du” command by size (largest to smallest) in Linux Mint 20, you will have to execute the command shown below in your terminal:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/sort-du-command-by-size-03.png" data-lazy- height="29" src="data:image/svg xml,” width=”464″>

By piping the output of the “du” command to the “sort” command and combining it with the “-n” and “-r” flags, you will be able to get the output in descending order, i.e., largest to smallest, as shown in the following image:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/sort-du-command-by-size-04.png" data-lazy- height="512" src="data:image/svg xml,” width=”745″>

Conclusion

By executing a single command that has been shared with you in this article, you will be able to sort the output of the “du” command by size (largest to smallest) very conveniently. Also, if you want the output of this command to be displayed in any other form, then you can try to explore its help manual for figuring out the right way to do so.

About the author

<img alt="Karim Buzdar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/karim-150×150.png" height="112" src="data:image/svg xml,” width=”112″>

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.