This article is a follow-up to the previous 90 Linux Commands frequently used by Linux Sysadmins post. As time allows, I will continue to publish articles on each of these 90 commands, geared toward Linux sysadmins and Linux power users.
Efficient disk space management is a key aspect of Linux system administration. The
ncdu (NCurses Disk Usage) command offers a significant improvement over the traditional
du command, providing a more interactive and user-friendly approach to analyzing disk space.
Table of Contents
What is Ncdu?
ncdu is a command-line utility in Linux that delivers an interactive and detailed view of the space occupied by files and directories. It stands out for its ease of use and interactive interface, making it a popular choice for system administrators and users who need a straightforward method to manage disk space.
Basic Command Structure
ncdu [options] [directory]
ncdu by navigating to the desired directory and executing:
This command scans the directory and displays a list of files and subdirectories, along with their respective sizes.
You can also use it this way:
This command initiates a scan of the
/home directory, presenting an interactive interface to view and navigate through the disk usage of each file and folder within it.
Analyzing Specific Directories: Direct
ncdu to analyze a particular directory by specifying its path:
This command is useful for monitoring disk usage in web server directories.
Sorting Output: Sort the output by size, name, or modification time using the
Exporting and Importing Scan Results: Save scan results for later review:
ncdu -o results.ncdu /path/to/directory
To read these results at a later time:
ncdu -f results.ncdu
Excluding Files or Directories: Exclude certain files or directories from the scan, useful for omitting non-essential items:
ncdu --exclude '/path/to/exclude'
ncdu offers several advantages:
- Time Efficiency: Facilitates quick identification of large files or directories.
- Resource Optimization: Aids in server storage management.
- Ease of Use: More user-friendly than the traditional
You can interact with the ncdu interface using the supported keys:
↑,↓ or k,j to Move →,l to enter ←,h to return g toggle graph c toggle counts a toggle average size in directory m toggle modified time u toggle human-readable format n,s,C,A,M sort by name,size,count,asize,mtime d delete file/directory v select file/directory V enter visual select mode D delete selected files/directories y copy current path to clipboard Y display current path ^L refresh screen (fix screen corruption) r recalculate file sizes ? to toggle help on and off q/ESC/^c to quit
ncdu tool is an invaluable resource for disk space management on Linux systems. Its interactive approach, makes it a great utility for Linux storage administration tasks. It simplifies disk usage analysis, catering to the needs of both novice and experienced Linux users.