1. Home
  2. Linux
  3. Disk space linux terminal

How to analyze disk space usage on Linux from the Terminal

Are you running out of space on your Linux server? Trying to figure out what is using up all of the space but can’t figure it out? Follow along with our guide as we go over how to analyze data usage on Linux through the terminal.

Note: although this guide focuses on the Linux server, these methods also work on any desktop or laptop running a Linux-based operating system. Feel free to follow along!

1. Analyze disk space on Linux – NCDU

The best way to find out your disk usage in the command-line on Linux is with the NCDU tool. It’s a Ncurses-based utility that scans outputs a graph (biggest to smallest) showing you how much space the data on your Linux filesystem is taking up.

Installing NCDU on Linux

The NCDU application is very lightweight and easy to get going. However, no modern Linux operating systems ship it by default, so we must demonstrate how to install it before we show you how to use it to analyze your Linux system’s filesystem usage.

To install NCDU on Linux, open up a terminal window or connect to your Linux server machine via SSH. From there, follow the command-line instructions outlined below that corresponds with the OS you currently use.


To install the NCDU application on Ubuntu, use the following Apt command.

sudo apt install ncdu


On Debian, you can get NCDU working with the following Apt-get command in a terminal.

sudo apt-get install ncdu

Arch Linux

Those on Arch Linux can get NCDU with the Pacman package manager.

sudo pacman -S ncdu


Are you on Fedora Linux? If so, you’ll be able to get NCDU up and running with the dnf command below.

sudo dnf install ncdu


To get NCDU working on OpenSUSE Linux, run the Zypper command below.

zypper addrepo https://download.opensuse.org/repositories/utilities/openSUSE_Leap_15.1/utilities.repo
zypper refresh
zypper install ncdu

Generic Linux

If you’re using a Linux operating system that is not covered on this list, you’ll still be able to install the software via the source code.

To get the source code for NCDU, you need to head over to the developer’s website.

Using NCDU to analyze filesystem usage in the command-line

To use NCDU to analyze filesystem usage, start by opening up a terminal. Then, run the ncdu command alongside the directory you want to analyze. For example, to analyze the /var directory, you’d run:

ncdu /var

Or, analyze the entire system by pointing NCDU at the / directory with:

ncdu /

Once you’ve run the ncdu command against the directory you want to analyze, you will see a window appear. In this window, you will see the NCDU app scan the folder. Sit back and be patient while it scans. It may take a long time, especially if you have a lot of files.

When NCDU is done scanning, you will be presented with an interactive graph. This graph will rank directories on the Linux system by size. The folder at the top is using the most data. The one at the bottom is using the least.

Using the UP/DOWN arrow keys, find the folder you want to look at. Then, press Enter to access it. To exit the NCDU disk usage analyzer, press q on the keyboard.

2. Analyze disk space on Linux  – DF

Another way to analyze file-system usage in the Linux terminal is with the DF tool. To use the DF tool, run df, and then the part of the filesystem you want to analyze. For example, to check the status of the ~/ directory run df ~/.

df ~/

Running the DF tool against a directory will generate a total readout of that directory, how much space is used, and how much is left. However, the readout is not in an easy to read format. To tell the DF tool to show a summary of how much data a directory is using on the system in an easy to read format, use the -h switch. The -h switch will print out the readout in gigabytes and megabytes.

df -h ~/

To analyze any directory, run the df command against any folder. However, understand that the df command doesn’t offer a detailed readout of the directory. Instead, it only offers up a quick summary.

3. Analyze disk space on Linux – DU

If the NCDU and DF tools don’t do it, another great way to analyze filesystem usage on Linux is the DU tool. DU can scan any directory and show a readout of how big each file is in that particular folder. It’s handy for finding what files are taking up the most space.

To find out what files are taking up the most space in any given directory on your Linux system, run du /directory. For example, to find out what are the largest files in the /var directory, run:

du -ch /var

After running the du command, it will show a list of every file, and how large it is, as well the total size of all files added together at the very bottom of the list. To make it easier to read, send the output of the command to a text file.

du -ch /my-favorite-directory > du-readout.txt

You can view the text file with the cat tool. Alternatively, open it up with your favorite text editor.

cat du-readout.txt

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.