Remove-Item
Delete a file or folder
Remove-Item -Path .\temp\old.log
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Remove-Item
Careful: There is no recycle bin. Deleted is gone. Use -WhatIf.
- PowerShell 7 On Linux and macOS, rm runs the system command instead of this cmdlet. Type the full cmdlet name there.
Deletes files or folders. Folders with contents need -Recurse. Some hosts also ask for -Force.
Try this
Remove-Item -Path .\temp\* -WhatIf
Coming from another shell
| Shell | What you might type |
|---|---|
| bash / zsh | rm -rf temp/ |
| cmd.exe | rmdir /s /q temp |
Remove -WhatIf only when the preview looks right.
More in From bash and From cmd.