DEFRAG.exe – Windows CMD Command

Defragment hard drive volumes.

Defrag has an undocumented option/b (boot optimization) which will clear out the Windows\Prefetch directory. Deleting prefetch files will make the machine boot more slowly so this is not recommended.

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.

Supported file systems: NTFS, ReFS, Fat or Fat32.

To run Defrag, you must be a member of the Administrators group on the local computer or have been delegated the appropriate authority. When working defrag will display a blinking cursor.

On a tiered volume traditional defrag (/D) is performed only on the Capacity tier. (See FSUTIL tiering)

Some file system volumes or drives cannot be defragmented:

  • Volumes that the file system has locked.
  • Volumes that the file system has marked as dirty, which indicates possible corruption. Run CHKDSK on a dirty volume to resolve this.
    Use the fsutil dirty query command to determine if a volume is dirty.

Volume names can be given either using the assigned drive letter (C:\) or the full volume name/path (\\?\Volume{…)

To obtain a list of volume_names using PowerShell:

PS C:\> Get-CimInstance Win32_Volume | Format-Table Name, Label, FreeSpace, Capacity

Free space consolidation (/X) takes all free sectors on the volume and arranges them together so they are contiguous. This is normally done only when you intend to re-size the volume with DISKPART SHRINK to make it smaller.
Ensure you have a good backup before running any consolidate/shrink process as this has a tendency to fail.

Defrag’s scheduled task runs as a maintenance task and by default is scheduled to run every 7 days at 2 am. An Administrator can change the frequency using the Optimize Drives application.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *