Find out which directory occupy the most disk space, usually for cleanup purpose.
My linux machine is running out of disk space, and I want to check which directory is the culprit hogging the precious space.
Check directory size
LATEST: The best command is
ncdu. I can easily identify the biggest directory and drill in to investigate further.
sudo apt-get install ncdu ncdu
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
du -sh * is the another command to show the size of files and directoies in the current directory.
sudo du -sh * # Output 33M brunch 136M cache 4.8M chrome 504M data 2.9M github 68M go 17M logs 752K nginx-1.4.6.tar.gz 0 share.txt
du by default doesn’t show hidden files and directory. So you need the following command
du -sch .[!.]* * |sort -h
Check disk usage on Filesystem
df -h to check to show the status of each filesystem and file out which mounted directory is low on disk space.
df -h # Output 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
I only have 2 main root directory, which is
/media/disk02 and their usage is above 90%.
Old Linux Kernels in Ubuntu
Old linux kernel on Ubuntu could take up quite some disk space depending how many version are stored (each version is about 200-300MB). Don’t delete these files directly, refer to remove old linux kernel images.