Tag Archives: unix

Using ncdu to examine disk usage

du has been my go-to tool for checking disk usage and it’s wonderfully simple. But I’ve been using ncdu for a few weeks now.

ncdu is short for NCurses Disk Usage. In addition to being able to visualize disk usage by directory, it lets you sort on different parameters, delete files, show hidden files, and a few more stuff that you’ll miss if you go back to plain du. Most importantly it acts as a file manager, so you can simply enter the directories to see a more fine-grained breakdown of file sizes. As an added bonus it has Vim keybindings along with normal arrow key movements.

ncdu - ncurses disk usage

Screenshot of ncdu + help popup

Installation:

brew install ncdu # macOS
sudo apt-get install ncdu # Ubuntu/debian

Elevating privileges temporarily with setuid permission (Unix)

You may have noticed that apart from the read (r), write (w) and executable (x) permissions in Unix, there’s an ‘s’ permission as well. This is called the setuid permission. If you have access to an setuid-enabled file, then you can execute that file with admin privileges even though you’re an unprivileged user. So, s means that the file is both executable and has root privileges.

Unix setuid permission

It’s possible to add enable setuid permission just as you do with any other permission.

chmod u+s filename

Be wary though, mistakenly assigned setuid can cause havoc if some stupid user takes advantage of the root privileges.