Bash History Builtins (Bash Reference Manual)
Next: History Interaction, Previous: Bash History Facilities, Up: Using History Interactively [Contents][Index]
9.2 Bash History Builtins
Bash provides two builtin commands which manipulate the history list and history file.
fc
fc [-e ename] [-lnr] [first] [last] fc -s [pat=rep] [command]
The first form selects a range of commands from
first
tolast
from the history list and displays or edits and re-executes them. Bothfirst
andlast
may be specified as a string (to locate the most recent command beginning with that string) or as a number (an index into the history list, where a negative number is used as an offset from the current command number).When listing, a
first
orlast
of 0 is equivalent to -1 and -0 is equivalent to the current command (usually thefc
command); otherwise 0 is equivalent to -1 and -0 is invalid.If
last
is not specified, it is set tofirst
. Iffirst
is not specified, it is set to the previous command for editing and -16 for listing. If the-l
flag is given, the commands are listed on standard output. The-n
flag suppresses the command numbers when listing. The-r
flag reverses the order of the listing. Otherwise, the editor given byename
is invoked on a file containing those commands. Ifename
is not given, the value of the following variable expansion is used:${FCEDIT:-${EDITOR:-vi}}
. This says to use the value of theFCEDIT
variable if set, or the value of theEDITOR
variable if that is set, orvi
if neither is set. When editing is complete, the edited commands are echoed and executed.In the second form,
command
is re-executed after each instance ofpat
in the selected command is replaced byrep
.command
is interpreted the same asfirst
above.A useful alias to use with the
fc
command isr='fc -s'
, so that typing ‘r cc
’ runs the last command beginning withcc
and typing ‘r
’ re-executes the last command (see Aliases).history
history [n] history -c history -d offset history -d start-end history [-anrw] [filename] history -ps arg
With no options, display the history list with line numbers. Lines prefixed with a ‘
*
’ have been modified. An argument ofn
lists only the lastn
lines. If the shell variableHISTTIMEFORMAT
is set and not null, it is used as a format string forstrftime
to display the time stamp associated with each displayed history entry. No intervening blank is printed between the formatted time stamp and the history line.Options, if supplied, have the following meanings:
-c
Clear the history list. This may be combined with the other options to replace the history list completely.
-d offset
Delete the history entry at position
offset
. Ifoffset
is positive, it should be specified as it appears when the history is displayed. Ifoffset
is negative, it is interpreted as relative to one greater than the last history position, so negative indices count back from the end of the history, and an index of ‘-1
’ refers to the currenthistory -d
command.-d start-end
Delete the history entries between positions
start
andend
, inclusive. Positive and negative values forstart
andend
are interpreted as described above.-a
Append the new history lines to the history file. These are history lines entered since the beginning of the current Bash session, but not already appended to the history file.
-n
Append the history lines not already read from the history file to the current history list. These are lines appended to the history file since the beginning of the current Bash session.
-r
Read the history file and append its contents to the history list.
-w
Write out the current history list to the history file.
-p
Perform history substitution on the
arg
s and display the result on the standard output, without storing the results in the history list.-s
The
arg
s are added to the end of the history list as a single entry.
When any of the
-w
,-r
,-a
, or-n
options is used, iffilename
is given, then it is used as the history file. If not, then the value of theHISTFILE
variable is used.
Next: History Interaction, Previous: Bash History Facilities, Up: Using History Interactively [Contents][Index]