7 Great Apps to View Disk Usage in Linux
BY CHRISTIAN CAWLEY
1. Native Command Line Tools
The first place to check is the command line. Several tools are available here, and are already bundled with Linux.
The first command you should try is df. This will report the amount of disk space in use. It can be used alone, to display a full total for all mounted file systems, or with a filename.
When used with a filename, df will output the remaining space on the specific partition where the file is stored.
The above command would show how much free space is available in the /etc/ directory. Meanwhile,
employs the -h switch, which means "human readable." This basically displays the file and folder sizes in a format you can read. Use this to interpret how much disk space is being used by a particular file or directory.
Meanwhile, du is also available. Differing slightly to df, du displays an estimate of disk space used by files. For example,
du -shc *.txt
displays the size of each TXT file in the current directory in human-readable format.
You can also use the ls (list) command to output a list of a directory's contents, and the file size.
This is done in any directory with
ls -l -h
2. Ncurses Disk Usage (Ncdu)
If you prefer to get the disk usage information you're looking for from a dedicated utility, then try ncdu. Potentially the simplest method in this list, ncdu scans your system as soon as the tool is launched. By default, the contents and usage of the Home directory are displayed, but this can be changed by specifying a different directory as a parameter.
You can install ncdu on Debian-based systems via the command line:
sudo apt install ncdu
Using ncdu is simple. In the command line, enter:
You'll need to wait for the results on larger HDDs. You can also scan the root filesystem using the -x command:
ncdu -x /
And there's the option to scan via SSH -- very useful for remote devices.
ssh -C user@system ncdu -o- / | ./ncdu -f-
Head to the ncdu website to find a full set of instructions.
Other features of ncdu include sorting by filename or size, deleting single files and directories, showing information about a file or folder, and toggling the visibility of hidden items.
With such good command line tools, you might think you've got everything you need. However, various visual tools will give you an enhanced view of your disk usage.
The first visual disk usage tool to look at is QDirStat, available across Linux desktop environments, as well as BSD.
Visual tools give a great insight into just what is going on with your PC's hard disk drive that a list of numbers simply cannot relate. One of the most popular options for this on Windows is WinDirStat, which is a clone of the KDirStat utility, upon which QDirStat is based.
With QDirStat, your HDD usage is represented by rectangles and squares, each of a different size. The bigger the square, the more HDD space is being used by that particular directory. Right-clicking on the rectangle in question will give you the option to visit the folder location.
This is a great way to find "secret" data that has been downloaded to your computer. Things like missing download locations and your internet cache can all be traced with these tools. And if you don't like the "blocky" view, usage data can also be viewed as a histogram.
You can get QDirStat via GitHub, but packages are available for openSUSE, SLE, and Ubuntu.
For the latter, first add the PPA (remember to remove it later):
sudo add-apt-repository ppa:nathan-renniewaldock/qdirstat sudo apt-get update
Once this is done, install with
sudo apt install qdirstat
You can then launch the software from the desktop, or from the terminal with the qdirstat command. Follow the prompt to select the directory to scan, then wait until the data is collated and presented.
A KDE version, K4DirStat, is also available.
4. Disk Usage Analyzer (Aka Baobab)
Formerly known as Baobab, Disk Usage Analyzer is, as you might have guessed, another visual tool. Rather than the block-based approach of QDirStat, this utility offers a radial treemap pie chart as a live illustration of disk usage. You'll find this in the right-hand pane; on the left, a list of the contents of the currently selected directory.
Everything is color-coded for easy analysis, but Disk Usage Analyzer doesn't really offer much more than that. For instance, there's no easy shortcut to the directories you're viewing, other than to open them manually in your default file manager.
Having said that, Disk Usage Analyzer is easy to use and ideal for quick checks of usage without too much involvement.
Another block-based graphical usage analyzer, xdiskusage has a quite basic UI and gathers information from the du command. This is run on your behalf, however, so the usage data is quickly compiled and presented.
Install in Debian-based systems with
sudo apt install xdiskusage
Run the xdiskusage command in the terminal to launch, then select the directory, or disk, to analyze.
The result is a tree-based presentation, with the parent directory block displayed left-most and the child directories and folders branching off to the right. Each block displays the directory name and disk usage.
You can navigate through this graphic representation of your directory structure using the mouse or arrow keys. Need to find out more about the directory block? Simply right-click for options, which include copying the path to the clipboard, and printing the display.
While it doesn't offer great graphics, xdiskusage is designed to be extremely lightweight. If you're in a situation where your disk has filled up without explanation and you're short of space, xdiskusage could be the solution you're looking for.
The downloadable executable for xdiskusage is 64-bit only, however the source can also be downloaded, and compiled on your system for installation.
Another disk usage tool employing the radial treemap approach is Duc. Featuring a collection of tools, you can install Duc on Debian-based distros with
sudo apt install duc
For other Linux families, you can download the source from the website and compile it.
Get started with Duc by indexing the /usr directory. This builds a database (more on that below), and can take a while on the first run:
duc index /usr
From here, you can use ls to list the contents of the directory and their impact on the HDD:
duc ls -Fg /usr/local
If you prefer to see this in Duc's visual analyzer meanwhile, use
duc gui /usr
There's also a console interface you can open with
duc ui /usr
Duc offers a far faster approach to disk usage analysis by maintaining a database of the disk's contents. This makes it ideal for larger systems; the Duc website boasts that it has been tested with "500 million files and several petabytes of storage."
Another option for a lightweight installation is JDiskReport, which is a Java-based disk analysis tool. Because it's Java, JDiskReport is cross-platform, which means you shouldn't run into any issues running it on older or unusual Linux distributions.
After analyzing your HDDs, JDiskReport presents the statistical data as charts and tables. This is where it comes into its own -- not only do you get the expected pie chart display, the utility also displays a top 50 list of the largest files. You'll also find a screen displaying the largest files by type.