The DEFRAG command is used to defragment a hard drive, which consolidates fragmented files and folders on the computer’s hard disk so that each occupies a single, contiguous space. This process can enhance the system’s performance by improving read/write efficiency on the disk. DEFRAG is particularly effective on machines that handle large files frequently and have experienced a decline in performance over time.


The basic syntax for using DEFRAG in Windows Command Prompt is:

DEFRAG <volume> [parameters]
  • <volume>: Specifies the drive letter (followed by a colon), mount point, or volume name.
  • [parameters]: Optional parameters that control the operation.


The DEFRAG command includes several options that modify its behavior:

  • /A: Perform analysis on the specified volumes.
  • /C: Defragment all volumes.
  • /E: Defragment all volumes except those specified.
  • /H: Run the operation at normal priority instead of the default low priority. Use this option to speed up the defragmentation process.
  • /M [n]: Run the operation on each volume in parallel in the background. Optional [n] specifies the number of threads to use.
  • /O: Perform the proper optimizations for each media type.
  • /T: Track an operation already in progress on the specified volume.
  • /U: Print the progress of the operation on the screen.
  • /V: Print verbose output containing the fragmentation statistics.
  • /X: Consolidate free space. Useful for preventing further fragmentation.


  1. Analyze Disk Fragmentation:

    DEFRAG C: /A

    Analyzes the disk fragmentation on drive C and displays a summary of the fragmentation statistics.

  2. Defragment All Disks:


    Defragments all volumes on the computer.

  3. Optimize and Defragment a Specific Disk:

    DEFRAG D: /O

    Optimizes and defragments the volume D. This is particularly useful for media-heavy storage where performance is critical.

  4. Verbose Output of Defragmentation Process:

    DEFRAG C: /V

    Provides a detailed view of the defragmentation process on drive C.

Common Issues

  • Access Denied: Ensure you are running Command Prompt as an administrator to use DEFRAG.
  • Drive Errors: Run CHKDSK before defragmenting to fix any file system errors that could interfere with the defragmentation process.
  • Performance Impact: Defragmenting can be resource-intensive. Use the /H option to run at normal priority if the machine is not in use.


Combine DEFRAG with other commands for system maintenance, such as:


This command first fixes errors on the C drive with CHKDSK, then defragments the drive with DEFRAG.

  • CHKDSK: Checks the disk for errors and displays a status report.
  • DISKPART: A command-line disk partitioning utility.
  • OPTIMIZE-DRIVES: A PowerShell cmdlet that optimizes a drive, which might involve defragmentation.

For detailed documentation, visit the Microsoft official DEFRAG documentation.