How to sort du -h command based on file size

In the GNU Coreutils package> = 7.5, command sort Provides the -h parameter which allows easy reading of numbers of this size (eg 10K 15M 1G etc.). Helps compare and shorten “du -h” results.

du -h * | sort -h

The above results will appear in descending order. You can invert this by using -r to display the 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

Source link

Originally posted 2020-11-19 13:31:01.

See also  Various ways to download ISO files on Linux systems

About wahyuway

Check Also

How To Deploy Droplet on DigitalOcean With Terraform

Hello good people. In today’s blog post we will be showing you how to create …

Leave a Reply