Knowing how much disk storage you have available on your Linux system is handy. Mostly because you need to know if and when you are going to run out with enough advance notice to do something about it.
Of course there are many graphical utilities for monitoring your disk space but we are all about the shell here at On The Line, so let's look at some ways to quickly assess your storage situation. We will start with the most generic but also most common and finish with the bells and whistles solution.
df is a very common unix command also found in GNU/Linux. It stands for 'disk free' and has been around since about 1987. I like to remember it as 'display filesystem' as it really shows you available disk space in file systems.
On it's own df is a bit overwhelming and ugly on the eyes.
A swift way to see just the file system for your current directory is to use:
df .
And now add the -h switch to make it 'human readable'.
df . -h
Nice! Now we can clearly see the current directory is mounted on / and this whole file system has 55GB available, about 46%.
du or 'disk usage' came from AT&T UNIX. du can differ from df as it shows the space allocated to files. But it's a handy way to quickly get the total space used by a directory and it's subdirectories.
By default you will get a list of every file in the current directory so let's just get the sum with the -s switch and make it human readable with -h.
du -sh directoryname
We can easily see that the /mnt/data1 directory is using about 7.3TB of space. This command can be helpful when you are trying to track down what is eating up your disk space.
duf or disk usage free is a more recent utility and less likely to be installed by defualt on your Linux distro. Fortunately it has been pre-packaged for most Arch-based, DEB-based and RPM-based systems and should be easy to install from your repo.
On it's own duf will show you a lovely formatted summary of all the block devices on your system.
If like me, you are not interested in the loop devices used by snap and the temp file systems on special devices you can filter out the junk with:
duf -only local
So there you have my top three go to storage commands, df, du and duf. I hope these 3 commands help you keep your disk space under control!
Happy storaging!