A source-cited reference library 399 modules · 19 subdomains · 5 domains
Research Library
Joël van der Loo
Photo: Joël van der Loo, CC BY-SA 4.0, via Wikimedia Commons

Cybersecurity / Defense and Hardening

Disk Cleanup (Cleanmgr)

CybersecurityDefense and Hardening848 words4 min readSource: learn.microsoft.com

cleanmgr is a command-line utility in Microsoft Windows operating systems designed to identify and remove unnecessary files from a computer's hard disk to free up storage space. It operates by scanning designated drives for file categories deemed non-essential, such as temporary internet files, downloaded program files, and items in the Recycle Bin, and provides options to automate cleanup tasks through scheduled execution.

How it works

The utility functions by analyzing file system locations associated with transient or redundant data. Upon invocation, cleanmgr evaluates specified drives for accumulations of files in predefined categories, including temporary setup files, temporary internet files, downloaded program files, old chkdsk fragments, recycle bin contents, temporary files, temporary offline files, offline files, compressible old files, and catalog files for the content indexer. Users can invoke interactive mode to manually select which file types to remove or employ command-line parameters to predefine cleanup actions. When executed with scheduling tools, cleanmgr performs automated scans and deletions based on stored configurations, enabling routine maintenance without user intervention. The process preserves user-specific settings, such as personalized web page configurations in temporary internet files, while removing the cached content itself.

Varieties or components

cleanmgr supports multiple operational modes defined by its command-line parameters. The /d parameter targets a specific drive for analysis, excluding use with /sagerun:n. The /sageset:n parameter launches the Disk Cleanup Settings dialog to configure cleanup preferences and stores these selections in the registry under an integer identifier n (ranging from 0 to 9999). The /sagerun:n parameter executes the cleanup tasks previously saved under identifier n across all system drives. The /tuneup:n parameter combines /sageset:n and /sagerun:n for the same n value, streamlining setup and execution. The /lowdisk parameter initiates cleanup with default settings, while /verylowdisk applies the same defaults without prompting for user confirmation. The /autoclean parameter removes residual files remaining after a Windows upgrade. The /? parameter outputs help text detailing syntax and usage. Each mode interacts with a consistent set of file category options accessible through the settings interface, which vary in availability depending on whether the targeted drive hosts the Windows installation.

Standards or algorithms that govern it

The behavior of cleanmgr is governed by predefined file categorization logic and registry-based persistence mechanisms. File identification relies on known system paths and attributes associated with transient data, such as files in the Temp folder unmodified for over one week, content in the Downloaded Program Files folder (including ActiveX controls and Java programs), and fragments retained by chkdsk in disk root folders. The compression of old files follows a threshold-based algorithm where files unused for a user-specified duration are marked for compression, though actual space savings are approximate due to variable compression ratios. Registry keys created via /sageset:n store user-selected cleanup profiles as binary values, enabling /sagerun:n to retrieve and apply these settings uniformly across all drives. The utility adheres to Windows file system access protocols, ensuring operations respect permissions and avoid deletion of active or system-critical files. No external standards or third-party algorithms are referenced in its operation; functionality is intrinsic to the Windows maintenance subsystem.

Where it fails or is limited

cleanmgr exhibits limitations in scope and functionality under certain conditions. When targeting a drive that does not contain the Windows installation, only the Recycle Bin and Catalog files for the Content Indexer options are available in the Disk Cleanup tab, restricting cleanup to these two categories regardless of user selection via /sageset:n. The utility does not provide granular control over individual file deletion within categories; for example, it removes all temporary internet files without distinguishing between benign and potentially useful cached content. The display of recoverable disk space from compressing old files is an estimate, as actual compression efficiency varies by file type and content, leading to potential discrepancies between reported and realized gains. cleanmgr lacks built-in logging or reporting features to document which files were removed or the exact space recovered per category. It cannot clean files locked by active processes, and its reliance on static file paths may miss transient data stored in non-standard or user-defined locations. Additionally, the tool does not assess or mitigate risks associated with deleting files that might be required for application rollback or troubleshooting, placing full responsibility for data integrity on the user or administrator. Finally, cleanmgr cannot operate on network drives or removable media unless explicitly mapped to a local drive letter, limiting its utility in distributed or external storage environments.

File Category Description Availability on Non-Windows Drives
Temporary Setup Files Files from completed setup programs Not available
Downloaded Program Files ActiveX controls and Java programs from web pages Not available
Temporary Internet Files Cached web pages for quick viewing Not available
Old Chkdsk Files Lost file fragments from disk error checks Not available
Recycle Bin Deleted files awaiting permanent removal Available
Temporary Files Program-generated temp data older than one week Not available
Temporary Offline Files Cached network files for offline use Not available
Offline Files User-selected network files for offline access Not available
Compress Old Files Infrequently used files marked for compression Not available
Catalog Files for Content Indexer Leftover indexing service files Available
Source

Adapted for this library from the original article at https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cleanmgr — see the publisher's site for the authoritative version. (retrieved October 2026).