Linux Tips for Windows Devs - Used Disk Space

Linux Tips for Windows Devs - Used Disk Space The project I am working on right now relies on several linux VMs hosted on Linode which were severely underutilized. In order to fall back to smaller VMs, the disks had to be resized in order to fit the requirements of the smaller VM package.

To do that, of course, I had to check how much of disk space was being used and if some space could be reclaimed. This task would certaily not classify as rocket science but since I haven’t touched Linux or Unix for about 15 years, some research needed to be done.

The first part was to figure out how much space used or free. The df -h command does exactly that:

df -h

Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G     0  2.0G   0% /dev
tmpfs           396M  7.0M  389M   2% /run
/dev/sda         73G   63G  5.7G  92% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs           396M     0  396M   0% /run/user/0

Now I knew that of the total 73G, 92% was being used. The next part was to trace where all of those 63G on / are. To do that I followed the top down approach where I first checked the size of each folder in / and then drilled in as needed. Disk usage command to the rescue: du -sh — /*

du -sh -- /*

11M     /bin
34M     /boot
0       /dev
5.7M    /etc
4.0K    /home
0       /initrd.img
0       /initrd.img.old
232M    /lib
4.0K    /lib64
16K     /lost+found
8.0K    /media
...

Using df -h and then du -sh — /* I was able to quickly pinpoint where all of the used space was allocated and reclaim enough space to shrink the VM instances. Let me know if there is a better way to do this. I am a Windows guy, what do I know.

References

Disk Usage command - https://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/
Df command - https://linuxize.com/post/how-to-check-disk-space-in-linux-using-the-df-command/

Published 11 May 2019

Building software and sharing knowledge.
Milan Nankov on Twitter