How to Delete Junk Files in Windows 10 Using CMD

To delete junk files in Windows 10 with Command Prompt, open Command Prompt as administrator and run del /q /f /s %TEMP%\* to empty your temporary folder. For a fuller cleanup, run cleanmgr /sageset:1 once to choose what to clean, then cleanmgr /sagerun:1 whenever you want to clean it. Files in use are skipped, which is normal.

These commands delete files without sending them to the Recycle Bin, so type them exactly as shown and don’t point them at other folders.

Note: Windows 10 reached end of support on October 14, 2025. Consumer Extended Security Updates (ESU) now run until October 12, 2027. The same commands work on Windows 11.

Quick Answer

Open Command Prompt as administrator, type del /q /f /s %TEMP%\*, and press Enter.

Step 1: Open Command Prompt as Administrator

  1. Select Start and type cmd.
  2. Right-click Command Prompt and choose Run as administrator.
  3. Select Yes on the User Account Control prompt.

Step 2: Delete Your Temp Files

  1. Close other apps so fewer files are in use.
  2. Type del /q /f /s %TEMP%\* and press Enter.
  3. Windows lists each deleted file. Messages saying a file is in use can be ignored.
  4. To also remove empty subfolders, run for /d %i in ("%TEMP%\*") do rd /s /q "%i".
Command Prompt running a command that deletes temporary files and listing the deleted files
The del command lists each file it removes. Files that are in use are skipped.

What the switches mean

Switch Meaning
/q Quiet: don’t ask to confirm
/f Force-delete read-only files
/s Include subfolders

Step 3: Clean the Windows Temp Folder

Run del /q /f /s C:\Windows\Temp\* in the same administrator window. Some files will be in use and skipped.

Step 4: Run Disk Cleanup From the Command Line

  1. Type cleanmgr /sageset:1 and press Enter.
  2. Check the categories you want, such as Temporary files, Windows Update Cleanup, and Delivery Optimization Files, and select OK.
  3. Run cleanmgr /sagerun:1 to clean them now and any time later.

Step 5: Remove Old Update Components (Optional)

Run DISM /Online /Cleanup-Image /StartComponentCleanup to remove superseded Windows update files. It can take several minutes. Afterward, you can’t uninstall older updates.

What Not to Delete

  • Don’t run del on the C:\Windows folder itself, System32, or Program Files. Only the Temp folders are safe to empty.
  • Don’t delete the SoftwareDistribution folder while updates are installing. If you need to reset it, follow our guide to clearing the Windows Update cache.
  • Don’t delete Prefetch files to “speed up” the PC; Windows rebuilds them and startup may briefly slow down.

Prefer a guided approach for update files? Our walkthrough on removing old Windows updates explains what each option deletes.

Troubleshooting

  • “Access is denied”: You’re not in an administrator window, or the file is in use. Restart and try again.
  • “The system cannot find the path specified”: Check for typos, especially the backslash before the asterisk.
  • Want a point-and-click method? See how to clear temp files from Settings; the steps are nearly the same on Windows 10.

New to the command line? Here’s how to open a folder in Command Prompt.

Frequently Asked Questions

Is it safe to delete everything in %TEMP%?

Yes. Files that apps still need are in use and won’t be deleted.

Can I automate this?

Save the commands in a .bat file and run it with Task Scheduler, or turn on Storage Sense in Settings.

Summary

  1. Open Command Prompt as administrator.
  2. Run del /q /f /s %TEMP%\*.
  3. Use cleanmgr /sageset:1 and /sagerun:1 for a full cleanup.
  4. Stay away from system folders.