CleanMgr - CMD


Overview

CleanMgr (Disk Cleanup) is a utility in Windows that helps users free up disk space on their computer’s hard drive by deleting unnecessary files like temporary files, system files, and emptying the Recycle Bin. It is particularly useful for maintaining system efficiency and is often used prior to creating system backups or performing system upgrades.

Syntax

The basic syntax for CleanMgr is as follows:

cleanmgr [/d drive_letter] [/sagerun:n | /sageset:n | /tuneup:n] [/lowdisk] [/verylowdisk] [/setup]
  • /d drive_letter: Specifies the drive on which to run Disk Cleanup.
  • /sagerun:n: Executes the cleanup configurations set by /sageset:n.
  • /sageset:n: Displays the Disk Cleanup Settings dialog box and creates a registry key to store the settings with the chosen number n.
  • /tuneup:n: Used in some versions of Windows to perform similar operations to /sagerun.
  • /lowdisk: Runs Disk Cleanup in a mode tailored for low disk space.
  • /verylowdisk: Runs a more aggressive cleanup suitable for very low disk space scenarios.
  • /setup: Cleans up setup logs and temporary files left from Windows installation processes.

Options/Flags

  • /d: This option lets you select the specific drive you want to clean, which is useful in systems with multiple partitions.
  • /sagerun:n: This flag allows the user to execute previously saved configurations, making repetitive tasks more manageable.
  • /sageset:n: It’s useful for setting up a specific cleaning routine that you can reuse.
  • /lowdisk and /verylowdisk: These are specifically designed to be used when disk space is low, with /verylowdisk providing a deeper clean.
  • /setup: This is mainly used post-system upgrade or installation to clean up residual setup files.

Examples

  1. Basic Usage:
    Run Disk Cleanup for drive C:

    cleanmgr /d c
    
  2. Configure and Run Custom Cleanup:
    First, configure the cleanup settings and store them with ID 50:

    cleanmgr /sageset:50
    

    Later, run Disk Cleanup with the saved settings:

    cleanmgr /sagerun:50
    
  3. Aggressive Cleanup:
    Run an aggressive cleanup for when the disk space is extremely low:

    cleanmgr /verylowdisk
    

Common Issues

  • Access Denied: Users sometimes encounter permission issues. Running the command prompt as an administrator can resolve these issues.
  • Unknown Flags: Using outdated or incorrect flags results in errors. Ensure you’re using the correct options as per your Windows version.

Integration

CleanMgr can be integrated with other commands in a batch script to automate cleaning and maintenance:

@echo off
cleanmgr /d c /sagerun:1
shutdown /r /t 00

This script configures Disk Cleanup and then restarts the computer immediately after the cleanup completes.

  • Defrag: Optimizes file layout on disks.
  • chkdsk: Checks the file system and disk surface for physical errors.

For additional resources, consult the official Microsoft documentation via their website or the built-in Windows Help system.