Daily Latest Tech Update

How to sort du -h command based on file size

  • Share

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

  • Share

Leave a Reply

Your email address will not be published. Required fields are marked *