The history built-in prints or edits command history.


  • history [-cF] [-d entry] [-s command] [-r file] [-w file] [count]


The history built-in prints or edits command history.

When executed with an option, the built-in edits history according to the option. If more than one option is specified, each option is processed in order.

When executed with the count operand, the built-in prints the most recent count history entries to the standard output in the same manner as the fc built-in.

When executed with neither options nor operands, the built-in prints the whole history.



Clear all history entries completely.

-d entry

Delete the specified entry. The entry should be specified in the same manner as the start and end operands of the fc built-in.


Rebuild the history file. This operation removes unused old data from the file.

-r file

Read command lines from file and add them to the history. The file contents are treated as lines of simple text.

-s command

Add command as a new history entry after removing the most recent entry.

-w file

Write the whole history to file. Any existing data in the file will be lost. The output format is lines of simple text, each of which is a command string.



The number of entries to be printed.

Exit status

The exit status of the history built-in is zero unless there is any error.


The history built-in is an elective built-in. It cannot be used in the POSIXly-correct mode because POSIX does not define its behavior.

Command history cannot be modified during line-editing.