rm — Delete files and directories across all 5 shells
Equivalents in every shell
Worked examples
Delete a directory and its contents
Bash
rm -rf dirPowerShell
Remove-Item dir -Recurse -Forcecmd.exe
rmdir /s /q dirDelete all files matching a glob
Bash
rm *.tmpPowerShell
Remove-Item *.tmpcmd.exe
del *.tmpPrompt before deleting each file
Bash
rm -i filePowerShell
Remove-Item file -Confirmcmd.exe
del /p fileGotchas
- `rm -rf /` (Unix) and `Remove-Item C:\ -Recurse -Force` (PowerShell) are equally catastrophic — modern shells often refuse the literal root path, but typos can still nuke a subtree.
- On Windows, `del` only deletes files; you need `rmdir` (or `Remove-Item -Recurse`) for directories.
- Deleted items go to the Recycle Bin via Explorer, but command-line deletes are permanent on every shell here.
WSL & PowerShell Core notes
pwshThe `rm` alias for `Remove-Item` is removed in PowerShell Core on Linux/macOS — `/bin/rm` resolves first. On Windows pwsh, `rm` is still the alias. To avoid surprises in cross-platform scripts, use `Remove-Item` explicitly; flag semantics differ (`-Recurse -Force` vs `-rf`).
WSL`rm -rf /mnt/c/Some/Dir` deletes Windows files but cannot remove anything held open by a Windows process (Explorer preview, antivirus scanner). Close the holder on Windows first, or use `cmd.exe /c "rmdir /s /q ..."` for the Windows native path.
Common tasks using rm
- Clean untracked files from a git repo
Delete files that git doesn't know about (build artifacts, scratch files, `.DS_Store`, `node_modules`) — the destructive sibling of `git restore`. ALWAYS dry-run first; there is no reflog recovery.
- Delete files older than 30 days
Remove files whose last-modified time is more than 30 days ago, recursively.
- Discard uncommitted changes in a git repo
Throw away local edits and reset the working tree to the last commit — the "I messed up, start over" gesture. Three subtly-different idioms (`git restore`, `git checkout --`, `git reset --hard`) cover three different scopes; picking the wrong one either keeps junk or nukes work you wanted to keep.