Linux/unix: Cursor and character control shortcut keys for command line terminals

Source: Internet
Author: User
Tags clear screen delete key echo command posix

From:http://linux.chinaunix.net/techdoc/system/2007/11/23/973027.shtml
In the use of Linux/unix command-line terminal, sometimes encounter keyboard backspace, delete keys, home keys, direction keys, such as do not listen to the phenomenon:
Press the BACKSPACE key, may pop up a ^?
Press the DELETE key, but come out a ^[[3~
Press the home key, but come out a ^[[1~
Press the left ARROW key, but come out a ^[[d
......
The following are shortcuts that can be used in most shell terminals to solve the above control functions such as cursor and character deletion.
--tried to use Stty to solve problems such as the home key, but no results (see: http://www.ifpubs.com/books/aix52/stty0.htm)
Note: If you use a pseudo-terminal (such as gnome-terminal) for a graphical environment, the following may conflict with a subset of the shortcut keys in the window program.
****************************************************************************************************
Common shortcut keys:
Ctrl + D Deletes a character, which is equivalent to the usual delete key (the command line is equivalent to exit if there is no character); EOF is also represented when working with multiple lines of standard input
Ctrl + H backspace deletes one character, equivalent to the usual backspace key
Ctrl + U Delete the characters before the cursor to the beginning of the line
Ctrl + K Deletes the character before the cursor to the end of the line
CTRL + C cancels the current line Input command, which is equivalent to CTRL + BREAK
Ctrl + A cursor moves to the beginning (Ahead of line), equivalent to the usual home key
Ctrl + e cursor moves to end of line
Ctrl + F Cursor moves forward (Forward) one character position
Ctrl + b cursor back (backward) move one character position
Ctrl + L clear screen, equivalent to execute clear command
Ctrl + P brings up the previous (Previous) command in the command history, which is equivalent to the usual up arrow
Ctrl + N brings up the next (next) command in the command history, equivalent to the usual up arrow
Ctrl + R display: Prompt to find relevant historical commands according to user input (Reverse-i-search)
****************************************************************************************************
Times Common shortcut keys:
ALT + F Cursor moves forward (Forward) to the next word
ALT + b cursor moves back (backward) to the previous word
Ctrl + W Deletes the beginning of the current word (word) from before the cursor position
Alt + D deletes from the cursor position to the end of the current word
Ctrl + y Pastes the last word that was deleted
****************************************************************************************************
Appendix: Stty Command Reference Source: http://www.ifpubs.com/books/aix52/stty0.htm
Command Reference Daquan, volume 5,s-u
Stty command
Use
Set, reset, and report workstation operation parameters.
Grammar
Stty [-A] [-g] [Options]
Describe
The Stty command sets some I/O options for devices that are currently entered as standard. This command writes the output to a device that is currently in standard output.
This operating system version uses the standard "X/open portability Guide, Release 4" Interface to control the terminal and maintain compatibility with POSIX and BSD interfaces. The Stty command supports POSIX and BSD adaptation options, but it is highly recommended to use the POSIX option. A list of deprecated BSD options (with corresponding POSIX options) is also available.
When you enter the following command, you can redirect the standard input for a TTY device:
Stty-a L, l W, W
B, b m, M x, X
C, c N, n y, y
D, d o, o Z, z
E, E p, p [
F, f Q, q \
G, G R, R]
H, h S, s ^
I, I T, t _
J, J U, u?
K, K V, v @
Combination mode
cooked see-raw options.
EK sets the ERASE and KILL characters to ctrl-h and ctrl-u key sequences, respectively.
EVENP enable Parenb and CS7.
-EVENP disables Parenb and sets Cs8.
LCase, LCase set XCASE,IUCLC and OLCUC. The workstation is used only in uppercase characters.
-lcase,-lcase set-xcase,-IUCLC, and-OLCUC.
NL sets-icrnl and-ONLCR.
-NL set ICRNL, ONLCR,-INLCR,-IGNCR,-OCRNL, and-onlret.
ODDP enable Parenb, CS7, and parodd.
-ODDP disables Parenb and sets Cs8.
parity see EVENP options.
-parity See-EVENP options.
Sane set the parameter back to a reasonable value.
Raw allows raw mode input (excluding input processing, such as erase, Kill, or interrupt), and returns parity (parity) bits.
-raw allows canonical input mode.
Tabs preserves tabs.
-tabs, Tab3 tab is replaced with a space when printing.
Window size
cols N, Columns N records the terminal (window) size as having n columns.
Rows N records the terminal (window) size as having n rows.
Size Prints the terminal (window) sizes to the standard output (first row, then column).
Discard options
The Stty command supports the following BSD options. For each option, the recommended POSIX options are given.
All use the STTY-A command to display all current settings.
The CRT uses the SANE option to reset the parameters to a reasonable value.
Crtbs Use the-echoe option.
Crterase Use the Echoe option.
-crterase Use the-echoe option.
Crtkill Use the Echoke option.
-crtkill use the Echok and-echoke options.
Ctlecho Use the ECHOCTL option.
-ctlecho Use the-ECHOCTL option.
DECCTLQ Use the-ixany option.
-DECCTLQ Use the Ixany option.
Even use the EVENP option.
-even Use the-EVENP option.
Everything displays all current settings using the Stty-a command.
Litout Use the-opost option.
-litout Use the Opost option.
Odd use the ODDP option.
-odd Use the-ODDP option.
Pass8 Use the-istrip option.
-pass8 Use the Istrip option.
Prterase Use the ECHOPRT option.
Speed uses the Stty command to display the current settings.
Tandem use the Ixoff option.
-tandem Use the-ixoff option.
Example
To display a short list of your workstation configurations, enter:
Stty This will list the settings that are different from the default values.
To display a complete list of your workstation configurations, enter:
Stty-a
To enable the key sequence to stop the list from scrolling out of the screen, enter:
Stty Ixon Ixany This sets the Ixon mode so that the scrolling of the list can be stopped by pressing the CTRL-S key sequence. The Ixany flag allows you to press any key to restore the scrolling of the list. The normal workstation configuration includes the Ixon and Ixany flags, which allow you to stop the scrolling of the list with the Ctrl-s key sequence, and only the CTRL-Q key order to make the list scroll again.
To reset the messed up configuration, enter:
Ctrl-j Stty Sane Ctrl-j
Press the CTRL-J key sequence before and after the command instead of pressing Enter. The system usually recognizes the CTRL-J key sequence when the parameters that control the Enter key process are messed up.
Sometimes the information that appears on the screen may look strange, or the system does not respond when you press the ENTER key. This can happen when you use the Stty command, and it is difficult to understand the operation with incompatible parameters or parameters. This can also happen when a screen-oriented application ends abnormally and the workstation configuration cannot be reset.
Enter the Stty sane command to set a reasonable configuration, but it may be slightly different from your normal configuration.
To save and restore the configuration of the terminal:
Oldconfig= ' stty-g ' # Save Configuration
Stty-echo # do not display password
echo "Enter Password: \c"
Read PASSWD # Get the password
Stty $OLDCONFIG # Restore Configuration This command saves the configuration of the workstation, closes the loopback signal, reads the password, and restores the original configuration.
Enter the Stty-echo command to turn off the loopback signal, which means that when you enter a password on the keyboard, the password does not appear on the screen. This action has nothing to do with the echo command, which displays the message on the screen.
File
/usr/bin/stty contains the Stty command.
Related information
Terminfo file, TTY special file termios.h header file.
The TTY Programs Subsystem in AIX 5L Version 5.2 general programming concepts:writing and Debugging Overview.
Programs line ldterm in AIX 5L Version 5.2 general programming concepts:writing and debugging discipline.
National Language support in AIX 5L Version 5.2 National Language Support Guide and Reference.

Goto: Linux/unix command-line terminal cursor and character control shortcut keys

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.