Print Download PDF Send Feedback

Previous

Next

Command History

You can recall commands you have used before, even in previous sessions.

Command

Description

Recall previous command.

Recall next command.

history

Show the last 100 commands.

!!

Run the last command.

!nn

Run a specific previous command: the nn command in the commands history list.

!‑nn

Run the nnth previous command.

For example, entering !‑3 runs the third from last command in the commands history list.

!str

Run the most recent command that starts with str.

!\?str\?

Run the most recent command containing str.

You may omit the trailing ?, if a new line follows str immediately.

!!:s/str1/str2

Repeat the last command, replacing str1 with str2.

Command Reuse

You can combine word designators with history commands to refer to specific words used in previous commands. Words are numbered from the beginning of the line with the first word being denoted by 0 (digit zero). Use a colon (:) to separate a history command from a word designator. For example, you could enter !!:1 to refer to the first argument in the previous command. In the command show interfaces, the interfaces is word 1.

Word Designator

Meaning

0

The operation word.

n

The nth word.

^

The first argument; that is, word 1.

$

The last argument.

%

The word matched by the most recent \?str\? search.

Immediately after word designators, you can add a sequence of one or more of these modifiers, each preceded by a colon:

Modifier

Meaning

p

Print the new command, but do not execute.

s/str1/str2

Replace str1 with str2 in the first occurrence of the word, to which you refer.

g

Apply changes over the entire command.
Use this modified in conjunction with s, as in gs/str1/str2.