Specify A Command From History

One can specify an event from their history on the input line to repeat it.

The easiest way to specify an event from history is to use the up and down arrow keys. The up arrow key (<>) steps backwards through command events and the down arrow key (<>) steps forward through events. When an event is on the input line it can be edited it as if it were on the command line or type <Enter> to run it; it then become the most recent event in shell history.

Example…
Specify the second-to-last command…
$ <> <>

To specify an event by its number enter an exclamation point (!, a.k.a a “bang”) followed by the event number.

Example…
Run history event number 1…
$ !1 <Enter>

Observe event number “!” is the last event thus typing !! is another way to rerun the last command.

This entry was posted in BSD, Bash, GNU/Linux, UNIX and tagged , , , , . Bookmark the permalink.

One Response to Specify A Command From History

  1. W Alief says:

    You can also type ! plus the first letter or so of a command and it will run the last instance of that command.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>