Typing commands in a Linux shell
Document commandentry; version: 20081002. L.S.Lowe.Introduction
This note is about command prompts, command entry, and command line editing, on our system. It's about how you enter Unix commands in a terminal emulator window such as konsole or xterm, or in a window on a remote computer via telnet or ssh.It applies to you if you have the default local environment, or one largely similar. It assumes you're using the Korn or Posix shell, these being the local recommendations. See later section on Problems if it doesn't appear to apply to you.
Scrolling in a terminal emulator window
You can move backwards and forwards (scrolling) in a terminal emulator window in two ways:- either use the mouse to move the scroll bar, or
- use the Shift key with PageUp or PageDown.
Command prompt, colours, and keys in our Linux
There are several options provided locally for the prompt that the system displays when it is ready for you to type a Unix shell command. Skip this section if you are happy with the default.- The default prompt option is that you are prompted with the string
host$ in a special colour,
and you can use the arrow keys to help with command line editing
(see below).
You can change this default by setting the variable envprompt
in your .envrc file at a point before the std.envrc is run.
- If you set envprompt=1, then your prompt is host$ in the default foreground colour.
- If you set envprompt=2, then your prompt is host$ in a special colour.
- If you set envprompt=3, then your prompt is current-directory$ in a special colour.
- If you set envprompt=4, then your prompt is user@host$ in a special colour.
- If you set envprompt=5, then your prompt is user@host:current-directory$ in a special colour.
- The default special colour for prompts is currently yellow.
- If you set envcolour=red (or green, blue, cyan, magenta, yellow, white, black), then your prompt is in that colour.
- The default window title option is that the title of the window
remains set at its initial value during your session.
You can change this default by setting the variable envtitle
in your .envrc file at a point before the std.envrc is run.
- If you set envtitle=1 then the current working directory is displayed as the title of the window, and this is updated whenever you use the cd command.
- If you set envtitle=2 then the current hostname and working directory is displayed as the title of the window, and this is updated whenever you use the cd command.
- If you set envtitle=3 then the current username, hostname and working directory is displayed as the title of the window, and this is updated whenever you use the cd command.
Command line entry and editing
This section deals with making alterations to commands which you are entering or which you have previously entered at a shell command prompt.The style of line editing described here is called gmacs. This is now the local default, and is set up for you using the set -o gmacs command. It is very similar to emacs line-editing.
In gmacs or emacs line-editing style, you can type ordinary characters (they are inserted at the cursor position), or you can type special characters (such as backspace and the arrow keys), or control characters (where you hold down CTRL and type a key), or escape sequences (where you press the ESC key and then type other keys). The insert key is ignored here: you are always in insert mode.
If you are entering a new command, and you don't make any mistakes, then you simply hit Return or Enter on the keyboard. Otherwise, if necessary, you can make use of the editing facilities. The most useful editing sequences (I think) are:
- left-arrow to move the cursor to the left without deleting,
- right-arrow to move the cursor to the right,
- backspace to delete the previous character,
- ESC backspace to delete the previous word-item,
- ctl-D to delete the current character,
- TAB to do file-completion on a partial filename,
- up-arrow to recall previous commands,
- down-arrow to recall relative next commands,
- ctl-R string to recall a previous command containing string,
- ESC . to add the last word of the previous command to the present line.
Details
These details include emacs/gmacs line-editing characters, and also characters defined for you internally by the stty command.- Arrowkeys
- These arrow keys are defined for you using softkey aliases, as follows:
- UP
- Fetch previous command. Can be used successively.
- DOWN
- Fetch next command. Can be used successively.
- LEFT
- Move cursor left one character.
- RIGHT
- Move cursor right one character.
- Backspace
- Erase previous character (Also see erase below).
- Delete
- This is treated as an ordinary character and appears as ^? (But see erase below).
- Tab
- Perform filename-completion.
- \
- Escape next character, rather than obeying it as an editing command.
- ctl-A
- Move cursor to start of line.
- ctl-B
- Move cursor backward (left) one character.
- ctl-C
- See intr (below).
- ctl-D
- Delete current character.
- ctl-E
- Move cursor to end of line.
- ctl-F
- Move cursor forward (right) one character.
- ctl-G
- (No special action: just another character).
- ctl-H
- See Backspace (above).
- ctl-I
- See Tab (above).
- ctl-J
- (New line) Execute the current line.
- ctl-K
- Delete from cursor to end of line
(or to column defined by numeric parameter). - ctl-L
- Line feed and display current line.
- ctl-M
- (Return) Execute the current line.
- ctl-N
- Fetch next command. Can be used successively.
- ctl-O
- Operate - execute the current line and fetch the relative next line.
- ctl-P
- Fetch previous command. Can be used successively.
- ctl-Q
- See xon (below).
- ctl-R string
- Recall - fetch a previous command containing string.
With a numeric parameter of 0, search forward. - ctl-R ^string
- Recall - fetch a previous command beginning string.
With a numeric parameter of 0, search forward. - ctl-R CR
- Recall - repeat previous recall.
With a numeric parameter of 0, search in reverse direction. - ctl-S
- See xoff (below).
- ctl-T
- Transpose two previous characters.
- ctl-U
- See kill (below).
- ctl-V
- Display version of the shell.
- ctl-W
- Delete text between the cursor and the mark.
- ctl-X ctl-X
- Interchange the cursor and mark.
- ctl-Y
- Yank - restore last item deleted or pushed, and mark the position.
- ctl-Z
- See susp (below).
- ctl-] char
- Move cursor forward to matching character on the line.
- ESC space
- Set mark to cursor position. (Initially, mark is at start of line).
- ESC #
- Insert a # (comment) at beginning of the line and enter it.
- ESC *
- Attempt multiple file-name generation on the current word.
- ESC .
- Insert the last word of the previous command
(or the N'th word if numeric parameter has been set). - ESC <
- Fetch the least recent (oldest) history line.
- ESC =
- List files matching current word as if a * were appended.
- ESC >
- Fetch the most recent (youngest) history line.
- ESC ESC
- Attempt unique file-name completion on the current word.
- ESC DEL
- Delete previous word-item (to left of cursor).
- ESC BSP
- Delete previous word-item (to left of cursor).
- ESC ctl-] char
- Move cursor backward to matching character on the line.
- ESC _
- Same as ESC . (above).
- ESC b
- Move cursor backward one word-item.
- ESC c
- Capitalize current word-item (from cursor onwards).
- ESC d
- Delete current word-item (from cursor onwards).
- ESC digits
- Define numeric parameter for next command.
If appropriate, changes a single action to a multiple one.
For example, ESC 12 ctl-D will delete twelve characters. - ESC f
- Move cursor forward one word-item.
- ESC h
- Delete previous word-item (to left of cursor).
- ESC i
- Attempt multiple file-name generation. (Local alias for ESC *).
- ESC l
- Change the current word-item to lowercase (from cursor onwards).
- ESC letter
- Softkey. Use value of alias _letter as if keyboard input.
- ESC p
- Push (save) the text from the cursor to the mark (see ctl-Y).
- erase
- Erase previous character. By default, this is Backspace, but this is configurable using the stty command if you have no Backspace key.
- intr
- Interrupt current process, or kill the current line. By default, this is ctl-C; configurable using stty.
- kill
- Erase the entire current line. By default, this is ctl-U; configurable using stty.
- susp
- Suspend the current process (can resume it later). By default, this is ctl-Z; configurable using stty.
- xoff
- Pause the output of a command. Also see xon.
- xon
- Resume the output of a command paused by xoff. The xoff/xon facility can be switched off using stty -ixon.
In the description above, a word-item means a word delimited by blanks or other characters which are not alphabetic, numeric or underscore. For example, if you are at the end of a long file pathname containing slashes, then typing ESC b moves you to the previous component in that pathname.
Problems
If the above description doesn't appear to work for you, then ask Lawrie Lowe. But if you like to do it yourself, try the following suggestions:-
Before June 2008:
Check your .profile file to ensure it contains the following
line near the top
(notice that this line begins with dot blank):
- . /usr/local/etc/std.profile
- Check your environment (ENV) file. By default, this is called
.envrc, or .kshrc if that doesn't exist.
Ensure that this file contains the following line near the
top (notice that this line also begins with dot blank):
- . /usr/local/etc/std.envrc
- Also ensure that lines after this line in your file do not override settings which have thereby been setup. If in doubt, comment out all your subsequent lines with a # character, and bring up a new window to test the modified file. If this works, then gradually re-instate commented lines which you think you still need.
Further documentation
The information on command line editing in emacs/gmacs mode is taken from Unix documentation: man ksh.LSL.