Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I accidentally typed ctrl + L in terminal and my terminal window jumped one 'screenful' size. I looked at the keyboard shortcuts in "Edit"->"Keyboard shortcuts" and didn't find that shortcut.

What does ctrl + L do and where is it defined?

share|improve this question

3 Answers 3

up vote 31 down vote accepted

ctrl + L just clear the terminal screen.

It is the keyboard shortcut equivalent of the command clear.

It is property of bash, so you did not found it under keyboard shortcuts in your gnome-terminal. From man bash:

clear-screen (C-l)
          Clear the screen leaving the current line  at  the  top  of  the
          screen.   With  an  argument,  refresh  the current line without
          clearing the screen.

See a detail list of Bash Keyboard Shortcuts.

share|improve this answer
    
Oh, that explains it. –  Parto Mar 14 at 15:28
    
@Jobin Now I am away, I will try to provide more details if possible. –  souravc Mar 14 at 15:54
    
+1, never thought it was a bash keybinding. –  i08in Mar 14 at 16:22
1  
It's not just bash though; Ctrl-L is the form-feed character. It's not so common, but sometimes you'll see ^L in source code separating "pages" of code. It made more sense when a printer would interpret it as a control character. –  Joshua Taylor Mar 14 at 17:37
1  
^L is the form-feed character in the ascii table, but that doesn't do anything unless it is received by a program that treats it accordingly (either bash or the terminal emulator, in this context). –  alexis Mar 15 at 12:38

If the shell you're using is not intercepting it, you are typing a "Form-feed" character in your terminal. If the terminal application does not intercept or use the keystroke in some way, Ctrl+Letter is translated to the ASCII code of the letter minus 64(1). 65 is the ASCII code of 'A', 'L' is the 12th letter -> code 10. If the shell does not know what to do of the code, it prints it.

Printing a FF char resulted in a new page on a line printer and a clear screen on the terminal (yes, I used a VT-52 back then, at 300 baud).

So Ctrl+L is 12 which is FF. In the same way, Ctrl+I is a TAB, and Ctrl+G rings the bell --- if the terminal or the shell does not intercept it, like Ctrl+C for example.

Notice from the other answer: it seems that bash do intercept CTRL-L and do a clear. Nice touch that the bash authors associated the key with a command which will do more or less the same that the ASCII code did on old terminals!

On the other hand, in my zsh the combination CTRL-I works as TAB and CTRL-H as a Backspace(2).

Old nice ASCII... (notice that letter L is at column 4, row 12, it has ASCII code 4*16+12=76).

Image from Wikimedia commons

Original Image here, from wikipedia article on ASCII.


Footnotes:

(1) Ctrl really used to clear the bit 7.

(2) this is the source of the "fail to remove word" joke you sometime find like for example "this was a bad^H^H^Hnot so nice idea"... (with normally a word stronger than bad!)

share|improve this answer
    
Nice. How do I use this chart by the way? I can see that letter L is at row 12 and column 4. Do I then just minus 32 from the 124 or how do you calculate the ASCII code? –  Parto Mar 14 at 15:35
    
@AvatarParto ups, wrote 32 instead of 65. Answer corrected. The table is binary, so the code is column*16+row. –  Rmano Mar 14 at 15:52
1  
Inserting literal ^Hs or ^Ws is nice when you can't use strikethroughs. :) –  Blacklight Shining Mar 14 at 23:47

Control-L is intercepted and interpreted by bash (actually by the readline library, which handles interactive editing on the command line). It is bound to the clear-screen function, as @souravc wrote.

Note on the meaning of Control-L: It is defined as Form Feed in the ASCII character table, but this means nothing unless some program interprets it accordingly. The terminal does not clear the screen when it sees a form feed, as you can verify by by saving a ^L in a file and printing the file with cat. When bash/readline sees the ^L, it executes the clear-screen function. This sends a sequence of characters that is understood by your terminal emulator (as described by termcap or terminfo), and has the effect of clearing the screen.

In very old printers, a ^L would advance the paper start printing on the next sheet, hence the name "form feed". But modern terminals and terminal emulators follow a newer ANSI standard, in which control commands are multi-character "escape codes" that begin with ^[ (escape). When bash sees your ^L, it is probably sending the two-command sequence ESC [ H ESC [ J, which moves to the top left of the screen and clears everything below it (hence the whole screen).

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.