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.
fcfc [-e ename] [-lnr] [first] [last] fc -s [pat=rep] [command]
The first form selects a range of commands from
firsttolastfrom the history list and displays or edits and re-executes them. Bothfirstandlastmay 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
firstorlastof 0 is equivalent to -1 and -0 is equivalent to the current command (usually thefccommand); otherwise 0 is equivalent to -1 and -0 is invalid.If
lastis not specified, it is set tofirst. Iffirstis not specified, it is set to the previous command for editing and -16 for listing. If the-lflag is given, the commands are listed on standard output. The-nflag suppresses the command numbers when listing. The-rflag reverses the order of the listing. Otherwise, the editor given byenameis invoked on a file containing those commands. Ifenameis not given, the value of the following variable expansion is used:${FCEDIT:-${EDITOR:-vi}}. This says to use the value of theFCEDITvariable if set, or the value of theEDITORvariable if that is set, orviif neither is set. When editing is complete, the edited commands are echoed and executed.In the second form,
commandis re-executed after each instance ofpatin the selected command is replaced byrep.commandis interpreted the same asfirstabove.A useful alias to use with the
fccommand isr='fc -s', so that typing ‘r cc’ runs the last command beginning withccand typing ‘r’ re-executes the last command (see Aliases).historyhistory [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 ofnlists only the lastnlines. If the shell variableHISTTIMEFORMATis set and not null, it is used as a format string forstrftimeto 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:
-cClear the history list. This may be combined with the other options to replace the history list completely.
-d offsetDelete the history entry at position
offset. Ifoffsetis positive, it should be specified as it appears when the history is displayed. Ifoffsetis 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 -dcommand.-d start-endDelete the history entries between positions
startandend, inclusive. Positive and negative values forstartandendare interpreted as described above.-aAppend 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.
-nAppend 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.
-rRead the history file and append its contents to the history list.
-wWrite out the current history list to the history file.
-pPerform history substitution on the
args and display the result on the standard output, without storing the results in the history list.-sThe
args are added to the end of the history list as a single entry.
When any of the
-w,-r,-a, or-noptions is used, iffilenameis given, then it is used as the history file. If not, then the value of theHISTFILEvariable is used.
Next: History Interaction, Previous: Bash History Facilities, Up: Using History Interactively [Contents][Index]