How to Defragment Hard Drives in Windows


In this occasion we want to share with you a small guide so that you learn how to defragment the hard disks in Windows from the command line, as well as to defragment disks, drives, folders, directories and even the files of pagination and of the registry.

But first you must know that the fragmentation of files on hard disks is nothing more than a normal and inevitable process due to the dynamics of the system’s operation, as copy and read processes frequently occur.

Photo Unsplash

In addition, this turns out to be one of the most common and current causes of the loss of performance of any operating system, therefore, it is important to regularly defragment the units of the equipment, initially the system.

You must take into account that a computer after 6 months of installing the system, when defragmenting correctly its disk works 50% faster, otherwise the fragmentation in the disks does the following:

  • It slows down the computer and decreases performance.
  • It increases the physical wear of the discs due to the excessive and unnecessary operation of the heads.
  • Increases the likelihood that files will be irreversibly damaged.

How does fragmentation work and why does it happen?

However, the fragmentation in the disks originates at the moment of copying new files sinceWindows places them in the available sectors no matter if they are less than the total file size.

For example, a text file that occupies only 4KB can be placed in adjacent sectors of the disk, if they exist, but if they do not, it will be distributed in different sectors even if they are physically distant.

When the disk is new or recently formatted, the copied files occupy contiguous clusters with each other, so there is no fragmentation.

However, as time goes by and due to the normal dynamics of working on the PC, files are erased and others are copied, so the time comes when the free space is distributed very unevenly and chaotically in the structure of the disk.

On the other hand, a simple file only 1 MB in size, can be physically divided into hundreds or thousands of fragments inside the disk, all this is sharpened if you copy and delete web pages often that normally have multitude of auxiliary files.

In addition, fragmentation brings with it additional work to the hard drive head, which can slow down your computer.

So the disk defragmenter moves and organizes the fragmented data logically again, so that the disks and drives can work more efficiently.

This is how the defragmenter works in Windows 7

The simple and discreet interface of the disk defragmenter that is introduced in Windows with the launch of Vista and later in Windows 7, does not convince most users accustomed to the tool that was used in Windows XP.

For this reason many of them prefer to install third-party programs to perform this task and even some illusions think that they can be more effective than the tool itself that includes the operating system.

There are even advantages and disadvantages of the Windows tool for defragmenting disks. Among the advantages we can mention that it does not interfere with other processes since it is only activated when the computer is in idle state (the user is not performing any task).

While its disadvantage is that by frequently using the equipment, you never effectively defragment the disks. But how to defragment the disks with the Windows tool? Here are the steps to follow:

  • In My Computer, select the unit to defragment.
  • Then right-click and in the Properties menu select Tools, then press the “Defragment Now” button. The Disk Defragmenter window will open.
  • Now select one of the drives and press the “Analyze disk” button.
  • Wait for the analysis to finish, if it is not necessary to defragment it will be shown in the result.
  • To start the defragmentation process use the “Defragment Disk” button.

It must be taken into account that the tool included in Windows XP made it possible to see the state of the fragmentation of a disk graphically, identifying the fragmented files of red color.

So in this case you can use a small application on your computer called DiskView (500 KB), in order to examine the state of the units.

How to defragment disks using DEFRAG

So far it is known that Windows includes among its tools the application Defrag.exe, which is responsible for executing the defragmentation of files very efficiently.

However, Defrag.exe works only through the CMD console, using the DEFRAG command, besides, it has all the necessary options and if you prefer the effectiveness, performance, speed, instead of an interface full of colored squares, plus a free application of course, then we recommend you to defragment your disks using the DEFRAG command.

We can say that this is the most direct and effective way to perform this task, you even have the ability to use the tool by entering commands directly into the CMD console, automating it through a simple batch file that you can create or download a more complete one.

Now if you want to defragment a drive or disk from the command line you just have to perform the following steps:

  • First open the CMD console, for that type in the Start or Run box: CMD and press the Enter key.
  • Then type in the console:DEFRAG /U, press the spacebar (create a space).
  • Now open My Computer, select the unit to defragment, drag and drop it over the console window.
  • Finally press the Enter key, then wait for the process to finish and observe the tasks that are being executed.

There is also an elementary or basic method to defragment only a folder or directory using commands, all you have to do is follow the steps below:

  • Open the CMD console by typing in the Start or Run CMD box and pressing the Enter key.
  • Type in the console:CONTIG /S /V, press the space bar (create a space).
  • Now open My Computer, find the folder to defragment, select it, drag and drop it over the console window.
  • Press the Enter key.

What are the parameters to use in DEGRAG?

  • /A Perform analysis on specified volumes.
  • /C Perform the operation on all volumes.
  • /E Perform the operation on all volumes except those specified.
  • /R Partial defragmentation (default) consolidates only fragments smaller than 64 MB.
  • /Defragmentation with normal priority.
  • /W Total defragmentation consolidates all fragments regardless of size.
  • /F Forces defragmentation even with little free space (less than 15%).
  • /M Execute the operation on each parallel volume in the background.
  • /T Track an operation that is already in progress in the specified volume.
  • /Print the progress of the operation on the screen.
  • /Print detailed output, including fragmentation statistics.
  • /X Perform available space consolidation in specified volumes.

Unfortunately, one of the limitations of DEFRAG is that it does not allow defragmentation of open files for exclusive operating system access, such as paging files and registry files, which due to their fragmentation are one of the main causes of Windows performance loss.

So in order to be able to carry out this task it is necessary to use the small application PageDefrag (69 Kb) available for free in SysInternals.

To use PageDefrag download it, unzip it and run it, then you only have to check the box indicated to start the application at the next restart and press the OK button.

When you restart the system, the paging and registry files will be defragmented, so you can quickly see the appreciable performance improvement.

You may be interested:

Facebook Comments