How can I delete input in the terminal?

Assuming you are using the "usual" bash with emacs bindings, using Ctrlw should work.

To delete three words either press Ctrlw three times or preceed it with Alt3 or ESC3.

For more shortcuts have a look at this list.


Most shells have a facility called keybindings. It's of course configurable, and the designers of Bash opted to use keybindings that are similar to the text editor Emacs. Here's a cheatsheet that shows all the various keyboard shortcuts one can use from within a Bash shell to move the cursor within a given prompt, as well as delete whole words etc.

  • Mastering The Linux Shell – Bash Shortcuts Explained (Now With Cheat Sheets)
  • Cheatsheet as a PDF
  • Bash Cheat Sheet

This is of course my favorite because it's a picture so it's easier to associate which bindings go with which keys.

ss of cheatsheet

Source: Bash Cheat Sheet - SCRIBD


If you ran the command itself by mistake, in emacs editing mode you can use up-arrow to move to the last command, and edit it to a new command undoing the mistake. But note that not all commands can be cleanly undone, perhaps installing those packages installed others as dependencies or made other changes.

Depending on the exact commands (here package installation), there might be logs of what was done somewhere; using the logs you shold be able to figre out what was done (and thus how to undo it).

Get confortable editing the command line and rummaging in the history bash keeps. It is a work (and ocassionally life-) saver. And go into the habit of reading commands twice (thinking carefully what you want to do in between) before pressing ENTER if there is the slightest possibility of something destructive.