Name

history

Synopsis

    history [options]

Display the list of history events. (History syntax is discussed earlier in the section “Command History.”)

Note: multiline compound commands such as foreach ... end are not saved in the history list. In general, the interactive command-line editing facilities are preferable to those of history and history substitution with the ! character.

Options

n

Display only the last n history commands, instead of the number set by the history shell variable.

-c

Clear history list.

-h

Print history list without event numbers.

-L file

Append the list of saved history commands in file to the history list.

-M file

Merge the current history list and the history list in file, sorted by time.

-r

Print in reverse order; show oldest commands last.

-S file

Save the history list to file. See also the savehist variable.

-T

Print with timestamp.

Example

To save and execute the last five commands:

    history -h 5 > do_it
    source do_it

Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.