Check Available Space on Ubuntu

Recently I got into a situation where I ran out of free space on my Ubuntu instance. The first thing you need to do is to check how much available space you have. The command below will give you the general idea.

df -h

To list the files/directories that take up most of the space use the following. You can make your system to show you more files by changing “-n 10” to “-n 20” etc.

sudo du -a / | sort -n -r | head -n 10
 
47286901        /
42315676        /var
41550196        /var/log
41534640        /var/log/jenkins
28101588        /var/log/jenkins/jenkins.log
13432208        /var/log/jenkins/jenkins.log.1
2978220 /home
2978216 /home/deploy
1589784 /home/deploy/www
1499948 /usr

Another command that will give you a good idea about the space allocated is:

sudo du -cha --max-depth=1 /var | grep -E "M|G"

You can decide how deep to go by changing “–max-depth” value

In order to get a better visual representation and more user friendly interface, you can install ncdu – an Ubuntu disk usage viewer package

sudo apt-get install ncdu

After you delete the files that take up all that space (in my situations those files were Jenkins log files), do not forget to reboot your Ubuntu instance.
For more information on how to check available space from command line, please read this article:
https://www.techrepublic.com/article/how-to-check-drive-space-on-linux-from-the-command-line/