Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

Consider the following bash prompt, where ^ denotes the prompt location:

# git commit -am "[bug 123456] Do this and that with the bug"

Suppose that I want to commit again to the same bug, with a different commit message. Is there a way to delete the text from the cursor position till the end of line?

share|improve this question
up vote 75 down vote accepted

Use Ctrl+K to delete from the cursor to the end of the line.

Use Ctrl+U to delete from the cursor to the beginning of the line.

share|improve this answer
... and Ctrl+U deletes everything to the left. – CJBS Jan 28 '15 at 18:13
Ctr+K actually cuts from the cursor position to eol (Ctrl+Y is paste, btw) – Alessandro Cuttin May 19 '15 at 17:14

It depends on whether you are using vi(set -o vi) or emacs(set -o emacs) editing mode within your shell.

By default, your shell generally defaults to emacs editing mode.

  • In emacs mode, deleting to the end of the line can be accomplished by using the command ctrl-k.

  • If, however, you happen to be using vi editing mode in your command shell, the same result can be accomplished by typing Esc(which will place you in command mode) followed by d-$

If you are uncertain as to which editing mode that you are currently using in your shell, enter the command set -o from the command line and you will be able to determine which editing mode that you are currently using:

set -o
emacs           on
vi              off
share|improve this answer
If you want a mnemonic, the K stands for kill (the line starting from cursor position). – Gregor Bruns Mar 17 '13 at 13:53
In vi command mode, D works the same as d$ – glenn jackman Mar 17 '13 at 16:54
+1 for actually writing the right answer and explaining that shellopts may change it. – TC1 Mar 17 '13 at 20:57
>> Thanks. It seems that I'm using vi, so CTRL+K does the trick. – Adam Matan Adam, then that's emacs-mode you're in, not vi. – catch22 Mar 19 '13 at 19:14
In Kubuntu oneiric (konsole), Ctrl+K and ESC Shift+D both work. ESC d deletes some of the line (maybe up to a ';'). (Typing a $ after that just sends the $ to the console.) I've been trying to figure out how to do that for quite awhile. Thanks! – Joe Mar 20 '13 at 18:56

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.