How To Check Directory Size On Linux

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 ncduncdu

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

du -sh * is the another command to show the size of files and directoies in the current directory.

sudo du -sh *# Output33M   brunch136M  cache4.8M  chrome504M  data2.9M  github68M   go17M   logs752K  nginx-1.4.6.tar.gz0     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

Run df -h to check to show the status of each filesystem and file out which mounted directory is low on disk space.

df -h# OutputFilesystem      Size  Used Avail Use% Mounted onudev            2.0G  4.0K  2.0G   1% /devtmpfs           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 / and /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.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.