How to sort folders by size in Linux?

To sort by folder size, you can use the following command:

du -sh * | sort -rh

The purpose of this command is to first use the `du` command to calculate the size of each folder, and then use the `sort` command to sort the folders in reverse order by size. The `-h` parameter displays the folder sizes in a human-readable format, the `-r` parameter indicates reverse sorting, and the `-h` parameter specifies the sorting by folder size.

After executing the above command, the folder will be displayed in descending order by size.

bannerAds