// you’re reading...

How in the Tech

How to sort folders by size in Linux/Unix

In my day to day profession I am often tasked to find out where all the storage space has gone on a system. For example, I need to figure out which user(s) are using more than their fair share on the mail server. Knowing that the mail folder resides under /home, I need a quick and easy way to list all of its subfolders sorted by size.

Thankfully, Linux makes this a rather trivial process – assuming you know the right command and appropriate flags:

du –max-depth=1 /home/ | sort -n -r

In Unix, it is equally similar:

du -sk /home/* | sort -n -r

Either command, when executed, will dump something similar to the following:

1234881 /home/
23441 /home/adam
19244 /home/support
13960 /home/admin

..on your screen. Now, you can get to cracking those knuckles on your top spacepigs!

Related Posts with Thumbnails

Discussion

No comments for “How to sort folders by size in Linux/Unix”

Post a comment