ncdu (NCurses Disk Usage)
I discovered an utility a few weeks ago and I thought it would be worth sharing. This utility is especially useful when you are looking for files that take a lot of disk space on your system. As an example, I received a Nagios notification saying that /var had less than 15% free. I logged on the system to see what is taking too much space. In the past, I would have use the du command (du -hs /var/*, then du -hs /var/log/* and so on), but I used ncdu. I cd'd into /var, then ran 'ncdu'.
Here are screen shots of an example (different of what happened yesterday):
This is what we see when we start ncdu in /var:
We can use the arrows up and down to select a folder and use the left and right arrows to go up/down the tree. In this case, I simply used the right-hand side arrow a few times until I got to the folder that contains the most data:
Here are screen shots of an example (different of what happened yesterday):
This is what we see when we start ncdu in /var:
We can use the arrows up and down to select a folder and use the left and right arrows to go up/down the tree. In this case, I simply used the right-hand side arrow a few times until I got to the folder that contains the most data:
That's already great, but that's before digging into the help (using ?). The options are (version 1.13):
- Sorting (typing again changes the sort order):
- By name (n)
- By size (s)
- By # of items (C)
- Deleting the selected file or directory (d) - Be careful!!!
- Toggle files before files when sorting (t)
- Show % and/or graph (g)
- Toggle between apparent size and disk usage (a) - useful for sparse files or files that are compressed by the file system (ZFS for example)
- Toggle display of child item counts (c)
- Show/hide hidden or excluded files (e)
- Show information about selected item (i)
- Recalculate the current directory (r)
- Spawn shell in current directory (b)
- Quit (q)
Interesting options found in the man page:
-x: do not cross the file system boundaries. For example, if you have /var on a different disk or partition, and you only want to run ncdu only on / (excluding /var), you can use this option. I tested it and it doesn't seem to be working.
-e: extended mode: Will use more RAM but reads ownership, permissions, and last modification time for each file
ncdu is available in EPEL repo for RHEL-based distribution, and is most likely available in most Ubuntu versions. ncdu 1.11 is available on Ubuntu 16.04 LTS.
As usual, any feedback is welcome,
Have fun!
Comments