DEFRAG.exe

Defragment hard drive volumes.

Syntax
      Defrag Volumes Operations [Options]

Volumes:
   /C | /AllVolumes
           On each volume run only the preferred operations from the given list of operations.

   /E | /VolumesExcept volume-paths
           Perform all the given operations on each volume except those specified.
           If the exception list is empty, this behaves as /AllVolumes.

           volume-paths The drive letter followed by a colon, mount point or volume name.
                        More than one volume can be specified. 
                        Run all the given operations on each specified volume.
Operations:
   /A | /Analyze
           Analyze the drive to show the current fragmentation status.

   /B | /BootOptimize
           Perform boot optimization to increase boot performance.

   /D | /Defrag
           Perform traditional defrag (this is the default). On a tiered volume, traditional
           defrag is performed only on the Capacity tier.

   /G | /TierOptimize
           On tiered volumes, optimize files to reside on the appropriate storage tier.

   /K | /SlabConsolidate
           On thinly provisioned volumes, perform slab consolidation to increase slab usage efficiency.

   /L | /Retrim
           On thinly provisioned volumes, perform retrim to release free slabs.
           On SSDs perform retrim to improve write performance.

   /O | /Optimize
           Perform the proper optimization for each media type.

   /T | /TrackProgress
           Track progress of a running operation for a given volume. An instance can show
           progress only for a single volume. To see progress for another volume launch another instance.

   /U | /PrintProgress
           Print the progress of the operation on the screen.

   /V | /Verbose
           Print verbose output containing the fragmentation statistics.

   /X | /FreespaceConsolidate
           Perform free space consolidation, moves free space towards the end of the volume
           (even on thin provisioned volumes). On tiered volumes consolidation is performed only
           on the Capacity tier.

Options:
   /File file-path-1 file-path-2 ... file-path-n
           To defrag only the selected files, specify multiple file paths seperated by space.
           Available only with Defrag.
           Wildcards may be used to defrag multiple files.

   /FileList listfile path
           This file contains the list of files (wildcards are supported)
           to be defragmented. Available only with Defrag. 

   /H | /NormalPriority
           Run the operation at normal priority (default is low).

   /I | /MaxRuntime n
           Run Tier optimization for at most n seconds on each volume.
           Available only with TierOptimize.

   /LayoutFile file-path
           Available only with BootOptimize. This file contains the list of files to be optimized.
           The default location is  %windir%\Prefetch\layout.ini.

   /M | /MultiThread [n]
           Run the operation on each volume in parallel in the background.
           For TierOptimize, at most n threads optimize the storage tiers in parallel.
           Default value of n is 8. All other optimizations ignore n.

   /OnlyMetadata
           Defrag only certain metadata files (like MFT and USN Journal) of each volume.
           Available only with Defrag. 
           The default behavior of Defrag operation will ignore the above metadata files.
           This option is supported on NTFS volumes only.

   /OnlyPreferred
           When volumes are specified explicitly, defrag performs all the given operations on each
           specified volume.  This switch lets defrag run only the preferred operations, from the
           given list of operations, on each specified volume.

Windows 10/ Server 2012 only support the following short options: /A /C /D /E /G /H /I /K /L /M /O /U /V /X /T

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:

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 a 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 2am. An Administrator can change the frequency using Optimize Drives application.

Examples

Analyse drive C: to see if it needs to be defragmented:

DEFRAG C: /Analyze /PrintProgress

Defragment drive c with verbose output saved to a file:

DEFRAG C: /U /V > FileName.txt

Defragment drives C and D in parallel with Tier Optimisation:

DEFRAG C: D: /TierOptimize /MultiThread

“This plastic doesn’t go away by itself, and to just let hundreds of thousands of tons of plastic be out there to be fragmented into these small and dangerous microplastics to me seems like an unacceptable scenario” ~ Boyan Slat

Related commands

CleanMgr - Automated cleanup of Temp files, Internet files, downloaded files, recycle bin.
DISKPART - Partition manager.
Contig - Single-file defragmenter (SysInternals/Microsoft).


 
Copyright © 1999-2026 SS64.com
Some rights reserved