Defrag command in Windows

The defrag command locates and merges fragmented files on local drives to improve system performance. Local administrator, or equivalent, is the minimum necessary requirement to run this command.

Applies to : Windows Server (Semi-Annual Channel), Windows Server 2016, Windows Server 2012 R2, Windows Server 2012.

The defrag command locates and merges fragmented files on local drives to improve system performance. Local administrator, or equivalent, is the minimum necessary requirement to run this command.

Defrag command in Windows

  1. Syntax defrag command
  2. Parameters
  3. Note
  4. For example
  5. Scheduled task

Syntax defrag command

 defrag | /C | /E [/H] [/M [n]| [/U] [/V]] defrag | /C | /E /A [/H] [/M [n]| [/U] [/V]] defrag | /C | /E /X [/H] [/M [n]| [/U] [/V]] defrag [/]* 

Parameters

ParameterDescription Specify the drive letter or path to the mount point of the fragmented or analyzed drive. A Perform an analysis of the specified drive. C Perform operations on all drives. D Perform traditional defragmentation (this is the default). However, on a stratified partition, the traditional defragmentation feature is only implemented on Capacity level. E Perform operations on all drives, except for the specified drives. G Optimize storage layers on specified drives. H Running at normal priority (default is low). I n The process of optimizing floors will run for up to n seconds on each drive. K Perform consolidation on the specified drive. L Perform the split again on the specified drive. M [n] Runs operations on each parallel drive in the background process. For up to n threads, it will optimize parallel storage layers. O Perform optimization appropriate for each type of media. T Track an activity that has been performed on the specified drive. U Export the process of action on the screen. V Output detailed output containing fragmented statistics. X Integrate free space on the specified drives. ? Show help information.

Note

  1. You cannot defragment certain types of partitions or specific file system drives:
    1. You cannot defragment the file system that has been locked.
    2. You cannot defragment the drive where the file system is marked as dirty, a sign that the system may be corrupted. You must run chkdsk on the dirty drive before you can defragment it. You can determine whether a drive is dirty or not, using the fsutil query command .
    3. You cannot defragment network drives.
    4. You cannot defragment cdROM.
    5. You cannot defragment a file system drive other than NTFS, ReFS, Fat or Fat32.
  2. With Windows Server 2008 R2, Windows Server 2008 and Windows Vista, you can schedule to defragment a drive. However, you cannot schedule to defragment Solid State Drive (SSD) or drive volumes on Virtual Hard Disk (VHD) located on an SSD.
  3. To perform this procedure, you must be a member of the Administrators group on the local computer or you must have the appropriate permissions. If the computer is attached to a domain, members of the domain administrator group can perform this procedure. As a best security method, consider using Run As to implement this process.
  4. The drive must have at least 15% of free space for the defrag command to completely and completely defragment. The defrag command uses this space to classify fragmented files. If a drive has less than 15% of free space, the defragmentation feature will only defragment part of it. To increase free space on the drive, delete unnecessary files or move them to another drive.
  5. While the defrag command is analyzing and defragmenting a drive, it will show the blinking cursor. When defrag finishes analyzing and defragmenting the drive, it will display the analysis report, report fragmentation, or both reports, and then exit the command prompt.
  6. By default, defrag displays a summary of both the analysis report and the fragmentation report if you do not specify the / a or / v parameter .
  7. You can view the report as a text file by entering > FileName.txt , where FileName.txt is the name of the file you specify. For example:
 defrag volume /v > FileName.txt 
  1. To interrupt the defragmentation process, at the command line, press CTRL + C.
  2. Running the defrag command and Disk defragmenter eliminates each other. If you are using the Disk defragmenter to defragment the drive and run the defrag command at the command line, the defrag command will fail. Otherwise, if you run the defrag command and open the Disk defragmenter at the same time, the defragmentation option in Disk defragmenter is also unavailable.

For example

To defragment on drive C and provide detailed results on progress, enter:

 defrag C: /U /V 

For parallel defragmentation on drives C and D in the background process, enter:

 defrag C: D: /M 

To perform a defragmentation analysis of the mounted drive on C drive and track progress, enter:

 defrag C: mountpoint /A /U 

To defragment all drives with normal priority and provide detailed output, enter:

 defrag /C /H /V 

Scheduled task

The scheduled task of the defrag command acts as a maintenance task and is usually scheduled to run each week. Admin can change the frequency with Optimize Drives application .

  1. When running from a scheduled task, the defrag command has below the following policy for SSD:
    1. Traditional defrag (eg moving files to make them arranged in logical order) and retrim only run once a month.
    2. If both t raditional defrag and retrim are ignored, analysis will not be performed.
    3. If the user runs t raditional defrag manually on the SSD, 3 weeks after the last scheduled task run, the next scheduled task will perform analysis and retrimination but ignore traditional defrag on the SSD.
    4. If analysis is ignored, the Last run time in Optimize Drives will not be updated. Therefore, for SSD, the Last run time in Optimize Drives can be calculated in months.
  2. Sometimes, this maintenance task may not defragment all drives, as this task is performed as follows:
    Do not "wake up" the computer to run the defrag command .
    1. Only start if the computer is on AC power and stop if the computer switches to battery power
    2. Stop if the computer stops working

See more:

  1. Cmstp command in Windows
  2. Dcgpofix command in Windows
  3. Del command in Windows
4.5 ★ | 2 Vote