how to check disk usage on linux

Updated

To check disk usage on Linux, you can use several built-in commands depending on whether you need a system-wide overview or details about specific files and directories.

1. Check Overall Filesystem Usage (df)

The df (disk free) command provides a summary of disk space usage for all mounted filesystems.

  • Command: df -h
  • Why use it: The -h flag makes the output "human-readable" (showing sizes in GB, MB, etc., instead of blocks).
  • What it shows: Total size, used space, available space, and the mount point for each filesystem.

2. Check Directory and File Usage (du)

The du (disk usage) command helps you identify which specific directories or files are consuming space.

  • Command: du -sh /path/to/directory
  • Options:

* -s: Displays only a summary for the specified directory.

* -h: Displays sizes in human-readable format.

  • Analyze Subdirectories: To see the size of subdirectories within a folder, use du -h --max-depth=1 /path/to/directory.

3. Interactive Analysis (ncdu)

If you prefer a more user-friendly, navigable interface within the terminal, ncdu is a popular tool. It allows you to browse through your directories and see exactly where your disk space is going.

  • Note: You may need to install this via your package manager (e.g., sudo apt install ncdu on Debian/Ubuntu).

Summary Table

Command Purpose Best For
df -h System-wide disk usage Seeing overall disk capacity and availability.
du -sh Directory/File usage Finding out which folders are taking up the most space.
ncdu Interactive analysis Visually exploring and cleaning up large files.