- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Show Colorized Disk Space Usage in Linux?
Linux is a popular open-source operating system that has gained immense popularity over the years due to its flexibility and stability. As we use our computers for various tasks like downloading software, creating and storing files, and performing other tasks, it is crucial to keep an eye on disk space usage. If your disk space becomes full, it can lead to various performance issues and errors for your machine. Therefore, it is essential to monitor your disk space usage regularly.
In this tutorial, we are going to explore how to show colorized disk space usage in Linux. We will discuss two methods that can be used for displaying color-coded disk space usage. We’ll use a command-line tool called `ncdu` that provides an interactive interface for the disk usage analysis. So, let's get started and learn how to show colorized disk space usage in Linux.
How to Show Colourised Disk Space Usage in Linux?
For showing colorized disk space usage on our Linux machine, we're going to use a command-line tool called ncdu. Ncdu stands for "NCurses Disk Usage" and it provides an interactive GUI for analyzing disk usage. The tool allows us to navigate through directories and files, and have a look at the disk usage in a clear and concise manner.
To use ncdu, we need to first install it on our Linux system. For Debian/Ubuntu-based systems, we can use the apt-get package manager to install ncdu. We can run the following command in the terminal to install ncdu −
sudo apt-get install ncdu
For a Fedora/RHEL-based system, we can use the dnf package manager to install ncdu. We can run the following command in the terminal to install ncdu −
sudo dnf install ncdu
For Arch Linux-based systems, we can use the pacman package manager to install ncdu. We can run the following command in the terminal to install ncdu −
sudo pacman -S ncdu
Now, that we’ve installed `ncdu`, we can move on to the next section of the article where we'll understand how to use ncdu to display colorized disk space usage.
Using Ncdu to Display Disk Usage
Ncdu provides a user-friendly interface that allows us to easily navigate through directories and view their disk usage. We can use the arrow keys to move up and down the directory tree, and the Enter key to open a directory or file. Ncdu also provides the option to delete files and directories directly from the interface, which can be helpful in freeing up disk space.
When we run ncdu, it displays a color-coded list of directories and files along with their disk usage. The color coding helps us quickly identify the directories and files that are taking up the most space on our system. By default, ncdu sorts the directories and files in decreasing order of size, so we can easily see which directories and files are using the most disk space.
The color coding used by ncdu is as follows −
Green − directories
Blue − files
Red − files that are not accessible to the current user.
To use ncdu to display disk usage, we can simply run the following command in the terminal −
ncdu
The output of the above command will look something like this.
Output
ncdu 1.14.1 ~ Use the arrow keys to navigate, press ? for help --- /home/user --- 34.4 GiB [##########] /Downloads 7.9 GiB [## ] /Documents 2.2 GiB [ ] /Music 870.3 MiB [ ] /Pictures 620.9 MiB [ ] /Videos 513.2 MiB [ ] /VirtualBox VMs 189.7 MiB [ ] /Snap 76.6 MiB [ ] /bin 72.5 MiB [ ] /lib 41.2 MiB [ ] /opt 34.5 MiB [ ] /boot 9.2 MiB [ ] /sbin 5.5 MiB [ ] /include 3.1 MiB [ ] /src 1.8 MiB [ ] /lib32 192.0 KiB [ ] /share 176.0 KiB [ ] /local
As we observe the output displayed above, we can notice that ncdu presents a comprehensive list of all the directories along with the space they are currently occupying on the system. It is indeed an efficient tool to manage disk space and locate files that are occupying a considerable amount of storage.
Below is a snapshot of the actual output generated by running ncdu in the Linux terminal. This will give you a better understanding of how ncdu works and what information you can expect from this powerful utility.
Output
If we want to display the disk usage of a specific directory on a machine, we can specify the directory path as an argument to the ncdu command. For example, to display the disk usage of the `Downloads` directory, we can run the following command −
ncdu Downloads
Output
--- /Users/pryadav8/Downloads ----------------------------------------------------------------------------------------------------------------------------------------------------------- 3.1 GiB [##########################] /tagic 1.1 GiB [######### ] /tagic-admin 845.6 MiB [####### ] /tagicpartner 771.6 MiB [###### ] /apiGateway 404.3 MiB [### ] /tagicclientmarine 331.0 MiB [## ] /installers 145.4 MiB [# ] /apache-jmeter-5.5 112.1 MiB [ ] files-WhatsApp.dmg 93.6 MiB [ ] /images 81.5 MiB [ ] apache-jmeter-5.5.tgz 74.1 MiB [ ] /SolsticeClientMac_V2A0AB20B0EPCF6CIC8072571.app 53.9 MiB [ ] /archives 47.8 MiB [ ] /Lead Score Generation_again 30.9 MiB [ ] /redis 29.8 MiB [ ] /LeetHub 28.5 MiB [ ] /redis-6.2.5 Total disk usage: 7.5 GiB Apparent size: 6.3 GiB Items: 476,499
Output
Once ncdu has finished analyzing the disk usage, it will display the results in the terminal window. We can use the arrow keys to navigate through the directories and files, and the Enter key to open a directory or file. To exit ncdu, we can simply press the q key.
By using ncdu, we can quickly and easily analyze disk usage on our Linux system, and identify the directories and files that are taking up the most space. The color-coded interface makes it easy to identify which directories and files are using the most disk space, and the ability to delete files and directories directly from the interface can be helpful in freeing up disk space.
Conclusion
In this article, we have learned how to show colorized disk space usage in Linux using the ncdu command-line tool. The article summarizes the installation process of ncdu on different Linux systems and how to use it to navigate directories and view disk usage. The color-coding used by ncdu helps us to quickly identify the directories and files that are taking up the most space on our system. By using ncdu, we can easily manage our disk space and prevent performance issues and errors caused by running out of disk space.