This guide explains how to use ncdu (NCurses Disk Usage) on Ubuntu to browse, analyze, and manage disk space. With ncdu, you can easily identify large files and directories, navigate through your filesystem, delete unnecessary files, and free up disk space.
Step 1: Launch ncdu
-
Open your terminal.
-
Run the following command to start
ncduin the current directory:ncduncduwill scan the directory and its subdirectories, displaying a list of files and folders sorted by size. -
If you want to scan a specific directory, use:
ncdu /path/to/directoryReplace
/path/to/directorywith the directory you want to analyze.
Step 2: Understanding the Interface
After ncdu finishes scanning, you will see:
-
A list of files and directories, sorted by size (largest at the top).
-
The total size of the scanned directory displayed at the top of the interface.
-
File and directory sizes are displayed on the left.
Step 3: Navigating in ncdu
Use the following keys to navigate within ncdu:
-
Up/Down Arrow Keys: Move up or down through the list.
-
Enter: Open (navigate into) a directory or view the contents of a file.
-
Left Arrow: Go back to the parent directory.
-
Right Arrow: Open a directory (same as Enter).
Step 4: Deleting Files or Directories
To delete unwanted files or directories:
-
Navigate to the file or directory you want to delete using the arrow keys.
-
Press d (delete) on your keyboard.
-
Confirm the deletion when prompted.
Warning: Be careful when deleting files, as this action is irreversible.
Step 5: Quit ncdu
To exit ncdu, press q on your keyboard.
Example Commands
-
Scan the root directory (requires sudo):
sudo ncdu / -
Analyze a specific directory (e.g.,
/var):ncdu /var
Conclusion
ncdu is a powerful and user-friendly tool for managing disk space on Ubuntu. By navigating through directories and identifying large files, you can efficiently free up space. Always double-check files before deletion to avoid accidentally removing important data.