ncdu is a great Linux command line to to analyze your disk space

One of the things I often run into quite often is freeing up disk space on my computer as well as cloud servers. Disk space is one the limited computing resources you have to use efficiently.

So I often have to audit the server usually using a combination of df -h which gives me a snapshot of disk usage across all partition. To drill down to specific files and folders, I use du -sh /folder/to/audit. So keep stepping into those folders with the largest disk space and see if I could delete or move some files or folders. It's a time-consuming and manual process.

Until I landed on ncdu, a cool ncurses-based front-end to du. What's ncurses?

ncurses (new curses) is a programming library providing an application programming interface (API) that allows the programmer to write text-based user interfaces in a terminal-independent manner. It is a toolkit for developing "GUI-like" application software that runs under a terminal emulator.~Wikipedia

So think of GUI application running in the terminal.
ncdu is really easy to use. You simply specify the directory you wish to analyze and in minutes,it will have crunched the data. It's super fast.

Installation

You have to download the software from https://dev.yorhel.nl and then compile from source. Since it runs on ncurses, make sure that you have the development libraries of ncurses installed first.

sudo aptitude install libncurses-dev  
wget https://dev.yorhel.nl/download/ncdu-1.12.tar.gz  
tar -xzvf ncdu-1.12.tar.gz  
cd ncdu-1.12  
./configure --prefix=/usr
make  
make install  

Usage

ncdu Simply run ncdu /dir/to/analyze and you are good. ncdu gives several options for manipulating files and folders and they include navigation, sorting, deleting folders. Some of these are as follows;

  • up, k Move cursor up
  • down, j Move cursor down
  • left, <, h Open parent directory
  • n Sort by name (ascending/descending)
  • s Sort by size (ascending/descending)
  • d Delete selected file or directory
  • g Show percentage and/or graph
  • i Show information about selected item
  • r Recalculate the current directory
  • q Quit ncdu

ncdu has saved me lots of time.

David Okwii

David Okwii is a Systems Engineer who currently works with Uganda's country code top-level domain registry.

Kampala Uganda http://www.davidokwii.com

Subscribe to oquidave@geek:~ #

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!