Explore Disk Usage with Ncdu

LinuxLinuxBeginner
Practice Now

Introduction

ncdu (NCurses Disk Usage) is a simple yet powerful command line tool that offers a detailed view of disk usage, enabling users to navigate through directories and clean up their disk space interactively. It's an improvement over the traditional du command, providing a user-friendly interface and additional features for sorting and deleting files directly from its interface.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux/SystemInformationandMonitoringGroup -.-> linux/du("`File Space Estimating`") linux/PackagesandSoftwaresGroup -.-> linux/software("`Linux Software`") subgraph Lab Skills linux/du -.-> lab-296141{{"`Explore Disk Usage with Ncdu`"}} linux/software -.-> lab-296141{{"`Explore Disk Usage with Ncdu`"}} end

Analyze and Manage Disk Space

To start using ncdu for a full system disk usage analysis, enter the following command into terminal:

ncdu /
alt text

This command initializes ncdu at the root directory, allowing you to analyze the disk usage of your entire filesystem. Once ncdu is running, you will see a textual user interface listing all files and directories in the root, along with their sizes.

Basic Operating within Ncdu

  • Navigation: Use the up and down arrow keys or j and k to cycle through the items. Use the right arrow or enter to open a selected directory, and the left arrow to return to the parent directory.
  • Sorting: Press s to sort items by file size, n for name, C for number of items, or M for modified time. Press the same key again to toggle ascending and descending order.
  • Viewing Options:
    • Toggle between disk usage and apparent size by pressing a.
    • Change the display mode by pressing g to show percentage, graphical representation, both, or none.
    • Press c to toggle the display of child item counts, and m for the latest modified time of child items (requires the -e flag).
  • Deleting Files: Press d to delete the selected file or directory. You will receive a confirmation prompt to prevent accidental deletions.
  • Additional Utilities:
    • Press i for detailed information about the selected item.
    • Press b to spawn a shell in the current directory. This can be customized with the NCDU_SHELL environment variable.
    • Press r to refresh or recalculate the current directory.
  • Exiting: Press q to exit ncdu and return to the command line.

Using ncdu from the root directory provides a comprehensive overview of where disk space is being utilized across your entire system, making it easier to perform cleanups and maintain efficient storage practices.

Summary

ncdu provides a highly interactive and intuitive way to analyze disk space usage on Linux systems. It offers a significant improvement over traditional methods, making it easier to identify and manage space hogs within your file system. By integrating ncdu into your regular system maintenance routines, you can efficiently manage disk space and keep your system clean and organized.

Other Linux Tutorials you may like