# History built-in

The history built-in prints or edits command history.

## Syntax

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

## Description

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.

## Options

`-c`
`--clear`

  Clear all history entries completely.

`-d entry`
`--delete=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.

`-F`
`--flush-file`

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

`-r file`
`--read=file`

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

`-s command`
`--set=command`

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

`-w file`
`--write=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.

## Operands

count

  The number of entries to be printed.

## Exit status

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

## Notes

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.