SEARCH

How-To Geek

Dig Deeper in Windows Defrag via Command Prompt

Windows users have learned over the years that they need to keep their computers defragmented to keep running at top speed.  While Windows Vista and 7 automatically defrag your disks, here’s some ways you can dig deeper into Windows Defragmenter.

Windows Disk Defragmenter was turned into a very stripped down utility in Windows Vista and 7.  In fact, Vista’s Disk Defragmenter didn’t even let you select the disks to defragment until it was updated in Service Pack 1.  The good thing, though, is that both Vista and 7 automatically defrag your disks on schedule, so for the most part you don’t need to think about it.

Do note, however, that for the most part you’re not going to see massive performance jumps by defragmenting a disk.  Actually, upgrading to an SSD would be the best way to improve your disk performance, and by the way, Don’t run defrag on an SSD drive! SSD drives do not need to be defragmented, and you actually decrease your drive’s performance by defragging it.

Using the Disk Defragmenter App

If you do open the defragmenter app, you may be surprised to find how sparce it is.  It lets you analyze or defragment individual disks; hold your Ctrl key to select multiple disks and defragment your whole system at once.  You can also change the defragment schedule.  By default, most computers will be set to defrag at 1AM Wednesday mornings, but you can change this if you’d rather it defrag at a different time or if your computer’s never running then.

But that’s all you can do with the Defragmenter app.  To dig deeper, we need to head over to the command prompt.

Defraging from Command Prompt

The Windows defragment tool actually has tons of features, but you just can’t access them from the window interface.  To dig deeper, open command prompt in Administrative mode.

To use the defrag tool, just enter defrag followed by the parameters you want to use.  As usual, you can view the command’s help file by entering defrag /?.  Then to use defrag, just enter the following, like you would with many command apps.

defrag [name of your drive] [parameter] [extra parameters]

So, to simply defrag your drive, just enter defrag [drive name].  If your main drive is C:, then just enter defrag C: to defrag your main C drive.  There’s tons more you can do with the disk defragmenter, as you can see from the included help info.

So, with that in mind, let’s dive in and look at some of the most common parameters you might want to use:

See if you need to defrag

Not sure if your hard drive needs defragmented?  Just analyze your disk by entering

defrag [drive name] /A

As you can see below, we entered defrag C: /A to analyze our C drive.  After a few moments, you can see how large your drive is (Or partition if your hard drive is in multiple partitions), how much free space it has, the total fragmented space, and largest free space segment.  Underneath, the defrag tool will tell you if it thinks you need to defrag now or not.

Defragment all your drives at once

Would you like to just defragment all of your drives without getting extra info or doing a more complicated defrag?  If so, just enter defrag /C and let defrag take over.  Or, hey, you could just do this from the main defrag window since it works the exact same.

Other Nice Options

Get more info about the defrag: /V
Consolidate free space on a drive: /X
Defrag at normal process priority: /H
Track a defrag already in progress: /T
Defrag all drives except the one listed: /E
Defrag all drives at the same time: /M – note, this is only advisable if you have multiple drives, and will not work good on a computer with multiple partitions

You can put the options you need together, too.  Say you want to defrag all of your devices in verbose mode to see more info, and you also want the defrag to run at top priority.  To do this, we’ll enter:

defrag /C /H /V

Once it’s running, you’ll see the list of the options you’ve selected on the top of the command prompt window.  Remember to not close the window before the defrag is finished, as this will kill the process.

Now that you’ve got more control over defrag, you can hopefully get your disks running at top performance.  Or, even if you don’t want to tweak anything, just running defrag /C is much geekier than opening the Disk Defragmenter.  We recently asked readers if they use the command prompt; if you’re not in the habit of using it, here’s a good chance to get started!

Matthew digs up tasty bytes about Windows, Virtualization, and the cloud, and serves them up for all to enjoy!

  • Published 12/9/10

Comments (15)

  1. Jeff

    OMG!!! FIRST

  2. Jeff

    Haha. Just kidding. In all honesty, its a very well written article. I enjoyed it.

  3. MJ

    Great article, never thought of it, and is good to know that a “Consolidate” option exists!

  4. Edmenje

    It’s been a looooooong time since the last time I used cmd to defrag or format a drive. I think it was back when I was running Windows 95 (yeah…that long). Geek creds to those who still do it today.

  5. Den

    To get started, simply run from the administrator defrag c:-b / U
    This command physically sorts the files for faster loading of the system.

  6. clement

    I switched to a paid defragger once I changed to Vista. It has the graphics, defragged my drive when there was only about 6% free space and I no longer need to schedule the task or check if its done as it runs in the background without any issues.

  7. Bill

    I’ve been using the smart defrag from IO bit (free) for over a year now with no problems. I don’t know how it compares to win7′s defragger however as I’m only using it on XP and Vista machines.

  8. JIm

    I’m thinking about putting an SSD in my next computer. How can running defrag on an SSD cause its performance to decrease?

  9. Matthew Guay

    @Jim – There’s a couple reasons. One, SSD drives have a limited number of read/write cycles (Often 100,000 or so), and doing a disk defrag obviously eats up read/write cycles since it’s moving files around. Next, SSDs can access data at any spot on the drive just as quick as another, whereas on a traditional platter drive the head may have to move to find the data. So, keeping the data close together is better on a traditional platter drive, but has no benefit on a SSD.

    For more info, check out the Wikipedia article about SSD drives, as it’s rather informative – http://en.wikipedia.org/wiki/SSD

  10. Mike

    What I miss is the graphics…

    As time goes on the graphics screen GUI feedback is slowly being removed and the new defrag is an example. I liked the old graphics for defrag and it also helped me. I could get it going and as I walked by doing other things I could tell the status of the operation just by looking at the screen.

  11. Randy Fonner

    My sister has a hp laptop with Vista 32 and when i analyze the hard drive it says it is 46% fragmented.

    Most of the files and by far the largest are System Volume Information – which are connected to system restore points.

    running a defragger only improved from 49% to 46%

    I know i can decrease the size of the system volume information folder, but wonder if these fragmented files actually slow performance (as opposed to other file types)

    advice?

    Thanks.

  12. Jon

    Windows Vista and Windows 7 do automatic defragging. There’s really no need to even think about a defrag anymore let alone try to run one in a command prompt.

  13. Kushal

    Amazing article thanks I m learning Linux ubuntu does it has a defrgmenter ? Because the cmd is terminal in Linux they both r almost the same

  14. RogerJ

    I have a problem with Windows 7 which is very similar to Randy Fonner’s, though instead of his 49 – 46% it’s only – only – 24 – 23%. All in System Volume Information, which is huge.

    But when I run the Windows 7 Defragger it goes straight to ’93% Analysed’…and stops right there. No further analysis, no defrag at all. Piriform’s (bless them!) Defraggler runs, but also stops at 23%.

    And I haven’t yet found a way to do what I could do with XP, which was to clear all old Restore Points bar the last.

    Any words of wisdom on this would be gratefully received!

  15. Aleksandar_B

    @Kushal
    As far as I’m aware Linux doesn’t need defragmentation due to the way it’s file system (ext2/3/4) works, reducing fragmentation.

    @RogerJ
    Try using Disc Cleanup to delete old Restore Points.

Enter Your Email Here to Get Access for Free:

Go check your email!