Running Disk Cleanup from the command line in Windows 11 lets you free up disk space efficiently without opening the GUI, especially useful for automation or remote management. It works by deleting temporary files, system cache, old updates, and other non-essential data—similar to the graphical tool, but with more control via switches. You need administrative privileges and a basic understanding of Command Prompt or PowerShell commands.
What You'll Need
- An administrator account on the Windows 11 device
- Access to Command Prompt or PowerShell (run as Administrator)
- At least 1–2 GB of free space on the target drive (recommended for safe operation)
Step-by-Step
- Open Command Prompt or PowerShell with administrative rights. Press Windows + S, type cmd or PowerShell, right-click the top result, and choose Run as administrator. If prompted by UAC, click Yes.
- Type the following command to list available cleanup types for a specific drive (replace
Cwith your target drive letter if needed), then press Enter:cleanmgr /sageset:C
This opens the Disk Cleanup Settings dialog for drive C: (even in command-line mode, a UI appears once). Check the boxes for the categories you want to clean—such as Temporary files, Recycle Bin, Downloaded program files, and Windows Update Cleanup. Click OK. This saves your selections as a one-time configuration. - Now run the actual cleanup using the saved settings. In the same elevated window, type:
cleanmgr /sagerun:C
Press Enter. The Disk Cleanup process begins silently in the background, using the options you saved in step 2. Wait for it to finish (you’ll see progress in the command window, and the window closes automatically when done). - Verify the cleanup. Open File Explorer, right-click the drive (e.g., C:), choose Properties, and compare the Used space value to what it was before. Alternatively, re-run
cleanmgr /sageset:Cand check if the checked items now show 0 MB or a much lower value.
Common Mistakes
- Running the command without admin rights—this causes the process to fail with access denied or no output. Always launch Command Prompt or PowerShell as administrator.
- Skipping step 2 and jumping straight to
/sagerunwithout first setting cleanup options—this results in no files being deleted because no categories were selected. - Using the wrong drive letter (e.g., typing
/sagerun:Dwhen you saved settings for C:). Always match the letter between/sagesetand/sagerun. - Assuming
cleanmgr /sagerunworks without prior/sageset—the command is designed to use a saved configuration, not to accept inline arguments for categories. - Running the command while critical system files are in use (e.g., during a large update). If files are locked, Disk Cleanup skips them silently. Restart your PC and retry if needed.
Tips
- To clean multiple drives, repeat steps 2 and 3 separately for each (e.g.,
/sageset:Dthen/sagerun:D). - For deeper cleanup, enable additional system files first: after
cleanmgr /sageset:Copens, click Clean up system files at the bottom of the dialog. This reveals options like Previous Windows installations and Temporary user files, which can free several gigabytes. - Automate recurring cleanups by creating a batch file. For example, save the following as
cleanup.bat(run as admin):@echo off cleanmgr /sageset:C cleanmgr /sagerun:C
You can schedule it via Task Scheduler for monthly runs. - Check available disk space first with:
wmic logicaldisk where "DeviceID='C:'" get FreeSpace,Size
This helps set realistic expectations.
Troubleshooting
If Disk Cleanup doesn’t delete files or seems stuck:
- Ensure no other programs are using heavy disk resources. Close browsers, downloads, or backup tools, then retry.
- Run System File Checker to repair corrupted system files that may block cleanup:
sfc /scannow
Wait for completion (20–30 minutes), then retrycleanmgr /sagerun:C. - If
cleanmgrreturns ‘The system cannot execute the specified program’, the Disk Cleanup tool may be missing or corrupted. Re-register it by running this in an elevated PowerShell:regsvr32 /i shdocvw.dll
Then try again. - For persistent issues with system files (e.g., old updates not clearing), use DISM to repair the Windows image:
DISM /Online /Cleanup-Image /RestoreHealth
Let it finish (requires internet), restart, and runcleanmgragain. - If you see Access Denied errors, verify your user account has full control over
C:\Windows\System32\cleanmgr.exeand the target drive. Right-click the drive > Properties > Security > Edit, and ensure your account has Full control.
Frequently Asked Questions
Does cleanmgr /sagerun delete personal files?
No—by default, it only deletes system-generated content like temporary files, caches, and update leftovers. It never touches your Documents, Photos, or Downloads unless you explicitly select Downloaded program files or similar categories that reference user-downloaded installers (not user data).
Can I specify cleanup categories directly in the command line?
Not natively. Windows does not support inline category selection like cleanmgr /sagerun:C /temp. You must use /sageset once to choose categories, then reuse /sagerun with the same drive letter. Third-party tools or PowerShell scripts can simulate this, but they are not built-in.
Does this work on Windows 11 Home edition?
Yes. Disk Cleanup is included in all Windows 11 editions (Home, Pro, Enterprise). The command-line method is identical across editions, though some advanced options (like Previous Windows installations) may not appear if you’re using a Home edition on a device that never ran a major upgrade (e.g., from Windows 10).
How long does a command-line Disk Cleanup take?
Typically 1–5 minutes for standard cleanup (temporary files, recycle bin). If you selected Windows Update Cleanup or Previous Windows installations, it can take 15–60 minutes depending on how much data is present. The command window shows no progress bar—just wait for it to close automatically.
Is there a way to preview what will be deleted before running?
Yes. After cleanmgr /sageset:C opens the dialog, check the boxes for the categories you want, then click OK—this does not delete anything yet. To preview, run cleanmgr /sagerun:C, but watch carefully: the first few seconds show a brief list of categories and estimated space in the command window before cleanup starts. Alternatively, use the GUI (search for Disk Cleanup), which always shows a preview before deletion.
Can I clean multiple drives in one command?
No. Each /sageset and /sagerun pair applies to a single drive letter. To clean D: and E:, run cleanmgr /sageset:D, select options, then cleanmgr /sagerun:D, and repeat for E:. You can chain commands in a batch file, but each must be separate.