Wednesday, April 12, 2023
HomeNetworkingUtilizing ncdu to view your disk utilization whereas greedy these TiB, GiB,...

Utilizing ncdu to view your disk utilization whereas greedy these TiB, GiB, MiB and KiB file sizes


The ncdu command supplies a quick and really easy-to-use solution to see how you might be utilizing disk house in your Linux system. It permits you to navigate via your directories and recordsdata and evaluate what file content material is utilizing up probably the most disk house. In the event you’ve by no means used this command, you’ll doubtless have to put in it earlier than you possibly can reap the benefits of the insights it may present with a command like considered one of these:

$ sudo dnf set up ncdu
$ sudo apt set up ncdu

The identify “ncdu” stands for “NCurses disk utilization. .It makes use of an ncurses interface to supply the disk utilization info. “Curses”, as you most likely know, has no connection to foul language. As a substitute, when associated to Linux, “curses” is a time period associated to “cursor” – that little marker in your display that signifies the place you might be at present working. Ncurses is a terminal management library that lends itself to establishing textual content person interfaces.

Utilizing ncdu

To begin ncdu on the command line, merely kind “ncdu”. You’ll see a show that appears one thing like what’s proven under as soon as it has run a sequence of instructions to shortly collect the wanted file measurement information to generate the itemizing for you.

ncdu 1.17 ~ Use the arrow keys to navigate, press ? for assist
--- /dwelling/shs ----------------------------------------------------------------
   61.3 GiB [###########] /fampix
    5.1 GiB [           ] /pix
    1.5 GiB [           ] /.cache
  483.1 MiB [           ] /.native
  311.3 MiB [           ] /movies
  152.9 MiB [           ] /nextjs
   85.3 MiB [           ] /.mozilla
   78.2 MiB [           ] /homebrew
   59.4 MiB [           ] /Desktop

You possibly can navigate up and down the itemizing utilizing your down arrow and up arrow keys. In the event you press the enter key while you’re sitting on a line that represents a listing, you’ll transfer into that listing. Later, you possibly can press the left-pointing arrow key to maneuver again into the previous listing.

The ncdu command is one that can record the recordsdata and directories in your present file system location in measurement order. Nonetheless, it shows file sizes based mostly on a binary-based numbering system with file sizes like 5.1 GiB, 10.2 MiB and 23.9 KiB. The second part under compares these measurements to numbers based mostly on powers of 10 (our regular numbering system). These tebibyte (TiB), gibibyte (GiB), mebibyte (MiB) and kibibyte (KiB) numbers are all based mostly on powers of two. They’re shut in measurement to terabytes, gigabytes, megabytes and kilobytes, however are all considerably bigger. One kibibyte equals 1,024 bytes – bigger than kilobyte at 1,000 bytes. One gibibyte equals 1,073,741,824 bytes – fairly a bit bigger than a gigabyte at 1,000,000,000.

Different choices

The ncdu software supplies various extra choices. For instance, you possibly can change to itemizing recordsdata by identify by urgent “n”, and you may delete a file by urgent “d” and responding to the request for affirmation. You possibly can pull up extra info on a file or listing by transferring to its identify within the itemizing and urgent “i”. You possibly can toggle between viewing file sizes and disk utilization by urgent “a”. The show will start with the doubtless bigger disk utilization sizes. The sizes proven will usually differ as a result of disk utilization counts the total measurement of the final block even when the file is not totally utilizing it.

In the event you begin ncdu with the -e possibility, you possibly can kind “m” to toggle between the traditional view and including file replace dates and instances to the show.

Verify the command’s man web page for extra choices.

Understanding the file sizes

So, what’s the distinction between the 2 units of file sizes – these you see when utilizing ls -l on the command line and people you see when utilizing ncdu? The numbers utilized by ncdu are all based mostly on powers of two (really all powers of 1024). The place one GB is outlined as 1000³ (1,000 x 1,000 x 1,000), one GiB is 1024³ (1,024 x 1,024 x 1,024).

The record under reveals how all of those numbers examine.

  • 1 TB is 10004 the place 1 TiB equals 10244 or (1,000,000,000,000 vs 1,099,511,627,776)
  • 1 GB is 10003 the place GiB is 10243 (1,000,000,000 vs 1,073,741,824)
  • 1 MB is 10002 the place MiB is 10242 (1,000,000 vs 1,048,576)
  • 1 KB is 1000 the place KiB is 1024 (1,000 vs 1,024)

This is a calculation to make the scale variations clear. It reveals that one GB is just 93% or so of 1 GiB.

$ echo "scale=2; 1000000000 / 1073741824" | bc
.93

Within the calculation above, we divide one GB (1,000,000,000 bytes) by one GiB  (1,073,741,824 bytes). That reveals that one GB equals 0.93 GiB. Nonetheless, it limits the variety of decimal locations to 2 with the “scale” parameter. Including some extra decimal locations reveals the distinction is definitely considerably bigger:

$ echo "scale=5; 1000000000 / 1073741824" | bc
.93132

Doing the mathematics

The for command under runs the calculations for one KiB, one MiB, one GiB and one TiB.

$ for n in 1 2 3 4
> do
>   echo "1024 ^ $n" | bc
> finished
1024
1048576
1073741824
1099511627776

To generate the record of values with commas in order that they’re simpler to learn, use a script like this one which makes use of the printf command:

#!/bin/bash

# generate record of powers of 1024
for num in 1 2 3 4
do
  echo "1024 ^ $num" | bc >> nums$$
finished

# add commas to the outcomes
n=0	
for num in `cat nums$$`
do
  ((n++))
  echo -n "1024^$n = "
  printf "%'d" $num
  echo
finished

Working the script will generate output like this:

$ powers_of_1024
1024^1 = 1,024
1024^2 = 1,048,576
1024^3 = 1,073,741,824
1024^4 = 1,099,511,627,776

Wrap-up

The ncdu command supplies a handy solution to evaluate your recordsdata and disk utilization. Understanding the variations between a Mebibyte (MiB) and a Megabyte (MB) together with the opposite file sizes based mostly on powers of 1024 shouldn’t be an issue so long as you grasp the importance of those numbers when your recordsdata with the ncdu command.

Copyright © 2023 IDG Communications, Inc.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments