Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I discovered this by mistake: Control+x followed by Backspace

Does anyone know why this clears the line? Any documentation?

share|improve this question

4 Answers 4

up vote 12 down vote accepted

Yes. From man bash:

   Killing and Yanking
       kill-line (C-k)
              Kill the text from point to the end of the line.
       backward-kill-line (C-x Rubout)
              Kill backward to the beginning of the line.
share|improve this answer
    
sweet, I learned something new today, thanks! –  ThatGraemeGuy Nov 9 '11 at 8:58

This is the equivalent of a cut in Windows. You can paste it back with Ctrl+Y.

share|improve this answer
    
I didn't even know that Bash has clipboard-like functionality! Nice to know! –  Belmin Fernandez Nov 7 '11 at 18:28
2  
It's actually the magic of readline. –  MikeyB Nov 7 '11 at 19:43
    
True but the end result is about the same. –  Tim Brigham Nov 7 '11 at 21:27
    
@timbrigham: Yes, but it means that it also works in other programs using readline, and for those that don't, you might be able to use rlwrap. –  hammar Nov 7 '11 at 23:03

As noted, it is in the man page. More precisely, the key-combinations in question are from EMACS, which is the default key-binding for Bash in a number of Linux distributions. If you need to use vi instead under Bash, you can use:

set -o vi

To switch it back to EMACS:

set -o emacs
share|improve this answer

bash supports something called the readline library, which allows you to do a completely amazing number of things with your shell. One of those things is that readline comes configured with a large number of default keyboard shortcuts, such as:

Ctrl-b  Move the cursor one character   ⇦ to the left
Ctrl-f  Move the cursor one character   ⇨ to the right
Alt-b   Move the cursor one word    ⇦ to the left
Alt-f   Move the cursor one word    ⇨ to the right
Ctrl-a  Move the cursor     ⇤ to the start of the line
Ctrl-e  Move the cursor     ⇥ to the end of the line
Ctrl-x-x    Move the cursor      ⇤⇥ to the start, and to the end again
Ctrl-d  Delete  the character   underneath the cursor
Ctrl-u  Delete  everything  ⇤ from the cursor back to the line start
Ctrl-k  Delete  everything  ⇥ from the cursor to the end of the line
Alt-d   Delete  word    ⇨ untill before the next word boundary
Ctrl-w  Delete  word    ⇦ untill after the previous word boundary
Ctrl-y  Yank/Paste  prev. killed text   at the cursor position
Alt-y   Yank/Paste  prev. prev. killed text at the cursor position
Ctrl-p  Move in history one line    ⇧ before this line
Ctrl-n  Move in history one line    ⇩ after this line
Alt->   Move in history all the lines   ⇩ to the line currently being entered
Ctrl-r  Incrementally search the line history   ⇧ backwardly
Ctrl-s  Incrementally search the line history   ⇩ forwardly
Ctrl-J  End an incremental search
Ctrl-G  Abort an incremental search and restore the original line
Alt-Ctrl-y  Yank/Paste  arg. 1 of prev. cmnd    at the cursor position
Alt-.
Alt-_   Yank/Paste  last arg of prev. cmnd  at the cursor position
Ctrl-_
Ctrl-x
Ctrl-u  Undo the last editing command; you can undo all the way back to an empty line
Alt-r   Undo all changes made to this line
Ctrl-l  Clear the screen, reprinting the current line at the top
Ctrl-l  Clear the screen, reprinting the current line at the top
Completion  TAB Auto-complete a name
Alt-/   Auto-complete a name (without smart completion)
Alt-?   List the possible completions of the preceeding text
Alt-*   Insert all possible completions of the preceeding text
Ctrl-t  Transpose/drag  char. before the cursor ↷ over the character at the cursor
Alt-t   Transpose/drag  word before the cursor  ↷ over the word at/after the cursor

Here's some good information on customizing readline as well.

share|improve this answer

Your Answer

 
discard

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.