Debian: how to decently sort du -sh *

dufHow to sort du by size.

The utility du works very well and in a linux mentality, basically it is perfect because it does just one thing but it does that at best.

So nothing to complain for the du utility, but you can always improve your tools.

I’m not the author of this script, but i publish it here for me as well, because I’m pretty sure it will be very useful in the next future.

You just save it as “duf” or another name you like, and then move it into /bin, you can call it from everywhere in your system.
Remember to make it executable by typing “chmod +x /bin/duf”


# With this file you are able to make du -csh * 
# With a decent sorting

du -sk * | sort -n |  
perl -ne '            
 for (qw(K M G)) {  
  if($s<1024) {        
   print "$_\t$f";     

And then when you try to use it:

root@erver:~# cd /var/log/mysql
root@server:/var/log/mysql# duf
4.0K	mysql-bin.000063
4.0K	mysql-bin.index
184.0K	mysql-bin.000066
2.0M	mysql-bin.000065
5.8M	mysql-bin.000064
5.8M	mysql-bin.000060
35.3M	mysql-bin.000062
77.9M	mysql-bin.000061


(Visited 1,117 times, 1 visits today)

Author: Giuseppe Urso

Giuseppe lives in Haarlem now with his shiny dog, Filippa In 1982 received his first home computer, a Commodore 64, followed by Datasette and a 1541 Floppy Disk Drive. In 1999 he installed his first Linux distro (LRH6). In 2006 he switched to Debian as favourite OS. Giuseppe Urso actively sustains the Free Software Fundation and his founder Richard Mattew Stallman, he speaks to people trying to convince them to join the fight now, and about how important is to use Free Software only. He has a job as Infra Specialist at Hippo Enterprise Java Cms an Open Source Enterprise class Content Management System, one of the coolest company ever, in Amsterdam. He's always ready to install Debian on other people computers for free.

One thought on “Debian: how to decently sort du -sh *”

Leave a Reply

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


This site uses Akismet to reduce spam. Learn how your comment data is processed.