Defragmenting your hard drive

March 2018

Defragmentation allows the consolidation of file fragments scattered on the disk to optimize the access time of hard disk when reading large files.

During this process sophisticated algorithms are used to determine the position of fragments and unused disk space and here are some precautions that should be taken:
  • The NTFS file system allows you to use your PC during the defragmentaion process, without resuming the whole process. However, files in use will not be defragmented.

Note that: When Windows is started normally, many processes are running in the background and to defragment optimally, it is highly recommended to start Windows in Safe Mode, then run the defrag!

To start the defragmentaion process:
  • For Windows XP and other versions, the procedure is basically the same:
  • Open My Computer, right click the disk of you choice and go to Properties.
  • Choose the Tools tab and click Defragment Now

Using Command line

It is also possible to run the defrag in command line:
  • defrag c: -f

Tip: You can defragment faster forcing defragmentation at startup:
  • Run regedit
  • Go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce
  • Right-click in the right window, "New"> "value string"
  • Name it "Defrag"
  • Double-click on it and enter: defrag.exe c: -f
  • Restart Windows and log

Defragmentation starts before starting other programs.

Selective defragmentation of a file or directory

You can defragment a single file or a directory with freeware from Microsoft: CONTIG

For example, to defragment a file:
  • contig myfile.iso

Defragment a directory (and subdirectories):
  • contig -s c:\windows\*.*

Defragment all files on the disk in the background:
  • start /low contig -s c:\*.*

Defragment while screen saver is active

The ultimate solution is to run the defragmentation whenever the screen saver is triggered:

JKDefrag is a small freeware program that uses the built-in Windows defragmenter to defragment your disk.
Since it uses the Windows API, it is as safe as Windows defragmenter.

Download JkDefrag and copy the JkDefragScreenSaver.scr to C:\Windows .

Defragment the pagefile (swap)

By default, Windows Defragmenter can not defragment the pagefile (swap, pagefile.sys).
This is problematic because the speed of access to this file is critical.

Also, Windows is not able to defragment the files being used in real-time, such as those of the registry.

There is a freeware that can do this PageDefrag:
  • Start PageDefrag
  • Select "Defragment at next boot" and click OK
  • Restart your computer.
Published by jak58. Latest update on February 27, 2018 at 12:36 PM by Jeff.
This document, titled "Defragmenting your hard drive," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (
ownCloud launches new cloud based services for professionals
What is HootSuite and how does it works?