Check and Clear Disk Space on Ubuntu

February 3, 2019

Check disk space by drive

df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G  4.0K  2.0G   1% /dev
tmpfs           396M  1.7M  394M   1% /run
/dev/sda5        14G   13G  601M  96% /
/dev/sdb1       5.8G  5.1G  462M  92% /media/disk02

Check disk space usage per directory

The best tool to check for disk space usage is ncdu.

sudo apt-get install ncdu
sudo ncdu

NOTE: run with sudo to make sure you can access all the files.

Sample output.

    1.1 GiB [##########] /vue                                                   
    1.0 GiB [######### ] /google-cloud-sdk
  429.6 MiB [###       ] /python
  283.7 MiB [##        ] /node
  220.8 MiB [##        ] /google_appengine
  203.9 MiB [#         ] /php
  182.0 MiB [#         ] /hugo
  138.4 MiB [#         ] /webpack
  135.6 MiB [#         ] /cache
   81.0 MiB [          ] /data

Remove old linux kernel images

Each version of linux kernel is about 200-300MB, refer to How To Remove Old Linux Kernel Images.

Inode Problem

It’s possible to bump into Error: no space left on device while there are still plenty of space. One possibility is you run out of inode. Refer to check free inode.

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.