This depends on the shell in question.
Some shells (like AT&T ksh88) offer virtually no input line editing.
In shells implementing
vi mode editing (you may have to enable this with
set -o vi), this is done by pressing Esc (to switch from insert mode) followed by 0 to jump to the beginning of line or $ to jump to the end of line. Then re-enter insert mode either by pressing i – the cursor will stay where it is – or a – the cursor will move one to the right to append text.
vi mode editing has recently been mandated by the POSIX standard.
The much more common
emacs mode editing (thank gods, it has nothing to do with the Emacs editor-slash-operating-system) uses Ctrl-A to jump to the beginning of the line and Ctrl-E to jump to the end of the line. This mode requires you to run
set -o emacs on many shells (most prominently AT&T ksh93) but is enabled by default in mksh and GNU bash.
Most modern shells support both
vi modes. (Both these modes require a tty to work.)
In many shells, you can customise keybindings; usually for the
emacs mode, although some shells also permit customising the keybinding for the
vi mode. If you have a key you'd rather have this bound to, you first need to figure out the key sequences it produces (for example, on my system, Alt-CursorLeft produces Esc+[+1+;+3+D (
^X is Ctrl-X and
^[ is Esc), so I can type something like
and will have this keybinding changed, depending on the shell. You can usually persist them in either the startup file (
~/.kshrc) or, for GNU bash, in
~/.inputrc. Note that not all shells support bindind all keys in all versions.
You can usually find out what chars a key generates by just running
cat on the shell, typing the key and watching. Then press
^C (Ctrl-C) to abort