| GNU Bash Reference Manual by Chet Ramey and Brian Fox Paperback (6"x9"), 180 pages ISBN 0954161777 RRP £19.95 ($29.95) "An essential resource .... the most detailed coverage available for all aspects of Bash" --- Linux User and Developer Magazine (Issue 37, Mar 2004) Get a printed copy>>> |
9.2 Bash History Builtins
Bash provides two builtin commands which manipulate the history list and history file.
fc-
Fix Command. In the first form, a range of commands from first to last is selected from the history list. Both first and last 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). If last is not specified it is set to first. If first is not specified it is set to the previous command for editing and -16 for listing. If thefc [-e ename] [-nlr] [first] [last]fc -s [pat=rep] [command]-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 by ename is invoked on a file containing those commands. If ename is 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, command is re-executed after each instance of pat in the selected command is replaced by rep. A useful alias to use with thefccommand isr='fc -s', so that typing ‘r cc’ runs the last command beginning withccand typing ‘r’ re-executes the last command (see section 6.6 Aliases). history-
history [n] history -c history -d offset 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 of n lists only the last n lines. If the shell variableHISTTIMEFORMATis set and not null, it is used as a format string for strftime 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. offset should be specified as it appears when the history is displayed.
-a- Append the new history lines (history lines entered since the beginning of the current Bash session) 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 current history file and append its contents to the history list.
-w- Write out the current history to the history file.
-p- Perform history substitution on the args and display the result on the standard output, without storing the results in the history list.
-s- The args are added to the end of the history list as a single entry.
-w,-r,-a, or-noptions is used, if filename is given, then it is used as the history file. If not, then the value of theHISTFILEvariable is used.
| ISBN 0954161777 | GNU Bash Reference Manual | See the print edition |