Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
  • 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?

share|improve this question
up vote 7 down vote accepted

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.

share|improve this answer
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 '14 at 18:11
That's why you usually can use ESC instead of Alt. – michas Feb 1 '14 at 18:12
I see. Is there a shortcut (combination) to delete the whole input at once? – henry Feb 2 '14 at 11:12
Ctrl-c or Ctrl-u will do that. For more like that have a look at this. – michas Feb 2 '14 at 11:23
Ctrl-u does it for me, thanks. – henry Feb 2 '14 at 13:02

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

share|improve this answer
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. – Blacklight Shining Feb 2 '14 at 4:22
Also: control-pageup and control-pagedown don't do anything in bash on my Ubuntu box. – Blacklight Shining Feb 2 '14 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 '14 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.” – Blacklight Shining Feb 5 '14 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.

share|improve this answer
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 '14 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.

share|improve this answer
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 '14 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


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.