Skip to content
shellmap

remove-itemPowerShell's delete cmdlet — the rm / rmdir / del equivalent across all 5 shells

Equivalents in every shell

Bashunix
rm file.txt

Deletes a file. `rm -r dir/` deletes a directory recursively; `rm -rf dir/` skips per-file confirmation (also masks errors from missing paths). `rm` has NO confirmation by default — there is no trash / undo unless you alias to `rm -i` or install `trash-cli`.

Zshunix
rm file.txt

Same external. On macOS, files removed by `rm` do NOT go to the Finder Trash — they are unlinked immediately and unrecoverable without backups. Use Finder's `Move to Trash` or `brew install trash` for recoverable deletes.

Fishunix
rm file.txt

Same external. Fish does NOT ship `rm -i` aliasing by default — accidental `rm dir/*` is just as destructive as in bash. For undo-able deletes install `trash-cli` and either alias `rm` to `trash` or use `trash` directly in muscle memory.

PowerShellwindows
Remove-Item file.txt

PowerShell-native cmdlet (aliases `rm`, `del`, `erase`, `ri`, `rd`, `rmdir`). For directories add `-Recurse -Force` — without `-Recurse` PowerShell PROMPTS before a recursive delete (different from Unix `rm` which silently refuses). `-LiteralPath` treats `[ ] *` as literal characters (PowerShell's wildcards otherwise interpret them).

cmd.exewindows
del file.txt

Built-in. `del` removes files only; `rmdir` (alias `rd`) removes directories with `rmdir /s /q dir` for recursive force. cmd splits files vs dirs across two binaries; PowerShell's `Remove-Item` unifies them under one cmdlet with `-Recurse` doing the dir-tree walk.

Worked examples

Delete a file

Bash
rm file.txt
PowerShell
Remove-Item file.txt
cmd.exe
del file.txt

Delete a directory recursively without prompts

Bash
rm -rf dir/
PowerShell
Remove-Item -Recurse -Force dir/
cmd.exe
rmdir /s /q dir

Delete all .log files older than 7 days

Bash
find . -name '*.log' -mtime +7 -delete
PowerShell
Get-ChildItem *.log | Where-Object LastWriteTime -lt (Get-Date).AddDays(-7) | Remove-Item
cmd.exe
forfiles /m *.log /d -7 /c "cmd /c del @file"

Gotchas

  • `Remove-Item -Recurse -Force` STILL prompts for some protected paths — `C:\Windows\Installer`, OneDrive-synced folders, and items with the ReadOnly attribute may need `-Confirm:$false` AND `-Force` together. Wrap destructive scripts in `$ConfirmPreference = 'None'` only after dry-running the same command with `-WhatIf`.
  • PowerShell `Remove-Item *` skips HIDDEN files by default — the OPPOSITE of Unix `rm -rf *` which removes hidden ones too. To match Unix semantics use `Remove-Item * -Force` (and `-Recurse` for dirs) OR `Get-ChildItem -Force | Remove-Item` to enumerate everything. This is the single biggest cleanup-script footgun for Unix transplants moving to PowerShell.
  • `-LiteralPath` is essential for paths containing `[ ] *` (PowerShell wildcards). `Remove-Item 'C:\My [Old] Folder'` SILENTLY DELETES NOTHING because the wildcard parser sees `[Old]` as a character class with no match — use `Remove-Item -LiteralPath 'C:\My [Old] Folder'`. Paths from `Get-ChildItem` arrive as objects that handle this automatically; literal strings do not.
  • PowerShell aliases `rm` to `Remove-Item`, but on pwsh Linux/macOS the alias is REMOVED so the real `/bin/rm` resolves. Scripts must spell `Remove-Item` (or use the cmdlet's actual flags) to behave identically on both platforms — `rm -rf` on Windows pwsh calls the cmdlet which doesn't understand `-rf` and errors out.
  • `Remove-Item` does NOT send files to the Recycle Bin — items are permanently unlinked. To send to Recycle Bin from PowerShell use `Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile($path, 'OnlyErrorDialogs', 'SendToRecycleBin')` after `Add-Type -AssemblyName Microsoft.VisualBasic`, or install the `Recycle` module from the PowerShell Gallery.

WSL & PowerShell Core notes

pwsh`Remove-Item` works the same on every pwsh — one twist: the `rm`, `del`, `erase`, `rd`, `rmdir` aliases are present on Windows pwsh but REMOVED on Linux / macOS pwsh so the system binaries resolve. Cross-platform scripts should use the full cmdlet name `Remove-Item` to be unambiguous, regardless of which platform they happen to be developed on.
WSLInside WSL, `rm /mnt/c/path` deletes through the DrvFs adapter — slower than native, and the file does NOT go to the Windows Recycle Bin. From the other direction, `Remove-Item \\wsl$\Ubuntu\home\...` from PowerShell deletes through the Plan 9 file server — also slow on deep trees. Bulk deletes are fastest run from the OS that owns the filesystem.

Related commands