Delete the Previous Word in Terminal (Ctrl+W)
Press Ctrl+W to delete the word to the left of the cursor on the command line. It is the fastest way to fix a mistyped argument. Same key on macOS Terminal, Linux and Windows WSL / Git Bash.
| Action | Mac | Windows | |
|---|---|---|---|
| Delete previous word | Ctrl+W | Ctrl+W | |
| Delete to start of line | Ctrl+U | Ctrl+U | |
| Delete to end of line | Ctrl+K | Ctrl+K | |
| Paste last deletion (yank) | Ctrl+Y | Ctrl+Y |
Erase one word at a time
Press Ctrl+W to delete the word immediately before the cursor. Repeat it to remove several words. It works the same in bash and zsh on macOS Terminal, Linux and Windows WSL / Git Bash.
Ctrl+W vs Alt+Backspace
Ctrl+W deletes back to the previous whitespace, so /usr/local/bin is removed as one chunk. Alt+Backspace (Option+Delete on Mac) deletes back to the previous word boundary, so it stops at each /. Both put the removed text in the kill-ring.
Get it back with Ctrl+Y
If you delete too much, press Ctrl+Y to yank (paste) the last killed text back onto the line.
FAQ
How do I delete a word in the terminal?
Press Ctrl+W to remove the word before the cursor. Press it again to delete more words. Same key on Mac, Linux and WSL.
What is the difference between Ctrl+W and Alt+Backspace?
Ctrl+W deletes back to the previous space. Alt+Backspace (Option+Delete on Mac) deletes back to the previous word boundary, stopping at punctuation like slashes.
Can I undo Ctrl+W?
Yes. The deleted word goes to the kill-ring; press Ctrl+Y to paste it back.
Does Ctrl+W work in zsh?
Yes, in both bash and zsh. In zsh the word boundary depends on the WORDCHARS setting.