Sort “du” Command by Size- Output Largest to Smallest
“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:
The help manual of the “du” command in a Linux Mint 20 system is shown in the following image:
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:
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:
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.