• Xubuntu 13.10

Say I paste a command, something like

sudo apt-get install abc yxz 123 DEF MMM KKK

into the terminal. Then I suddenly had a change in mind and thus I would like to delete the last 3 packages without using backspace. Is there a way to mark them, as in using something like ctrl + shift + left?

5 Answers 5


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.

  • Hm, in my terminal/bash conole, which is actually xfce4-terminal, the Alt+N trick changes to the tab N (I often have more than one tab open, the first one usually running htop).
    – henry
    Feb 1, 2014 at 18:11
  • 1
    That's why you usually can use ESC instead of Alt.
    – michas
    Feb 1, 2014 at 18:12
  • I see. Is there a shortcut (combination) to delete the whole input at once?
    – henry
    Feb 2, 2014 at 11:12
  • 2
    Ctrl-c or Ctrl-u will do that. For more like that have a look at this.
    – michas
    Feb 2, 2014 at 11:23
  • Lol, when you google your own questions... so I wanted to add: but if there's only one tab open, the Alt+N bit works pretty great! Neat. :-)
    – henry
    Aug 11, 2018 at 9:52

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.

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

  • Correction to the did-you-know box: control-c sends SIGINT, not SIGTERM. control-z actually suspends the job (sending SIGSTOP to the process group); you have to issue bg afterwards to make it continue in the background. Feb 2, 2014 at 4:22
  • Also: control-pageup and control-pagedown don't do anything in bash on my Ubuntu box. Feb 2, 2014 at 4:26
  • @BlacklightShining you're quite right about SIGINT of course but Ctrl+Z does send a job to the background, whether it continues running is another issue. What is Ctrl+PgUp supposed to do? I don't see it in the image above.
    – terdon
    Feb 2, 2014 at 12:36
  • @terdon Fair enough. I just found it misleading; I would interpret send a process to the background as make a process continue running in the background. According to the image, control-pageup and control-pagedown are supposed to “scroll the terminal, even remote or graphical ones.” Feb 5, 2014 at 0:49

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.

  • I am aware of some of the things you said, I usually don't have such "problems" which could have, as you said, some bad consequences. Thanks for reminding me though, I have yet to work through some guides for beginners. :) (#1, #2)
    – henry
    Feb 1, 2014 at 18:17

If you're using bash then you can do following

Alt-3 followed by Ctrl+w assuming you're at the end of command.


Alt+N is used to pass universal argument to the following command to be executed N number of times.

Ctrl+w deletes a word backward.

  • Interesting, thanks. Unfortunately in my terminal/bash conole, which is actually xfce4-terminal, the Alt+N trick changes to the tab N (I often have more than one tab open, the first one usually running htop).
    – henry
    Feb 1, 2014 at 18:11

I am assuming you are using bash. Bash default editing mode is emacs. Bash supports both emacs mode and vi mode.

In Bash-Emacs and Bash-vi mode:

C-w (Control-w) will clear last word


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .