6

Ncdu Command in Linux: Disk Usage Analysis with Examples

 9 months ago
source link: https://linuxblog.io/ncdu-command-in-linux-examples/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Disk Usage Analysis with Examples

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.

Teleport

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.

What is Ncdu?

ncdu Linux

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]

Initiate ncdu by navigating to the desired directory and executing:

ncdu

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:

ncdu /home

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.

ncdu examples

Analyzing Specific Directories: Direct ncdu to analyze a particular directory by specifying its path:

ncdu /var/www/html

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 -o option:

ncdu -o

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'

Using 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 du command.

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

Conclusion

The 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.

Useful links/references: 

Related commands:

  • pstree – display a tree of processes.
  • ls – list directory contents.
  • df – display disk space usage.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK