I usually don’t do very complicated tasks via SSH, but part of my job, on remote servers, is to keep things neat, tidy and organized. Part of this task is to fetch directories and files size to see what’s going on, who/what is using what and how much disk space, etc.
If you are using a command line terminal in a Unix based Operating System like Linux, MacOS etc., and you are not really into memorizing every possible command available, you probably rely on our dear old friend Google to find the commands you need quickly.
Unfortunately, there is not an easy-to-remember command to get directories and files sizes in a readable format. If you are like me, you do not want to remember anything more than what is strictly essential.
I use the following terminal command very often: du -skh * | sort -h
. Quite neat right? This little gem sorts all your files AND folders by size with a human-readable format (GB, MBs etc.).
Since I’m lazy, and I don’t want to remember this, even if it’s so simple, I added this command as an alias inside my .bash_profile.
If you are not familiar with it, just navigate to your home folder and locate the hidden file .bash_profile or .bashrc, and place the following snippet in it: alias dul="du -skh * | sort -h"
Restart the terminal and now, every time you write dul
, the command will be executed; of course, you can change dul to whatever word is easy for you to remember.
This simple and basic trick saved me a lot of time, I hope you can find it useful too.