Defrag command in Windows
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
- Syntax defrag command
- Parameters
- Note
- For example
- 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
- You cannot defragment certain types of partitions or specific file system drives:
- You cannot defragment the file system that has been locked.
- 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 .
- You cannot defragment network drives.
- You cannot defragment cdROM.
- You cannot defragment a file system drive other than NTFS, ReFS, Fat or Fat32.
- 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.
- 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.
- 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.
- 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.
- 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 .
- 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
- To interrupt the defragmentation process, at the command line, press CTRL + C.
- 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 .
- When running from a scheduled task, the defrag command has below the following policy for SSD:
- Traditional defrag (eg moving files to make them arranged in logical order) and retrim only run once a month.
- If both t raditional defrag and retrim are ignored, analysis will not be performed.
- 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.
- 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.
- 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 .
- Only start if the computer is on AC power and stop if the computer switches to battery power
- Stop if the computer stops working
See more:
- Cmstp command in Windows
- Dcgpofix command in Windows
- Del command in Windows
You should read it
May be interested
- Guide to run hard drive defrag on Windows 10 to speed up Windowshard drive defragmentation is one of the effective methods to help speed up the windows computer by making the data on your hard disk more neat and tidy. so how to defragment hard drive on windows 10? please follow the instructions below.
- 10 useful commands in Windows you should knowcommand prompt is used to execute batch files, perform tasks quickly, help you troubleshoot and solve some windows problems when the system crashes. however, not all commands in windows are useful and must be done regularly. with the 10 command lines in the following article it is very useful even if you are not an administrator.
- How to Defrag Windows 10when too many files in your hard disk are in different places or clusters in your hard disk, or 'fragmented,' your computer slows down. when you defrag your drive, the pieces of files are moved to locations that are contiguous (beside each...
- How to use the option equivalent to the 'ls' command in Windowsthe 'ls' command (note ls, not is) is one of the first terminal commands veterans teach to linux beginners.
- The command reg add in Windowsthe reg add command adds new subkeys or entries to the registry.
- Rem command in Windowsthe rem command helps write comments (comments) in a batch file or config.sys.
- Instructions for using Command Promptdeep in windows is a command-line world that is obscure. in this article, we will show you how to solve errors and make your computer more secure.
- Rd command in Windowsthe rd command helps delete a directory
- Cmd command in Windowsthe cmd command starts a new version of the command interpreter, cmd.exe. if used without parameters, cmd will display copyright information and the version of the operating system.
- How to use the command history function in Command Promptcommand prompt is an extremely familiar command for anyone using windows operating system. besides, a lot of current software also supports the command line to perform actions on the command prompt window, instead of on the screen.