DU - CMD


Overview

The DU (Disk Usage) command in Windows CMD provides information about the quantity of disk space used by the specified files and directories. This tool is useful for managing and monitoring disk usage, helping users to identify how space is distributed in directories on their drives. It is commonly used in administrative environments, for system cleanup tasks, and optimizing space utilization.

Syntax

The basic syntax for the DU command is as follows:

du [options] [directory_path]
  • directory_path: Specify the path to the directory you want to analyze. If not specified, it defaults to the current directory.

Options/Flags

The following options modify the behavior of the DU command:

  • -l, --log-level level : Set the logging level (0-4). Default is 1.
  • -q, --quiet: Suppress all output, only show summary and errors.
  • -s, --summarize: Display only a summary of total disk usage size for the specified directory and any subdirectories.
  • -u, --usage: Show detailed usage statistics for specified directory.
  • -v, --verbose: Provide verbose output, listing each file/directory as it is processed.

Examples

  1. Basic Usage: To view the disk usage of the current directory:
    du
    
  2. Specify Directory: To calculate disk usage of a specific directory:
    du C:\Users\Username\Documents
    
  3. Summarized Output: To get the total disk usage of a directory without detail:
    du -s C:\Data
    
  4. Verbose Output: To view detailed disk usage including each file processed:
    du -v C:\Data
    

Common Issues

  • Permission Errors: When you lack necessary permissions to read a directory or file. Solution: Run CMD as Administrator.
  • Large Output: For directories with many files, output can be extensive. Solution: Use --summarize option to limit output.
  • Path Not Found: Specifying a non-existent directory will result in an error. Solution: Ensure the path is correct and accessible.

Integration

Combine DU with other commands for comprehensive tasks:

  • Pipe to sort for Ordered Output:
    du | sort -n
    
  • Scripting Usage:
    Create a batch file to report disk usage of multiple directories and log it:

    @echo off
    du C:\Users > C:\user_usage.txt
    du C:\Data >> C:\user_usage.txt
    
  • DIR: Lists files and folders in directories.
  • CHKDSK: Checks the file system and file system metadata of a volume for logical and physical errors.

For more detailed information, refer to the official Microsoft documentation or the help provided in the command line by running du /?.