O'Reilly logo

Mac OS X Tiger in a Nutshell by Jason McIntosh, Chuck Toporek, Chris Stone, Andy Lester

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Command History

bash lets you display or modify previous commands. Commands in the history list can be modified using:

  • Line-edit mode

  • The fc command

Line-Edit Mode

Line-edit mode lets you emulate many features of the vi and Emacs editors. The history list is treated like a file. When the editor is invoked, you type editing keystrokes to move to the command line you want to execute. In the Terminal, the arrow keys work in both Emacs mode and vi command mode. You can also change the line before executing it. See Table 5-32 for some examples of common line-edit commands. When you're ready to issue the command, press Return. The default line-edit mode is Emacs. To enable vi mode, enter:

    $ set -o vi

Note that vi starts in input mode; to type a vi command, press Esc first.

The mode you use for editing bash commands is entirely separate from the editor that is invoked for you automatically within many commands (for instance, the editor invoked by mail readers when you ask them to create a new mail message). To change the default editor, set the VISUALor EDITOR variable to the filename or full pathname of your favorite editor:

    $ export EDITOR=emacs

Table 5-32. Common editing keystrokes

vi

Emacs

Result

K

Ctrl-p

Get previous command.

J

Ctrl-n

Get next command.

/string

Ctrl-r string

Get previous command containing string.

H

Ctrl-b

Move back one character.

L

Ctrl-f

Move forward one character.

b

M-b

Move back one word.

w

M-f

Move forward one word.

X

Del

Delete previous ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required