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  How to install and configure Docker on CentOS 7

About wahyuway

Check Also

How to install and configure Anaconda on CentOS 7

How to install and configure Anaconda on CentOS 7

Anaconda is the most popular machine learning and data science tool used in large scale …

Leave a Reply