Exert control and defrag from the command line in Windows 7

Using the options available from the command line version of the Windows 7 defragmentation utility you have much more control over the maintenance of your storage devices.

Of all the maintenance tasks one must do to keep a personal computer running properly, none is as basic as defragmentation. The constant saving and deleting of files can cause major inefficiencies in the way your storage hardware performs. Running the Windows 7 defragmentation utility can restore some of that lost efficiency, but if you use the command line you can expand your options and enhance your control over the process.

Note: I saw this tip on TechNet but I wanted to expand on it a little bit. As they mention, the syntax for the Windows 7 version of the command line version of defrag.exe is different than it was for Vista.


The defrag.exe application should be run from an elevated command prompt. Click the Start button and type cmd in the Search box. Navigate to the cmd.exe menu item and right-click it to get to the context menu where you should click the Run as administrator entry as shown in Figure A,

Figure A

Run an elevated command line prompt
After answering the UAC, you will get the familiar command prompt window, similar to Figure B.

Figure B

Run defrag.exe from here

Here is the general syntax for defrag.exe:

Defrag <volume> | /C | /E <volumes> [/A | /X | /T] [/H] [/M] [/U] [/V]

And here is an explanation for each of the available options:




Defragment all local volumes on the computer.


Defragment all local volumes on the computer except those specified.


Display a fragmentation analysis report for the specified volume without defragmenting it. This option will tell you whether you actually need to defrag a particular drive.


Perform free-space consolidation on a particular volume. This option will delete some system restore points and other extraneous files and frees that space for use.


Track an operation already in progress on the specified volume. This option will report whether a defrag operation is currently taking place on a particular volume.


Run the operation at normal priority instead of the default low priority. Specify this option if a computer is not otherwise in use. This option should increase the speed at which a defrag operation is performed.


Defragment multiple volumes simultaneously, in parallel. You will need to have SATA or SCSI drives for this to be useful.


Print the progress of the operation on the screen. This is a good option to have on so you can track your commands - without it you may find yourself wondering if anything is happening.


Verbose mode. Provides additional detail and statistics, which will help your decision making, especially when coupled with the analysis option listed above.


The drive letter or mount point of the volume to defragment.

Bottom line

The various defrag options give you a significant amount of control with regard to this common utility. Probably the most common command with this technique would be:

Defrag C: /H /U /V
That would give the defrag operation for drive C: higher priority, show you the progress, and provide the most description during each step. (Figure C)

Figure C

Defrag complete

Additional information: