May 4, 2009 9:00 AM PDT

Defrag Windows from the Command Prompt

by Dennis O'Reilly
  • Font size
  • Print
  • 2 comments

If it were up to me, I'd never defragment my PC's drives. I'm one of those people who prefers to have Windows' maintenance operations done in the background, without my direct intervention.

So it comes as no surprise that I'm a big fan of Vista's automatic-defrag setting. But I also know better than to put all my faith in Microsoft's ability to keep my system healthy. Last year, I started using Auslogics' free Disk Defrag utility, which works with Windows 2000 and up.

If you prefer to use Windows' defragger, you can open it by pressing the Windows key (or Ctrl-Esc), pressing R (in XP), typing defrag in Vista or dfrg.msc in XP, and pressing Enter. The interface of Vista's Disk Defragmenter is nonexistent; the utility is clearly designed for behind-the-scenes operation. Your only options are to set the defrag schedule, select the volumes to defrag, and run the defragger.

Windows Vista Disk Defragmenter utility

Vista's Disk Defragmenter utility is a no-frills affair.

(Credit: Microsoft)

XP's version of the Disk Defragmenter isn't much more functional, although it does give you a little more graphical feedback about the state of your drives.

You get more control over your disk defrags by running Windows' defragger utility from a command prompt and entering command switches that modify its actions. Start by opening a command-prompt window. One way is by pressing the Windows key (or Ctrl-Esc), pressing R (in XP), typing cmd, and pressing Enter. Or click Start > All Programs > Accessories, right-click Command Prompt, and select Run as administrator.

At the command prompt, type defrag ? to see a list of available command switches. In both XP and Vista, you can add -a to the "defrag" command to analyze the drive only, -f to force a defrag with less than 15 percent free space, -b to defrag only boot files, and -v to show a "verbose" report of the defrag.

Vista adds a couple of other switches: -i defrags even when the PC isn't idle, -c works on all drives, and -w processes chunks of files smaller than 64MB; without this switch, Vista's defragger ignores all file fragments smaller than 64MB.

Defrag command switches

Type defrag ? at a command prompt and press Enter to see a list of available command switches.

(Credit: Microsoft)

For example, to defrag all your Vista volumes regardless of fragment size and when there's less than 15 percent free space, enter this line at the command prompt and then press Enter:

defrag -c -w -f

The utility will display a report on the selected volumes prior to beginning the defragmentation.

Windows Disk Defragmenter report

Windows defrag utility will show a report on the selected volumes prior to defragmenting the drives.

(Credit: Microsoft)

Unfortunately, defrags run from a command prompt aren't any faster than those conducted via the graphical interface. That's the biggest advantage of specialty defrag programs such as Auslogics' Disk Defrag, which is much speedier than the defragger in Windows.

The fact is, Vista's automated defrags were doing a great job of keeping my disk space nice and compact. I didn't notice much of a performance improvement after I manually defragged my Vista PC, but the defrag did wonders for my ancient XP box, which I admit I had neglected to defrag for many months.

The other day, I was talking to a guy who wanted a PC but didn't want Vista. He asked me how long he would have to wait for new PCs running Windows 7. When I told him that such systems were still several months away, he indicated that he'd buy a machine from a company that let you "downgrade" Vista to XP.

I didn't say anything, but part of me thought he was crazy. I'll take Vista over XP any day of the week. Not having to run a disk-defrag utility is only one of the reasons why. (Yes, I know you can automate disk defrags in XP via Scheduled Tasks, as Microsoft explains in this Knowledge Base article, but doing so is too much hassle for the average Windows user.)

Dennis O'Reilly has covered PCs and other technologies in print and online since 1985. Along with more than a decade as editor for Ziff-Davis's Computer Select, Dennis edited PC World's award-winning Here's How section for more than seven years. He is a member of the CNET blog Network, and is not an employee of CNET.
Recent posts from Workers' Edge
Time to update the software user's bill of rights
Put Task Manager in Windows' notification area
Windows diagnostic tool big on info, short on help
Three more ways to slice and dice the Web
Firefox note-taking add-ons are Web supersavers
The best of Windows 7's new interface features
Four ways to reduce your PC's carbon footprint
Five tips for safe Web shopping
Add a Comment (Log in or register)
by SerengetiValley May 4, 2009 11:04 AM PDT
Just install Diskeeper 2009 on the machine, turn on DK's automatic defrag feature, and be done with it. never need to worry about fragmentation again. I run 3 XP machines currently, including a heavily used desktop with 5x500GB drives, and I've never had to defrag in months...Diskeeper's auto defrag feature keeps the drives in perfect condition.

I suppose 7 will see some improvements on the automatic maintenance front, but until then, we are stuck with an ageing XP and slightly bloated Vista.
Reply to this comment
by Tangmeister May 6, 2009 6:04 PM PDT
There is another Command-line switch that is completely undocumented in the default XP defragger.

This is the -b switch, which tells Windows to defrag your prefetch and boot files, like BootVis once did, until MS killed it.

For example:

defrag c: -b

This won't work if c: isn't your system drive, and d: won't if c: is your system drive.

Also, I think defragging is a good thing.
Reply to this comment
advertisement

15 sites that went kaput in 2009

Web sites launch all the time, but they also shut their doors. We highlight 15 that bit the dust this year.

Top 10 news stories of the decade

Let the debate begin: Was the iPhone more important than iTunes? Was anything bigger than Google finding a great business model? CNET offers its list of the 10 most important stories of the '00s.

About Workers' Edge

Dennis O'Reilly has covered PCs and other technologies in print and online since 1985. Along with more than a decade as editor for Ziff-Davis's Computer Select, Dennis edited PC World's award-winning Here's How section for more than seven years. He is a member of the CNET Blog Network and is not an employee of CNET.

Add this feed to your online news reader

Workers' Edge topics

advertisement
advertisement

Inside CNET News

Scroll Left Scroll Right