How do I clear temporary files on Windows?
Use forfiles to preview old files, clear %TEMP% with PowerShell, and confirm space is back with Disk Cleanup.
What this covers
Temporary files pile up from installers, browsers, and apps. They are usually safe to remove, but files currently in use should be left alone. This sequence helps you check first, clean safely, and confirm the space came back.
Symptom
Preview old files in your temp folders
Before deleting anything, list what is actually old enough to remove. Point the tool at %TEMP% (run echo %TEMP% in Command Prompt to see the exact path) and set the age cutoff, for example 30 days. The echo action only prints matching paths, so nothing is deleted; if the list is empty, there is nothing safe to clear by age.
Windows' forgotten find -mtime equivalent — selects files by age and runs a command on each one.
$ forfiles /P "C:\Logs" /S /M *.log /D -30 /C "cmd /c echo @path"Clear %TEMP% with PowerShell
Close running apps and installers first, then empty the current user's temp folder from PowerShell. The command removes items recursively and skips locked files instead of failing the whole run. Success looks like the folder emptying quickly; any remaining files are usually in use and can be cleared after a reboot.
Empty %TEMP% safely from PowerShell to reclaim disk space and clear stale installer caches.
$ Remove-Item "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinueConfirm with Disk Cleanup
Run Disk Cleanup on the system drive, let it scan, and check the Temporary Files category. It should now report little or nothing, and you should see free space recovered. If Disk Cleanup still shows a large Temporary Files entry, some files were locked; reboot and repeat the PowerShell step.
Save a cleanup profile once, then run it unattended on any schedule.
$ cleanmgr /sageset:1How to confirm it worked
Run Disk Cleanup again: the Temporary Files category should be near zero and free disk space should have increased. No app should report missing temp data.
Sources
- Remove-Item (Microsoft.PowerShell.Management)Evidence: Documents -Recurse to delete folders with children, -Force for hidden/readonly items, and -ErrorAction SilentlyContinue behavior.
- Remove-Item — Delete files and foldersEvidence: Shows Remove-Item with -Recurse and -Force used to delete directory trees.
- cleanmgr - Windows CommandsEvidence: Documents cleanmgr /sageset:n to configure a saved cleanup profile and /sagerun:n to run it unattended.
- CleanMgr - Automated Cleanup of Temp FilesEvidence: Explains the sageset/sagerun workflow and the registry location where the cleanup profile is stored.
- FORFILES - Windows CMDEvidence: SS64 documents /D -30 as files last modified more than 30 days ago, and shows "cmd /c del @path" as the standard deletion pattern.
- forfiles | Microsoft LearnEvidence: Microsoft documents forfiles /D +/-n to select files with last-modified date older/newer than n days, /S for recursion, and /C to run a command per file with @path variables.
Last verified: 2026-09-22
Related guides
A file refuses to delete because another program holds it open. Confirm the lock, find the owner, close it, then remove the file for good.
Use PowerShell to group files by SHA256 and confirm identical copies before you delete anything.
Hidden files and folders are invisible by default in Windows Explorer. Fix it by toggling the Explorer registry values for Hidden and ShowSuperHidden.