Skip to main content

QUICK GUIDE: Clearing Disk Space

====================================================================================

Identifying where disk space is being used

NCDU

NCDU is a command line tool that can be used to review disk usage across a filesystem.

ncdu /

Note: You can specify a directory other than /. ie if you wanted to review the contents of /var, you would format the command as follows:

ncdu /var
Find

We can also use the find command to locate files over a specified size.

find / -type f -size +300M > filelist.txt  

The above command would search / (and all subdirectories) for any files over 300M in size. There are various options available for size specification: 

  • G-> for gibibytes  

  • M-> for megabytes  

  • K-> for kibibytes  

  • b-> for bytes  

------------------------------------------------------------------------------------------------------------------------------------------  

Quick wins

/var/log/journal - this can be vacuumed to reduce the size:  

journalctl --vacuum-size=500M 
View largest directories in /
du -h --max-depth=1 / 2> /dev/null

------------------------------------------------------------------------------------------------------------------------------------------  

Disk Reserve

Most linux filesystems (depending on FS type) will have a segment reserved for special processes. The default percentage is 5.

We can use the tune2fs command for ext2/ext3/ext4 filesystems.

Check disk reserve:

tune2fs -l /dev/partition

Changing disk reserve:

tune2fs -m2 /dev/partition

------------------------------------------------------------------------------------------------------------------------------------------  

Inodes

Check for inode usage:

du --inodes -d 1 / 2>/dev/null