Windows 7 / Getting Started

The Defrag.exe Command-Line Tool

You can use Defrag.exe to defragment a volume from the command line. As with other command-line utilities, you can include it as part of a script to be executed when the disk is not in use. To do so, click Start > All Programs > Accessories, right-click Command Prompt, and choose Run as administrator. Click Yes to accept the UAC prompt and then type the following command:

Defrag <volume> | /C | /E <volume> [/A | /X | /T] [/H] [/M] [/U] [/V] Table below describes the parameters of the Defrag command:

For example, the command defrag C: /X /V would defragment the C: volume, perform free space consolidation, and provide verbose output.

Parameters Available with the Defrag Command
ParameterMeaning
volumwThe drive letter of the volume to be defragmented. You can specify more than one drive letter if needed.
/BOptimizes boot files and applications but does not defragment the rest of the volume.
/CDefragment all local volumes.
/EDefragment all local volumes except those specified.
/AAnalyze the volume and display a report, but do not defragment.
/XPerform free space consolidation.
/TTrack a defragmentation already in progress.
/HRun the defragmentation at normal priority (by default, runs at low priority).
/MDefragment multiple volumes simultaneously in parallel.
/UPrint the defragmentation process on the screen.
/VUse verbose mode, which provides additional detailed information.

Error Checking

Occasionally, a volume might not appear in the Disk Defragmenter dialog box. This might happen because the disk contains errors such as bad sectors. You can check a disk for errors and repair problems by accessing the Tools tab of the disk's Properties dialog box and clicking Check now. You receive the Checking Disk dialog box. To proceed, select Automatically fix file system errors. If desired, also select the Scan for and attempt recovery of bad sectors option. Then click Start. If the disk is in use, Windows will ask you whether you want to dismount the disk, which will invalidate any opened references to the disk. Click Force a dismount to do so or Cancel to perform the disk check later. You can then schedule the disk check to take place on the next reboot. Note that this might slow down the startup significantly, especially if you've selected the Scan for and attempt recovery of bad sectors option.

Checking Disk for Errors
[Previous] [Contents] [Next]