Home life · Updated
How to Clean PC with CMD: Step-by-Step Guide
Quick answer You can use Command Prompt to run built-in Windows tools that clear temporary files, check disk health, and manage system cleanup—no extra software needed.
Cleaning your PC with Command Prompt (CMD) is a free, built-in way to remove junk files, fix disk errors, and free up space. It’s not a magic one-click fix, but it does let you run several maintenance tasks that Windows provides. You’ll need to open CMD as an administrator for most of these commands. Here’s how to do it safely and effectively.
What You’ll Need
- A Windows PC (Windows 10 or 11 works best)
- Administrator access to your computer
- A few minutes of patience—some commands take time to finish
Step-by-Step
- Open Command Prompt as Administrator – Press the Windows key, type
cmd, right-click on “Command Prompt” and choose “Run as administrator.” If prompted by User Account Control, click “Yes.” - Run Disk Cleanup (Cleanmgr) – Type
cleanmgrand press Enter. Select the drive you want to clean (usually C:). Check the boxes for files you want to delete (like Temporary files, Recycle Bin, and Thumbnails) and click OK. To get more options, runcleanmgr /sageset:1first, thencleanmgr /sagerun:1to execute with all options checked. - Delete Temporary Files Manually – Type
del /q /f /s %temp%\*and press Enter. This removes files in your user temp folder. You can also rundel /q /f /s C:\Windows\Temp\*to clear system temp files (be careful—some may be in use). - Check Disk for Errors (Chkdsk) – Type
chkdsk C: /fand press Enter. If the drive is in use, you’ll be asked to schedule it for next restart. TypeYand restart your PC to let it run. This scans for file system errors and bad sectors. - Run System File Checker (SFC) – Type
sfc /scannowand press Enter. This checks and repairs corrupted Windows system files. It can take 10-20 minutes, so let it finish. - Optimize Drives (Defrag) – Type
defrag C: /Oand press Enter. This optimizes your drive (defragmentation for HDDs, TRIM for SSDs). Only run this on traditional hard drives; SSDs are already optimized automatically, but this command is safe.
Common Mistakes
- Running without admin rights – Many commands (like chkdsk and sfc) need administrator privileges. If you get “Access denied,” close and reopen CMD as admin.
- Deleting files that are in use – The
delcommand may skip files that are locked by running programs. That’s normal; don’t force it. - Using chkdsk on an SSD unnecessarily – While not harmful, chkdsk is mainly for traditional hard drives. SSDs don’t need frequent scans; use it only if you suspect issues.
- Interrupting sfc /scannow – Let it run to completion. Closing the window mid-scan can leave your system in an inconsistent state.
Tips
- Use the /quiet switch for cleanmgr –
cleanmgr /verylowdiskruns cleanup with minimal prompts, handy for quick cleanups. - Combine commands with && – You can run multiple commands in one line, like
cleanmgr /sagerun:1 && chkdsk C: /f, but be careful—some need a restart. - Check disk space before and after – Use
dir C:\orfsutil volume diskfree C:to see how much space you’ve freed. - Run these regularly – Once a month is a good habit to keep your PC tidy.
Troubleshooting
- “Access denied” errors – Make sure you’re running CMD as administrator. Right-click and select “Run as administrator” every time.
- Cleanmgr doesn’t show many options – If you’re not seeing “Clean up system files,” click that button to get more categories. Some options only appear after you do that.
- Chkdsk says the volume is in use – This is normal. Type
Yand restart your PC. The scan will run before Windows fully loads. - SFC finds errors but can’t fix them – Try running
DISM /Online /Cleanup-Image /RestoreHealthfirst, then runsfc /scannowagain. DISM repairs the system image that SFC relies on. - Defrag says “Optimization is not available” – This can happen on SSDs if TRIM isn’t supported. It’s not a problem; your drive is likely already fine.
Frequently Asked Questions
Is it safe to delete temp files with CMD?
Yes, temporary files are safe to delete. They’re meant to be temporary, and Windows will recreate them as needed. Just make sure you’re not deleting files that are currently in use—CMD will skip those.
Will chkdsk damage my SSD?
No, chkdsk won’t damage an SSD, but it’s not necessary. SSDs don’t have moving parts, so they don’t need the same error checking as hard drives. Use it sparingly on SSDs.
How long does sfc /scannow take?
It typically takes 15-20 minutes, but it can be longer on slower systems. Let it run without interruption.
Can I use CMD to clean my PC without admin rights?
Some commands like del %temp% might work without admin, but most cleanup tasks (like cleanmgr or chkdsk) require admin privileges. You’ll need to be an administrator.
What’s the difference between cleanmgr and del temp?
Cleanmgr is the official Disk Cleanup tool that removes various system files safely. del manually deletes files from specific folders. Cleanmgr is safer because it filters out files that shouldn’t be removed.
Do I need to restart after running these commands?
Only if you scheduled chkdsk or if the system asks you to. Most commands take effect immediately. Restarting after a cleanup is a good idea to clear memory and finalize changes.
Related
Sources: Microsoft Support. Menus and buttons can differ slightly by version. Spotted something out of date? Tell us.