.\" Man page generated from reStructuredText
.\" by the Docutils 0.22.4 manpage writer.
.
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "HISTORY" "1" "May 15, 2026" "4.7" "fish-shell"
.SH NAME
history \- show and manipulate command history
.SH SYNOPSIS
.nf
\fBhistory\fP [\fBsearch\fP] [\fB\-\-show\-time\fP] [\fB\-\-case\-sensitive\fP]
                 [\fB\-\-exact\fP | \fB\-\-prefix\fP | \fB\-\-contains\fP] [\fB\-\-max\fP \fIN\fP] [\fB\-\-null\fP] [\fB\-\-reverse\fP]
                 [\fISEARCH_STRING\fP \&...]
\fBhistory\fP \fBdelete\fP [\fB\-\-case\-sensitive\fP]
               [\fB\-\-exact\fP | \fB\-\-prefix\fP | \fB\-\-contains\fP] \fISEARCH_STRING\fP \&...
\fBhistory\fP \fBmerge\fP
\fBhistory\fP \fBsave\fP
\fBhistory\fP \fBclear\fP
\fBhistory\fP \fBclear\-session\fP
\fBhistory\fP \fBappend\fP \fICOMMAND\fP \&...
.fi
.sp
.SH DESCRIPTION
.sp
\fBhistory\fP is used to search, delete, and otherwise manipulate the history of interactive commands \%<#\:history-search>\&.
.sp
The following operations (sub\-commands) are available:
.INDENT 0.0
.TP
\fBsearch\fP
Returns history items matching the search string. If no search string is provided it returns all history items. This is the default operation if no other operation is specified. You only have to explicitly say \fBhistory search\fP if you wish to search for one of the subcommands. The \fB\-\-contains\fP search option will be used if you don\(aqt specify a different search option. Entries are ordered newest to oldest unless you use the \fB\-\-reverse\fP flag. If stdout is attached to a tty the output will be piped through your pager by the history function. The history builtin writes the results to stdout.
.TP
\fBdelete\fP
Deletes history items. The \fB\-\-contains\fP search option will be used if you don\(aqt specify a different search option. If you don\(aqt specify \fB\-\-exact\fP a prompt will be displayed before any items are deleted asking you which entries are to be deleted. You can enter the word \(dqall\(dq to delete all matching entries. You can enter a single ID (the number in square brackets) to delete just that single entry. You can enter more than one ID, or an ID range separated by a space to delete multiple entries. Press [enter] to not delete anything. Note that the interactive delete behavior is a feature of the history function. The history builtin only supports \fB\-\-exact \-\-case\-sensitive\fP deletion.
.TP
\fBmerge\fP
Immediately incorporates history changes from other sessions. Ordinarily \fBfish\fP ignores history changes from sessions started after the current one. This command applies those changes immediately.
.TP
\fBsave\fP
Immediately writes all changes to the history file. The shell automatically saves the history file; this option is provided for internal use and should not normally need to be used by the user.
.TP
\fBclear\fP
Clears the history file. A prompt is displayed before the history is erased asking you to confirm you really want to clear all history unless \fBbuiltin history\fP is used.
.TP
\fBclear\-session\fP
Clears the history file from all activity of the current session. Note: If \fBhistory merge\fP or \fBbuiltin history merge\fP is run in a session, only the history after this will be erased.
.TP
\fBappend\fP
Appends commands to the history without needing to execute them.
.UNINDENT
.sp
The following options are available:
.sp
These flags can appear before or immediately after one of the sub\-commands listed above.
.INDENT 0.0
.TP
\fB\-C\fP or \fB\-\-case\-sensitive\fP
Does a case\-sensitive search. The default is case\-insensitive.
.TP
\fB\-c\fP or \fB\-\-contains\fP
Searches items in the history that contain the specified text string. This is the default for the \fB\-\-search\fP flag. This is not currently supported by the \fBdelete\fP subcommand.
.TP
\fB\-e\fP or \fB\-\-exact\fP
Searches or deletes items in the history that exactly match the specified text string. This is the default for the \fBdelete\fP subcommand. Note that the match is case\-insensitive by default. If you really want an exact match, including letter case, you must use the \fB\-C\fP or \fB\-\-case\-sensitive\fP flag.
.TP
\fB\-p\fP or \fB\-\-prefix\fP
Searches items in the history that begin with the specified text string. This is not currently supported by the \fBdelete\fP subcommand.
.UNINDENT
.INDENT 0.0
.TP
\fB\-t\fP or \fB\-\-show\-time\fP
Prepends each history entry with the date and time the entry was recorded. By default it uses the strftime format \fB# %c%n\fP\&. You can specify another format; e.g., \fB\-\-show\-time=\(dq%Y\-%m\-%d %H:%M:%S \(dq\fP or \fB\-\-show\-time=\(dq%a%I%p\(dq\fP\&. The short option, \fB\-t\fP, doesn\(aqt accept a strftime format string; it only uses the default format. Any strftime format is allowed, including \fB%s\fP to get the raw UNIX seconds since the epoch.
.TP
\fB\-z\fP or \fB\-\-null\fP
Causes history entries written by the search operations to be terminated by a NUL character rather than a newline. This allows the output to be processed by \fBread \-z\fP to correctly handle multiline history entries.
.TP
\fB\-\fP*NUMBER* \fB\-n\fP \fINUMBER\fP or \fB\-\-max\fP \fINUMBER\fP
Limits the matched history items to the first \fINUMBER\fP matching entries. This is only valid for \fBhistory search\fP\&.
.TP
\fB\-R\fP or \fB\-\-reverse\fP
Causes the history search results to be ordered oldest to newest. Which is the order used by most shells. The default is newest to oldest.
.TP
\fB\-\-color\fP \fIWHEN\fP
Controls when to use syntax highlighting colors for the history entries.
\fIWHEN\fP can be \fBauto\fP (the default, colorize if the output is a terminal \%<>), \fBalways\fP, or \fBnever\fP\&.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help for this command.
.UNINDENT
.SH EXAMPLE
.INDENT 0.0
.INDENT 3.5
.sp
.EX
history clear
# Deletes all history items

history search \-\-contains \(dqfoo\(dq
# Outputs a list of all previous commands containing the string \(dqfoo\(dq.

history delete \-\-prefix \(dqfoo\(dq
# Interactively deletes commands which start with \(dqfoo\(dq from the history.
# You can select more than one entry by entering their IDs separated by a space.
.EE
.UNINDENT
.UNINDENT
.SH CUSTOMIZING THE NAME OF THE HISTORY FILE
.sp
By default interactive commands are logged to \fB$XDG_DATA_HOME/fish/fish_history\fP (typically \fB~/.local/share/fish/fish_history\fP).
.sp
You can set the \fBfish_history\fP variable to another name for the current shell session. The default value (when the variable is unset) is \fBfish\fP which corresponds to \fB$XDG_DATA_HOME/fish/fish_history\fP\&. If you set it to e.g. \fBfun\fP, the history would be written to \fB$XDG_DATA_HOME/fish/fun_history\fP\&. An empty string means history will not be stored at all. This is similar to the private session features in web browsers.
.sp
You can change \fBfish_history\fP at any time (by using \fBset \-x fish_history \(dqsession_name\(dq\fP) and it will take effect right away. If you set it to \fB\(dqdefault\(dq\fP, it will use the default session name (which is \fB\(dqfish\(dq\fP).
.sp
Other shells such as bash and zsh use a variable named \fBHISTFILE\fP for a similar purpose. Fish uses a different name to avoid conflicts and signal that the behavior is different (session name instead of a file path). Also, if you set the var to anything other than \fBfish\fP or \fBdefault\fP it will inhibit importing the bash history. That\(aqs because the most common use case for this feature is to avoid leaking private or sensitive history when giving a presentation.
.SH NOTES
.sp
If you specify both \fB\-\-prefix\fP and \fB\-\-contains\fP the last flag seen is used.
.sp
Note that for backwards compatibility each subcommand can also be specified as a long option. For example, rather than \fBhistory search\fP you can type \fBhistory \-\-search\fP\&. Those long options are deprecated and will be removed in a future release.
.SH Copyright
fish-shell developers
.\" End of generated man page.
