GNU/Linux Disk Space Analysis

Published by Krrish Ghimire on

When GNU/Linux disk space is full, there are few things to do to know what is taking up the space. After that you can decide what to keep, what to delete, or what to move to backup devices. First, check which device is taking up space by running this command df -h. Check the available space, used space, used percentage. Once you know which device is taking space, check the mount point of the device in the output of above mentioned command. Now, you know which directory to dig.

Next step is to dig deeper to the exact directory which is taking up space. Use this command: sudo du -xhd1 / 2>/dev/null | sort -h. du is the command to check disk usage. x tells it to skip files in other filesystems. h makes the output human readable. d1 shows just 1 depth of directory i.e. current directory and its immediate subdirectories. / is the root filesystem. Feel free to replace it with the directory you want to explore. 2>/dev/null discards all the errors. sort -h sorts the output by human readable sizes.

Basically, you will get list of sorted directories by used size. Use the same command by replacing the directory until you find the exact directory that needs to be checked. Then, it is upto you to what to do with the files that is taking up space. Delete it, backup it to another device or do anything you want.