Defrag

Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2

Defrag

Locates and consolidates fragmented boot files, data files, and folders on local volumes.

Syntax

defrag Volume

defrag Volume [/a]

defrag Volume [/a] [/v]

defrag Volume [/v]

defrag Volume [/f]

Parameters
  • Volume
    The drive letter or a mount point of the volume to be defragmented.
  • /a
    Analyzes the volume, displays a summary of the analysis report, and indicates whether you should defragment the volume.
  • /v
    Displays the complete analysis and defragmentation reports. When used in combination with /a, displays only the analysis report. When used alone, displays both the analysis and defragmentation reports.
  • /f
    Forces defragmentation of the volume when free space is low.
  • /?
    Displays help at the command prompt.
Remarks
  • A volume must have at least 15% free space for defrag to completely and adequately defragment it. Defrag uses this space as a sorting area for file fragments. If a volume has less than 15% free space, defrag will only partially defragment it. To increase the free space on a volume, delete unneeded files or move them to another disk.

  • You cannot defragment volumes that the file system has marked as dirty, which indicates possible corruption. You must run chkdsk on a dirty volume before you can defragment it. You can determine if a volume is dirty by using the fsutil dirty query command. For more information about chkdsk and fsutil dirty, see Related Topics.

  • While defrag is analyzing and defragmenting a volume, it displays a blinking cursor. When defrag is finished analyzing and defragmenting the volume, it displays the analysis report, the defragmentation report, or both reports, and then exits to the command prompt.

  • By default, defrag displays a summary of both the analysis and defragmentation reports if you do not specify the /a or /v parameters.

  • You can send the reports to a text file by typing **>**FileName.txt, where FileName.txt is a file name you specify. For example:

    defragVolume**/v>**FileName.txt

  • To interrupt the defragmentation process, at the command line, press CTRL+C.

  • Running the defrag command and Disk Defragmenter are mutually exclusive. If you are using Disk Defragmenter to defragment a volume and you run the defrag command at a command-line, the defrag command fails. Conversely, if you run the defrag command and open Disk Defragmenter, the defragmentation options in Disk Defragmenter are unavailable.

Examples

To analyze drive C, type:

defrag C: /a

To analyze drive C and display the analysis report, type:

defrag C: /a /v

To defragment drive C, type:

defrag C:

To defragment drive C and display the defragmentation report, type:

defrag C: /v

Formatting legend

Format Meaning

Italic

Information that the user must supply

Bold

Elements that the user must type exactly as shown

Ellipsis (...)

Parameter that can be repeated several times in a command line

Between brackets ([])

Optional items

Between braces ({}); choices separated by pipe (|). Example: {even|odd}

Set of choices from which the user must choose only one

Courier font

Code or program output

See Also

Concepts

Defrag
Command-line reference A-Z
Command shell overview
chkdsk
Fsutil
Fsutil: dirty