Question – How do I sort du -h command output by there sizes?
In the GNU Coreutils >= 7.5 package, sort command provides -h parameter allows to compare human-readable numbers (e.g., 10K 15M 1G etc). This helps up to compare the results of `du -h` and short them.
du -h * | sort -h
The above will show the results in the ascending order by size. You can reverse this using -r to show results in descending order.
du -h * | sort -rh 15M btmp.1 7.2M apache2 2.2M auth.log.1 1.9M btmp 1.5M auth.log 1.3M redis 656K letsencrypt 468K auth.log.4.gz 264K auth.log.2.gz 260K cloud-init.log 240K auth.log.3.gz 168K mail.log.1