Is Your Linux Disk Full? Quickly Find and Free Up Space!

If you diligently keep tabs on your disk space utilization, or have a monitoring platform like LogicMonitor that bugs you about it (shameless plug), you might appreciate this quick guide on freeing up disk space in Linux. We’ll look at some commands and techniques you can use to quickly find large files to remove.

Running out of disk space on your Linux system can bring things to a halt. Whether you’re a diligent system administrator or just a Linux user facing low disk warnings, effectively managing disk usage is crucial. This guide will show you powerful command-line tools and techniques to quickly pinpoint and remove large, unnecessary files, helping you reclaim valuable disk space.

We’ll dive into two essential utilities: ncdu for interactive, visual analysis, and du for scriptable, detailed reporting. Let’s get your disk space back under control!

Visual Disk Analysis with ncdu (NCurses Disk Usage)

If you’ve never used ncdu (NCurses Disk Usage) before, well, you should install it and use it. It’s an incredibly intuitive and powerful tool for interactively exploring your disk usage.

How to Install ncdu

If you’re on Ubuntu/Debian you should be able to pull it in with a quick sudo apt-get install ncdu. Most Debian/Ubuntu-based systems can install ncdu with a simple command.

If your package manager doesn’t have it, you can get it here but consider switching distros unless you’re some kind of an expert. Actually, I don’t really care about what distro you run, but it just seems like something that should be in the repos. Anyways, enough whining, let’s delete some files.

Getting Started with ncdu

ncdu is pretty damn simple. To start ncdu, simply pass it a directory path, or just let it use the current directory:

$ ncdu ./test

It will crank through recursively and calculate the size of everything. This could take a bit of time on larger/slower drives. It was able to jam through ~850 GiB on my SSD in under a minute, so don’t fret. It will be worth the wait, and it seems (very scientific) to be much faster than something like du, but it could be just that it shows progress better.

Here’s a glimpse of what you’ll see:

ncdu 1.12 ~ Use the arrow keys to navigate, press ?
for help
--- /home/michael/test ------------------------------------------------------------------------------------
  264.0 KiB [##########] /bin
   72.0 KiB [##        ]  feed.xml
e   4.0 KiB [          ] /test
    0.0   B [          ]  3
    0.0   B [
  ]  2
    0.0   B [          ]  1

Clearly we want to start in /bin if our goal is to make space. The directory is only a few hundred KiB, but it’s clearly the largest, and that’s the point of ncdu. We can drill into /cgibin and see its contents sorted the same way.

The interface is designed for easy navigation using arrow keys. You’ll quickly identify the largest directories or files. For instance, in the example above, /bin is clearly the largest item.

  • Enter a directory: Use the Right arrow or l key.
  • Go up one directory: Use the Left arrow or h key.
  • Delete a selected file/directory: If we want to (for example), delete feed.xml we can hit the d key while it’s selected. You’ll be prompted for confirmation.
  • Get more information: You can also get more information about the file (like the actual vs apparent disk usage) by typing i.
  • Toggle directory content counts: You can toggle directory content counts with c.
  • Read-only mode: If you’re a little trigger shy and want to just browse without actually deleting anything, you can pass -r when you first start ncdu to put it into read-only mode:

      $ ncdu -r ./test
    

Anyways, from there you just dig through the largest folders and find the stuff you’re willing to part with. You’ll have free space in no time. There are more helpful keyboard shortcuts later in this article. You can see them all by typing ?.

ncdu Keyboard Shortcuts for Power Users

ncdu offers intuitive navigation and sorting options:

Navigation:

  • Up, k - Move cursor up
  • Down, j - Move cursor down
  • Left, h - Go up one directory
  • Right, l - Enter directory

Sorting:

  • s - Sort by size
  • n - Sort by name
  • C - Sort by items (e.g., directory vs. file)

You can press these keys repeatedly to toggle ascending or descending sort order.

Anyways, ncdu is a great tool for finding large files and cleaning up disk space on Linux. However, if you’re looking for something more geared towards scripting, and less interactive, try out du.

Advanced Disk Usage Analysis with du

du is the disk usage tool that ncdu takes after. It will crank through a folder and spit out file and folder sizes. It’s perfect for when you need more control, especially for scripting or generating reports.

Here it is run against the same directory from the ncdu examples above. We’ll pass -h to get human readable sizes:

$ du -h ./test
264K	./test/bin
4.0K	./test/test
344K	./test

As you can see, it’s almost identical to ncdu’s output (as you might expect). Of course, we’re not getting sizes for individual files:

$ du -ah ./test
4.0K	./test/bin/ticker.sh
4.0K	./test/bin/ticker.cgi
4.0K	./test/bin/hello.py
248K	./test/bin/index.cgi
264K	./test/bin
72K	./test/feed.xml
0	./test/1
4.0K	./test/test
0	./test/2
0	./test/3
344K	./test

Whoa! That’s a lot of stuff. We just want this directory though, not the whole recursive list of every file (useful as that may be):

$ du -ahd1 ./test
264K	./test/bin
72K	./test/feed.xml
0	./test/1
4.0K	./test/test
0	./test/2
0	./test/3
344K	./test

Now that’s more like it! We added -a to show all files (not just directories), and we passed -d1 to tell du to only go down a depth of 1 folder.

Sorting du Output for Easy Analysis

However, notice anything? Yeah, that sorting, it sucks! I want to see the big stuff at the top so I can delete it. I don’t want to sort through this visually. No problem, we can use sort. I’ve gotten some bewildered reactions even from salty old unix nerds with this little trick:

$ du -ahd1 ./test | sort -hr
344K	./test
264K	./test/bin
72K	./test/feed.xml
4.0K	./test/test
0	./test/3
0	./test/2
0	./test/1

Awesome! It even sorted the human readable output, what is this wizardry? Well, it’s sort -h, which stands for “Human readable”. The -r is to reverse the sort to match ncdu, but you can drop it to have the big stuff at the bottom. You can pipe to head or tail to narrow things down.

There’s still something goofy though, it’s showing the size of the whole ./test directory, which we don’t really care about, and which isn’t shown in ncdu. No worries, simply change the way we pass args to du and we’re good to go:

$ du -h ./test/* | sort -hr
264K	./test/bin
72K	./test/feed.xml
4.0K	./test/test
0	./test/3
0	./test/2
0	./test/1

So, we ditched -a and -d1 because it will interfere with our glob and give us the whole recursive directory. Basically we’re passing “every directory in ./test” instead of “./test and the directories within it”.

This command effectively lists the sizes of direct children of ./test and sorts them by size.

Conclusion: ncdu vs. du - Which Tool is Right for You?

As you can see, both ncdu and du have their merits when it comes to finding large files on Linux to free up space.

  • ncdu: Ideal for casual, interactive use and visual exploration.
  • du: Perfect for hardcore scripting, automation, and detailed reporting. Use it with sort -h for human-readable, sorted output.

If you’re not sure, try both! You’ll certainly run across use cases for both in the future.

Happy deleting and enjoy your reclaimed disk space!

If you’ve created something cool or need a hand, feel free to drop me a line.