04/01/2026
Software
DevOps
Making C:\tmp Behave Like Linux /tmp on Windows
One Linux feature I really like is having a /tmp folder where I can throw temporary files and let them get cleared automatically later. To get something similar on Windows, I use a C:\tmp folder and clear it on startup.
ClearTmp.ps1
$TempPath = "C:\tmp"
if (Test-Path $TempPath) { Remove-Item "$TempPath\*" -Recurse -Force -ErrorAction SilentlyContinue }
Script is available here.
Run on startup (Startup folder)
For most personal setups, this is enough.
- Create
C:\tmp. - Save the script as
C:\scripts\ClearTmp.ps1(or use the one linked above). - Press
Win + R, typeshell:startup, and press Enter. - In that folder, right-click ->
New->Shortcut. - For Type the location of the item, paste:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\scripts\ClearTmp.ps1"
- Name it something like
Clear tmp on startupand finish. - Restart (or sign out/in) and verify
C:\tmpgets cleared.
Another way: Task Scheduler
If you want more control over startup behavior, this is another good option.
- Create
C:\tmp. - Save the script as
C:\scripts\ClearTmp.ps1(or use the one linked above). - Open Task Scheduler -> Create Task.
- Trigger:
At startup. - Action:
Start a program.- Program/script:
powershell.exe - Add arguments:
- Program/script:
-NoProfile -ExecutionPolicy Bypass -File "C:\scripts\ClearTmp.ps1"
That gives me a simple scratch directory on Windows that behaves a lot more like Linux /tmp.