bash: Bash History Builtins

1 
1 9.2 Bash History Builtins
1 =========================
1 
1 Bash provides two builtin commands which manipulate the history list and
1 history file.
1 
1 'fc'
1           fc [-e ENAME] [-lnr] [FIRST] [LAST]
1           fc -s [PAT=REP] [COMMAND]
1 
1      The first form selects a range of commands from FIRST to LAST from
1      the history list and displays or edits and re-executes them.  Both
1      FIRST and LAST may be specified as a string (to locate the most
1      recent command beginning with that string) or as a number (an index
1      into the history list, where a negative number is used as an offset
1      from the current command number).  If LAST is not specified it is
1      set to FIRST.  If FIRST is not specified it is set to the previous
1      command for editing and -16 for listing.  If the '-l' flag is
1      given, the commands are listed on standard output.  The '-n' flag
1      suppresses the command numbers when listing.  The '-r' flag
1      reverses the order of the listing.  Otherwise, the editor given by
1      ENAME is invoked on a file containing those commands.  If ENAME is
1      not given, the value of the following variable expansion is used:
1      '${FCEDIT:-${EDITOR:-vi}}'.  This says to use the value of the
1      'FCEDIT' variable if set, or the value of the 'EDITOR' variable if
1      that is set, or 'vi' if neither is set.  When editing is complete,
1      the edited commands are echoed and executed.
1 
1      In the second form, COMMAND is re-executed after each instance of
1      PAT in the selected command is replaced by REP.  COMMAND is
1      intepreted the same as FIRST above.
1 
1      A useful alias to use with the 'fc' command is 'r='fc -s'', so that
1      typing 'r cc' runs the last command beginning with 'cc' and typing
1      'r' re-executes the last command (⇒Aliases).
1 
1 'history'
1           history [N]
1           history -c
1           history -d OFFSET
1           history [-anrw] [FILENAME]
1           history -ps ARG
1 
1      With no options, display the history list with line numbers.  Lines
1      prefixed with a '*' have been modified.  An argument of N lists
1      only the last N lines.  If the shell variable 'HISTTIMEFORMAT' is
1      set and not null, it is used as a format string for STRFTIME to
1      display the time stamp associated with each displayed history
1      entry.  No intervening blank is printed between the formatted time
1      stamp and the history line.
1 
1      Options, if supplied, have the following meanings:
1 
1      '-c'
1           Clear the history list.  This may be combined with the other
1           options to replace the history list completely.
1 
1      '-d OFFSET'
1           Delete the history entry at position OFFSET.  OFFSET should be
1           specified as it appears when the history is displayed.
1 
1      '-a'
1           Append the new history lines to the history file.  These are
1           history lines entered since the beginning of the current Bash
1           session, but not already appended to the history file.
1 
1      '-n'
1           Append the history lines not already read from the history
1           file to the current history list.  These are lines appended to
1           the history file since the beginning of the current Bash
1           session.
1 
1      '-r'
1           Read the history file and append its contents to the history
1           list.
1 
1      '-w'
1           Write out the current history list to the history file.
1 
1      '-p'
1           Perform history substitution on the ARGs and display the
1           result on the standard output, without storing the results in
1           the history list.
1 
1      '-s'
1           The ARGs are added to the end of the history list as a single
1           entry.
1 
1      When any of the '-w', '-r', '-a', or '-n' options is used, if
1      FILENAME is given, then it is used as the history file.  If not,
1      then the value of the 'HISTFILE' variable is used.
1