Automated cleanup of Temporary files, Internet files, downloaded files, recycle bin.
Syntax CLEANMGR [/d drive] /LOWDISK CLEANMGR [/d drive] /VERYLOWDISK CLEANMGR [/d drive] /SETUP CLEANMGR [/d drive] /Autoclean CLEANMGR [/d drive] /sageset:n CLEANMGR [/d drive] /sagerun:n Key /D drive The drive that you want Disk Cleanup to clean. NOTE: The /d option is not utilized with /SAGERUN:n. Specify the %systemroot% drive to see all the available options. /LOWDISK Disk Cleanup will open with all options checked. Normally invoked when Windows notifies that of disk space is running out. /VERYLOWDISK Disk Cleanup will open with all options checked, no user prompts. /SAGESET:n Display the Disk Cleanup Settings dialog box and create a registry key to store the settings you select. REQUIRES ELEVATION The n value is stored in the registry and allows you to specify different tasks for Disk Cleanup to run. n can be any integer from 0 to 9999. /SAGERUN:n Run task 'n' All drives in the computer will be enumerated, and the selected profile will be run against each drive. /TUNEUP:n Run /sageset and /sagerun for the same n /SETUP Analyze the system files left over from a previous Windows version. [Undocumented] /Autoclean Analyze the system files left over from a previous Windows version/in-place upgrade. and also remove those files automatically. [Undocumented] /HELP Display help /USAGE Display help /? Display help
If CLEANMGR is run without /sageset or /sagerun, it will start by calculating how much disk space could be saved. This makes the process slower to startup.
Although many of these files are often described as "junk" you should carefully evaluate what they do before deleting them. By default only the Downloaded Program Files and Temporary Internet Files will be selected.
Having a hard drive that is over 75% - 80% full will affect performance because file fragmentation (and automatic defragmentation) will increase. Also assuming you have the default 'system managed size' for the page file, that will automatically shrink to fit in the available space. For a drive that has more than 25% free space, deleting files will not make any difference to performance.
Some cleanup options require elevation, when run without elevation the GUI will include an option [Clean up System Files] which will relaunch CLEANMGR in Elevated mode. When necessary CLEANMGR can take ownership of the files before deleting them.
To enable Cleanmgr on older servers of Windows Server, open Server Manager and choose Add feature, then select "Desktop Experience"
After running cleanmgr on a server you may want to disable
"Desktop Experience" again.
The following options can be toggled on or off when running /SAGESET:n
Branch Cache
Catalog Files for the Content Indexer
Compress Old Files
Delivery Optimization Files
Diagnostic data viewer database files
DirectX Shader cache
Downloads (Personal downloads folder)
Downloaded Program Files *
Language resources Files
Offline Files
Old Chkdsk Files
Recycle Bin * (empties the recycle bin to recover the disc space)
Retail Demo Offline Content
Setup Log files
System Error memory dump files
System Error minidump files
Temporary Files
Temporary Internet Files *
Temporary Setup Files
Temporary Offline Files
Thumbnails
Update package Backup Files
User file history
Windows Defender Antivirus
Windows error reports and feedback diagnostics
Windows Update Cleanup
Windows Upgrade log filesItems marked with * have a [View Files] option in the GUI to view the individual files.
The Recycle Bin and Catalog Files for the Content Indexer may appear for more than one drive.
The user’s 'Application Data' folder is not available for cleanup in the above list. Many files in Application Data hold system data that should not be deleted. However if you have an application that leaves a significant number of temporary/junk files in App Data, these can be selectively removed from a profile by writing a custom batch script.
The 'User Profile/Recent Items' folder can contain many more shortcuts than are useful. A very large number of these can affect logon/logoff times. To clear out the shortcuts:
CD %userprofile%\AppData\Roaming\Microsoft\Windows\Recent
Echo y| del *.*
Save the following batch script:
@Echo off
Taskkill /f /im Explorer.exe
Start Explorer.exe
Exit
Then to restart Windows Explorer, just run the batch file.
Registry settings for CLEANMGR are held in:
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches]Here are a set of registry entries to turn on a typical selection of cleanmgr options, these can be used with REG or Regedit to pre-populate the regisitry as a scriptable alternative to running /SAGESET
Log files for CLEANMGR are stored in:
C:\Windows\System32\LogFiles\setupcln\
Choose a set of options for cleanup (this will display the GUI) and Save as settings group #64:
CLEANMGR /sageset:64
Run the saved settings group #64
CLEANMGR /sagerun:64
To run Disk Cleanup this way regularly, you can create a shortcut which can be run from the Windows Startup folder or via a regular schedule. To run the saved settings group #64
%systemroot%\system32\cmd.exe /c CLEANMGR /sagerun:64
”Mrs. Joe was a very clean housekeeper, but had an exquisite art of making her cleanliness more uncomfortable and unacceptable than dirt itself“ ~ Charles Dickens
DELPROF - Delete user profiles and/or User Profile cache.
DEFRAG - Defragment hard drive.
Q253597 - Automating Disk Cleanup in Windows.
Equivalent bash command (Linux):watch - Execute/display a program periodically.