Windows 7 tips and tweaks
Schedule Disk Cleanup using command line options
Share this page with your friends!
No matter how big hard disk drives grow, they never seem quite big enough to hold all the files. Even terrabyte drives can be filled these days with digital video, music and photos. Those are all valuable files of course, and they are essential. Not all files on the disk are important and as you use the computer junk files gradually eat up the disk space too. There are caches for web browsers, temporary files, backups and more. They all use up a little disk space and they contribute to the clutter on the disk drive and they can even slow Windows down in extreme cases.
Clearing out unwanted junk files makes room for more important ones and also enables Windows to work more efficiently. Disk Cleanup is a utility bundled with Windows that enables you to di just this. Everyone knows how to use Disk Cleanup of course, but do you really? There are several secret command line switches that enable you to use it in ways you probably never thought of.
Cleanmgr command line switches
Let's take a look at the command line switches. Click Start, All Programs, Accessories and then Command Prompt. At the command prompt, type
cleanmgr /? which is the real name of Disk Cleanup followed by a command line switch that requests help. A window pops up with the following message:
cleanmgr [/SAGESET:n | SAGERUN:n | TUNEUP:n /LOWDISK | /VERYLOWDISK /SETUP]
The square brackets mean that all these command line switches are optional. You can use any you like or none at all. Type
cleanmgr on its own and Disk Cleanup will run in the usual way, but add a command line switch and it modifies its behaviour.
cleanmgr /verylowdisk and a disk cleanup operation is performed, but the difference is that this time no options dialog is displayed. The utility just runs and does its job. Windows probably runs this automatically when you run out of disk space.
We can use this to create an icon on the desktop that removes all junk files and recovers lost disk space. Right click the desktop and select New, Shortcut. When it says Type the location of the item, enter
cleanmgr /verylowdisk. Click Next and enter a name for the shortcut, such as Junk Remover or something and click Finish. Try your new utility by double clicking the icon on the desktop.
So what's the difference between /verylowdisk and /lowdisk? The former just runs whereas the latter displays an options dialog so you can choose what you want to erase, such as temporary internet files, Recycle Bin and so on. The /tuneup command line switch is similar to /lowdisk and an options dialog is displayed, but with fewer items ticked. It's a bit like a quick cleanup.
Finally, /sageset:n and sagerun:n are interesting. If you type
cleanmgr /sageset:n where n is any number between 1 and 65535 then the Disk Cleanup options dialog is displayed, but it doesn't actually clean up. What it does is to save your settings and associate them with the number. You can save lots of different cleanup configurations by giving each one a different number like
cleanmgr /sageset:1 and
cleanmgr /sageset:2 and so on. To execute Disk Cleanup with a specific configuration, use
cleanmgr /sagerun:n where n is the number you want. For example,
cleanmgr /sagerun:5. All the settings are known to cleanmgr and this means that it doesn't display the options dialog. It just does them.
You could create shortcuts on the desktop for different cleanup operations, such as a quick cleanup, a thorough cleanup and so on. You chould even drag them to the Start menu and create new menus for them.
Schedule Disk Cleanup to run automatically
Now that we have explored the command line switches for cleanmgr, let's see how to schedule a disk cleanup task. Click Start, All Programs, Accessories, System Tools, Task Scheduler. Click Create Basic Task in the Actions panel on the right. Enter a name like My Disk Cleanup and click the Next button (a description is optional). You can then choose when to run it, such as daily, weekly, monthly and so on. Click Next and you get more options, such as the days of the week you want to run it. Set whatever schedule you want and click Next.
You'll be prompted to select an action and this should be to start a program. In the Program/Script box enter
cleanmgr /sagerun:1 or whatever settings you have stored. What you need to do is to choose a command line that does not stop and display the options dialog and this means running settings you've already saved with /sageset:n.
Go to Windows 7 tips index...