Linux: What Is Using Up My Disk Space?
scottalanmiller last edited by scottalanmiller
If you are working on Linux and do a df -h you might find that you have a filesystem that is filling up. Great, let's clean it up. What what is consuming all of the space? In some cases you might already know (all those ISOs you've been downloading, perhaps?) But in some cases you might not know where all of that capacity has been hiding. Is there an easy way to track it down?
Yes there is. There are lots of ways to do it but as an old school UNIX system admin, this is what I like to do. It's slightly manual but is fast, easy and clear and walks you though the file system allowing you to really track what is going on.
cd / sudo du -smx * 2>/dev/null | sort -n
This will give you a top level view of your directories in that file system mounted on root. It will order them for you with the largest at the bottom. You don't care about the top, those will be tiny.
Pick the one at the very bottom, cd into it and run the du command again, exactly as before. This will drill down one level and show you the biggest directories within that level. You can keep doing this until you find your culprit files or directories.
You can, of course, look at the second biggest directories, third biggest, etc. in case you have storage that needs cleaned up all over the place. Generally a surprise filling of the disk will be in a single, obvious spot once you have drilled down.