Disk Defragment from the Vista command line

       548 words, 3 minutes

The Windows Vista Disk Defragmenter has been improved over the Windows XP version, but you can’t see or use all the best features unless you run it from the command line.


By default the defrag tool only defragments files smaller than 64 MB, because according to Microsoft’s benchmarks, fragments of this size, which already consist of at least 16000 contiguous clusters, have a negligible impact on performance. If you still want to defrag files larger than 64 MB too, you need to use the -w switch mentioned below to defragment files of all size.

Disk Defragmenter does not defragment files in the Recycle Bin, or files which are in use. Disk Defragmenter will not degragment Bootsect dos, Safeboot fs, Safeboot csv, Safeboot rsv, Hiberfil sys, Memory dmp, or the Windows page file. Using the -b parameter will optimize these boot files.

Some swtiches that are available from the command line for Disk Defragmenter are:

<volume> Specifies the drive letter or mount point path of the volume to be
defragmented or analyzed.

-c    Defragments all volumes on this computer.
      Don’t specify a drive letter while using this.

-a    Performs fragmentation analysis only.

-r    Performs partial defragmentation (default). Attempts to
      consolidate only fragments smaller than 64 megabytes (MB).

-w    Performs full defragmentation. Attempts to consolidate all file
      fragments, regardless of their size, even 64 MB files.

-f    Forces defragmentation of the volume when free space is low.
      A volume must have at least 15 % free space before Disk Defragmenter
      can completely defragment it.

-i    This makes Defrag run <a href="http://ss64.com/nt/in.html">in</a>
      the background, and operate only <a href="http://ss64.com/nt/if.html">if</a> the
      computer is idle, like when run as a scheduled task.

-b    Optimizes boot files and applications only. Use this option
      during a separate defrag operation.

-v    Specifies verbose mode. The defragmentation and analysis output
      is more detailed

The only indication you will get is a blinking cursor. This means that the process is going. To interrupt the defragmentation process, press Ctrl + C in the command window.

If you find that you are unable to defragment or cannot run the defragment utility in Vista or that a drive or volume has been marked by Vista as having errors, run chdsk by entering: > chkdsk c: /f ... at a command prompt; where c is the drive letter. You will be able to then run Defrag after Chkdsk has repaired the file system.

To run you will need to run the command line prompt as the Administrator. If you’re not sure how to open a command line, or open it as an Administrator click here.

To defrag you boot files enter into the command line:

> defrag c: -b

To defrag all files on all drives/volumes, even the files over 64 MB enter into the command line:

> defrag -cwv

This may take a while, but you’ll see a report for each drive. The cursor will blink until finished, then it will return to the command prompt.

Here are a few other examples:

> defrag d:  
> defrag d:’vol’mountpoint -w -f  
> defrag d: -a -v

You could use the command line once a week, or even once a month, in addition to daily default defragmenting to keep your computer running faster.

Source: Disk Defragment Windows Vista from the Command Line