O'Reilly logo

bash Quick Reference by Arnold Robbins

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

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

  • Line-edit mode

  • The fc command

  • C-shell–style history

Line-Edit Mode

Line-edit mode emulates 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. You can also change the line before executing it. When you're ready to issue the command, press the Enter key.

Emacs editing mode is the default. To control command-line editing, you must use either set -o vi or set -o emacs; Bash does not use variables to specify the editor.

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

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

ESC-b

Move back one word.

w

ESC-f

Move forward one word.

X

DEL

Delete previous character.

x

CTRL-d

Delete character under cursor.

dw

ESC-d

Delete word forward.

db

ESC-h

Delete word backward.

xp

CTRL-t

Transpose two characters.

The fc Command

fc stands for either "find command" or "fix command," since it does both jobs. Use fc -l to list history commands and fc -e to edit them. See the fc entry in the later section Built-in Commands for more information.

Examples

$ history ...

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