Analyzing disk usage with ncdu on Linux systems

0 Shares
0
0
0
0

Introduction

Disk space management is a critical task for Linux system administrators. As the number and size of files and directories increase, tracking disk usage is essential to maintain system performance and ensure that critical processes have enough space to work. One tool that can help with this is ncdu (NCurses Disk Usage). This tutorial provides an in-depth look at ncdu, including details on how to install it, how to use it, and an overview of its optional parameters.

Ncdu, short for NCurses Disk Usage, is a command-line tool designed to help users and system administrators find and manage disk space usage on Linux systems. Unlike traditional disk usage tools like Du, ncdu It offers an interactive interface that makes it easier to navigate through lists and get a visual picture of space usage.

This tool is on the library. ncurses It is built to provide a text-based graphical interface in the terminal. This is ncdu It allows for a user-friendly way to explore directories, sort files and directories by size, and delete unnecessary files directly from the interface.

Step 1 – How to install ncdu

Before you can ncdu To use it, you need to install it on your system. Most Linux distributions include ncdu They are included in their default repositories, making installation easy using the system's package manager.

  • On Debian/Ubuntu based systems
sudo apt update
sudo apt install ncdu
  • On Red Hat/CentOS systems

For Red Hat based systems, you may need to enable the EPEL repository to find the ncdu package.

sudo yum install epel-release sudo yum install ncdu

 

  • On Fedora systems
sudo dnf install ncdu
  • In Arch Linux
sudo pacman -S ncdu

Once the installation is complete, you can use ncdu to analyze disk usage.

Step 2 – How to use Ncdu

To start analyzing disk usage with ncdu, just run the command followed by the path you want to check. If no path is provided, ncdu It will analyze the current working directory.

ncdu /path/to/directory
After executing the command, ncdu It scans the specified directory and presents an interactive interface. The interface shows a list of files and subdirectories along with their size and the percentage of disk space they occupy.

Step 3 – Optional ncdu parameters

ncdu offers several command line options that can change its behavior or alter its output. Here are some optional parameters that can be particularly useful:

  • -x: Only count files and directories on the same file system as the specified directory. This is useful for excluding mounted drives or network file systems.
  • -o: Export scanned data to a file that can be read later.
  • -r: Enable read-only mode, which disables the ability to delete files from within the interface.

For a full list of options, you can type man ncdu In the terminal to the page ncdu man See.

Step 4 – Advanced Usage and Tips

Beyond basic disk usage analysis, ncdu can be used in more advanced scenarios. For example, scan remote servers or check another user's disk usage.

  • Scan remote directories: ncdu can also scan remote directories via SSH. Use the following syntax:
ssh -C user@system ncdu -o- / | ./ncdu -f-

Make sure you have SSH access to the remote host and ncdu installed on both the local and remote machines.

  • Deleting files and directories: Be careful with this, but ncdu Allows you to delete files and directories from within your interface. Navigate to the file or directory and press d to delete it.

Result

ncdu is a powerful and user-friendly tool that can greatly simplify disk usage analysis on Linux systems. By providing an interactive interface and a variety of command line options, it allows both novice and experienced system administrators to manage disk space effectively. As with any system tool that can modify or delete files, it should be used with caution. Regular use of ncdu, combined with good disk management practices, can help ensure that your Linux systems run smoothly and are free of space issues.

Leave a Reply

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

You May Also Like