2 .\" Copyright 1989 AT&T
3 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
4 .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
5 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
6 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
7 .\" http://www.opengroup.org/bookstore/.
8 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
9 .\" This notice shall appear on any product containing this material.
10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
11 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
12 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
13 .TH HISTORY 1 "May 13, 2017"
15 history, fc, hist \- process command history list
19 \fB/usr/bin/fc\fR [\fB-r\fR] [\fB-e\fR \fIeditor\fR] [\fIfirst\fR [\fIlast\fR]]
24 \fB/usr/bin/fc\fR \fB-l\fR [\fB-nr\fR] [\fIfirst\fR [\fIlast\fR]]
29 \fB/usr/bin/fc\fR \fB-s\fR [\fIold\fR=\fInew\fR] [\fIfirst\fR]
35 \fBhistory\fR [\fB-hr\fR] [\fIn\fR]
41 \fBfc\fR \fB-e\fR \fB-\fR [\fIold\fR=\fInew\fR] [\fIcommand\fR]
46 \fBfc\fR \fB-s\fR [\fIold\fR = \fInew\fR] [\fIcommand\fR]
51 \fBfc\fR [\fB-e\fR \fIename\fR] [\fB-nlr\fR] [\fIfirst\fR [\fIlast\fR]]
57 \fBhist\fR [\fB-lnprs\fR] [\fB-e\fR \fIeditor\fR][\fB-N\fR \fInum\fR][\fIfirst\fR[\fIlast\fR]]
63 The \fBfc\fR utility lists or edits and reexecutes, commands previously entered
64 to an interactive \fBsh\fR.
67 The command history list references commands by number. The first number in the
68 list is selected arbitrarily. The relationship of a number to its command does
69 not change except when the user logs in and no other process is accessing the
70 list, at which time the system can reset the numbering to start the oldest
71 retained command at another number (usually 1). When the number reaches the
72 value in \fBHISTSIZE\fR or \fB32767\fR (whichever is greater), the shell can
73 wrap the numbers, starting the next command with a lower number (usually 1).
74 However, despite this optional wrapping of numbers, \fBfc\fR maintains the
75 time-ordering sequence of the commands. For example, if four commands in
76 sequence are given the numbers 32 766, 32 767, 1 (wrapped), and 2 as they are
77 executed, command 32 767 is considered the command previous to 1, even though
81 When commands are edited (when the \fB-l\fR option is not specified), the
82 resulting lines is entered at the end of the history list and then reexecuted
83 by \fBsh\fR. The \fBfc\fR command that caused the editing is not entered into
84 the history list. If the editor returns a non-zero exit status, this suppresses
85 the entry into the history list and the command reexecution. Any command-line
86 variable assignments or redirection operators used with \fBfc\fR affects both
87 the \fBfc\fR command itself as well as the command that results, for example:
91 \fBfc -s -- -1 2>/dev/null\fR
98 reinvokes the previous command, suppressing standard error for both \fBfc\fR
99 and the previous command.
102 Display the history list. If \fIn\fR is given, display only the \fIn\fR most
110 Reverse the order of printout to be most recent first rather than oldest first.
119 Display the history list without leading numbers. This is used to produce files
120 suitable for sourcing using the \fB-h\fR option to the \fBcsh\fR built-in
121 command, \fBsource\fR(1).
124 .SS "History Substitution:"
126 History substitution allows you to use words from previous command lines in the
127 command line you are typing. This simplifies spelling corrections and the
128 repetition of complicated commands or arguments. Command lines are saved in the
129 history list, the size of which is controlled by the \fBhistory\fR variable.
130 The \fBhistory\fR shell variable can be set to the maximum number of command
131 lines that is saved in the history file, that is:
141 allows the history list to keep track of the most recent 200 command lines. If
142 not set, the C shell saves only the most recent command.
145 A history substitution begins with a \fB!\fR (although you can change this with
146 the \fBhistchars\fR variable) and can occur anywhere on the command line;
147 history substitutions do not nest. The \fB!\fR can be escaped with \fB\e\fR to
148 suppress its special meaning.
151 Input lines containing history substitutions are echoed on the terminal after
152 being expanded, but before any other substitutions take place or the command
154 .SS "Event Designators:"
156 An event designator is a reference to a command line entry in the history list.
164 Start a history substitution, except when followed by a space character, tab,
165 newline, \fB=\fR or \fB(\fR.
175 Refer to the previous command. By itself, this substitution repeats the
186 Refer to command line \fIn\fR.
192 \fB\fB!\fR\fB-n\fR\fR
196 Refer to the current command line minus \fIn\fR.
202 \fB\fB!\fR\fIstr\fR\fR
206 Refer to the most recent command starting with \fIstr\fR.
212 \fB\fB!?\fR\fIstr\fR\fB?\fR\fR
216 Refer to the most recent command containing \fIstr\fR.
222 \fB\fB!?\fR\fIstr\fR\fB?\fR \fIadditional\fR\fR
226 Refer to the most recent command containing \fIstr\fR and append
227 \fIadditional\fR to that referenced command.
233 \fB\fB!{\fR\fBcommand\fR\fB}\fR \fIadditional\fR\fR
237 Refer to the most recent command beginning with \fBcommand\fR and append
238 \fIadditional\fR to that referenced command.
244 \fB\fB^\fR\fIprevious_word\fR\fB^\fR\fIreplacement\fR\fB^\fR\fR
248 Repeat the previous command line replacing the string \fIprevious_word\fR with
249 the string \fIreplacement\fR. This is equivalent to the history substitution:
251 Repeat the previous command line replacing the string \fIprevious_word\fR with
252 the string \fIreplacement\fR. This is equivalent to the history substitution:
256 \fB!:s/\fR\fIprevious_word\fR\fB/\fR\fIreplacement\fR\fB/\fR.
260 To re-execute a specific previous command \fBand\fR make such a substitution,
261 say, re-executing command #6:
265 \fB!:6s/\fR\fIprevious_word\fR\fB/\fR\fIreplacement\fR\fB/\fR.
271 .SS "Word Designators:"
273 A `\fB:\fR' (colon) separates the event specification from the word designator.
274 2It can be omitted if the word designator begins with a \fB^\fR, \fB$\fR,
275 \fB*\fR, \fB\(mi\fR or \fB%\fR. If the word is to be selected from the previous
276 command, the second \fB!\fR character can be omitted from the event
277 specification. For instance, \fB!!:1\fR and \fB!:1\fR both refer to the first
278 word of the previous command, while \fB!!$\fR and \fB!$\fR both refer to the
279 last word in the previous command. Word designators include:
286 The entire command line typed so far.
295 The first input word (command).
304 The \fIn\fR'th argument.
313 The first argument, that is, \fB1\fR.
331 The word matched by (the most recent) \fB?\fR\fIs\fR search.
337 \fB\fIx\fR\fB\(mi\fR\fIy\fR\fR
340 A range of words; \fB\(mi\fR\fIy\fR abbreviates \fB0\(mi\fR\fIy\fR.
349 All the arguments, or a null value if there is just one word in the event.
358 Abbreviates \fIx\fR\fB\(mi$\fR\fI\&.\fR
364 \fB\fIx\fR\fB\(mi\fR\fR
367 Like \fIx\fR\fB*\fR but omitting word \fB$\fR.
372 After the optional word designator, you can add a sequence of one or more of
373 the following modifiers, each preceded by a \fB:\fR.
380 Remove a trailing pathname component, leaving the head.
389 Remove a trailing suffix of the form `\fB\&.\fR\fIxxx\fR', leaving the
399 Remove all but the suffix, leaving the extension.
405 \fB\fBs/\fR\fIoldchars\fR\fB/\fR\fIreplacements\fR\fB/\fR\fR
408 Substitute \fIreplacements\fR for \fIoldchars\fR. \fIoldchars\fR is a string
409 that can contain embedded blank spaces, whereas \fIprevious_word\fR in the
410 event designator can not.
414 \fB^\fR\fIoldchars\fR\fB^\fR\fIreplacements\fR\fB^\fR
426 Remove all leading pathname components, leaving the tail.
435 Repeat the previous substitution.
444 Apply the change to the first occurrence of a match in each word, by prefixing
445 the above (for example, \fBg&\fR).
454 Print the new command but do not execute it.
463 Quote the substituted words, escaping further substitutions.
472 Like \fBq\fR, but break into words at each space character, tab or newline.
477 Unless preceded by a \fBg\fR, the modification is applied only to the first
478 string that matches \fIoldchars\fR. An error results if no string matches.
481 The left-hand side of substitutions are not regular expressions, but character
482 strings. Any character can be used as the delimiter in place of \fB/\fR. A
483 backslash quotes the delimiter character. The character \fB&\fR, in the right
484 hand side, is replaced by the text from the left-hand-side. The \fB&\fR can be
485 quoted with a backslash. A null \fIoldchars\fR uses the previous string either
486 from a \fIoldchars\fR or from a contextual scan string \fIs\fR from
487 \fB!?\fR\fIs\fR. You can omit the rightmost delimiter if a newline immediately
488 follows \fIreplacements\fR; the rightmost \fB?\fR in a context scan can
489 similarly be omitted.
492 Without an event specification, a history reference refers either to the
493 previous command, or to a previous history reference on the command line (if
497 Using \fBfc\fR, in the form of
501 \fBfc -e \(mi [\fIold\fR=\fInew\fR] [\fIcommand\fR],\fR
512 \fBfc -s [\fIold\fR=\fInew\fR] [\fIcommand\fR],\fR
519 the \fIcommand\fR is re-executed after the substitution
520 \fIold\fR\fB=\fR\fInew\fR is performed. If there is not a \fIcommand\fR
521 argument, the most recent command typed at this terminal is executed.
524 Using \fBfc\fR in the form of
528 \fBfc [-e \fIename\fR] [-nlr ] [\fIfirst\fR [\fIlast\fR]],\fR
535 a range of commands from \fIfirst\fR to \fIlast\fR is selected from the last
536 \fBHISTSIZE\fR commands that were typed at the terminal. The arguments
537 \fIfirst\fR and \fIlast\fR can be specified as a number or as a string. A
538 string is used to locate the most recent command starting with the given
539 string. A negative number is used as an offset to the current command number.
540 If the \fB-l\fR flag is selected, the commands are listed on standard output.
541 Otherwise, the editor program \fB-e\fR \fIname\fR is invoked on a file
542 containing these keyboard commands. If \fIename\fR is not supplied, then the
543 value of the variable \fBFCEDIT\fR (default \fB/bin/ed\fR) is used as the
544 editor. When editing is complete, the edited command(s) is executed. If
545 \fBlast\fR is not specified, it is set to \fIfirst\fR. If \fIfirst\fR is not
546 specified, the default is the previous command for editing and \(mi16 for
547 listing. The flag \fB-r\fR reverses the order of the commands and the flag
548 \fB-n\fR suppresses command numbers when listing. (See \fBksh\fR(1) for more
549 about command line editing.)
556 If this variable is set when the shell is invoked, then the value is the
557 pathname of the file that is used to store the command history.
566 If this variable is set when the shell is invoked, then the number of
567 previously entered commands that are accessible by this shell is greater than
568 or equal to this number. The default is \fB128\fR.
571 .SS "Command Re-entry:"
573 The text of the last \fBHISTSIZE\fR (default 128) commands entered from a
574 terminal device is saved in a \fBhistory\fR file. The file
575 \fB$HOME/.sh_history\fR is used if the \fBHISTFILE\fR variable is not set or if
576 the file it names is not writable. A shell can access the commands of all
577 \fIinteractive\fR shells which use the same named \fBHISTFILE\fR. The special
578 command \fBfc\fR is used to list or edit a portion of this file. The portion of
579 the file to be edited or listed can be selected by number or by giving the
580 first character or characters of the command. A single command or range of
581 commands can be specified. If you do not specify an editor program as an
582 argument to \fBfc\fR then the value of the variable \fBFCEDIT\fR is used. If
583 \fBFCEDIT\fR is not defined then \fB/bin/ed\fR is used. The edited command(s)
584 is printed and re-executed upon leaving the editor. The editor name \fB\(mi\fR
585 is used to skip the editing phase and to re-execute the command. In this case a
586 substitution parameter of the form \fIold\fR\fB=\fR\fInew\fR can be used to
587 modify the command before execution. For example, if \fBr\fR is aliased to
588 \fBa\'fc\fR \fB-e\fR \fB\(mi a\'\fR then typing \fB`r\fR \fBbad=good\fR
589 \fBc'\fR re-executes the most recent command which starts with the letter
590 \fBc\fR, replacing the first occurrence of the string \fBbad\fR with the string
594 Using the \fBfc\fR built-in command within a compound command causes the whole
595 command to disappear from the history file.
598 \fBhist\fR lists, edits, or re-executes commands previously entered into the
599 current shell environment.
602 The command history list references commands by number. The first number in the
603 list is selected arbitrarily. The relationship of a number to its command does
604 not change during a login session. When the number reaches \fB32767\fR the
605 number wraps around to \fB1\fR but maintains the ordering.
608 When the \fBl\fR option is not specified, and commands are edited, the
609 resulting lines are entered at the end of the history list and then re-executed
610 by the current shell. The \fBhist\fR command that caused the editing is not
611 entered into the history list. If the editor returns a \fBnon-zero\fR exit
612 status, this suppresses the entry into the history list and the command
613 re-execution. Command line variable assignments and redirections affect both
614 the \fBhist\fR command and the commands that are re-executed.
617 \fIfirst\fR and \fIlast\fR define the range of commands. Specify \fIfirst\fR
618 and \fIlast\fR as one of the following:
625 A positive number representing a command number. A \fB+\fR sign can precede
632 \fB\fB-\fR\fInumber\fR\fR
635 A negative number representing a command that was executed \fInumber\fR
636 commands previously. For example, \fB-1\fR is the previous command.
645 \fIstring\fR indicates the most recently entered command that begins with
646 \fIstring\fR. \fIstring\fR should not contain an \fB=\fR.
651 If \fIfirst\fR is omitted, the previous command is used, unless \fB-l\fR is
652 specified, in which case it defaults to \fB-16\fR and last defaults to
656 If \fIfirst\fR is specified and \fIlast\fR is omitted, then \fIlast\fR defaults
657 to \fIfirst\fR unless \fB-l\fR is specified in which case it defaults to
661 If no editor is specified, then the editor specified by the \fBHISTEDIT\fR
662 variable is used if set, or the \fBFCEDIT\fR variable is used if set,
663 otherwise, \fBed\fR is used.
666 The following options are supported:
670 \fB\fB\fR\fB-e\fR \fIeditor\fR\fR
673 Uses the editor named by \fIeditor\fR to edit the commands. The \fIeditor\fR
674 string is a utility name, subject to search via the \fBPATH\fR variable. The
675 value in the \fBFCEDIT\fR variable is used as a default when \fB-e\fR is not
676 specified. If \fBFCEDIT\fR is null or unset, \fBed\fR is used as the editor.
685 (The letter ell.) Lists the commands rather than invoking an editor on them.
686 The commands is written in the sequence indicated by the \fIfirst\fR and
687 \fIlast\fR operands, as affected by \fB-r\fR, with each command preceded by the
697 Suppresses command numbers when listing with \fB-l\fR.
706 Reverses the order of the commands listed (with \fB-l\fR \fB)\fR or edited
707 (with neither \fB-l\fR nor \fB-s\fR).
716 Re-executes the command without invoking an editor.
721 \fBksh93\fR supports the following options:
725 \fB\fB-e\fR \fIeditor\fR\fR
728 Specify the editor to use to edit the history command. A value of \fB-\fR for
729 \fIeditor\fR is equivalent to specifying the \fB-s\fR option.
738 List the commands rather than editing and re-executing them.
744 \fB\fB-N\fR \fInum\fR\fR
747 Start at \fInum\fR commands back.
756 Suppress the command numbers when the commands are listed.
765 Write the result of history expansion for each operand to standard output. All
766 other options are ignored.
775 Reverse the order of the commands.
784 Re-execute the command without invoking an editor. In this case an operand of
785 the form \fIold=new\fR can be specified to change the first occurrence of the
786 string \fIold\fR in the command to \fInew\fR before re-executing the command.
791 The following operands are supported:
802 Selects the commands to list or edit. The number of previous commands that can
803 be accessed is determined by the value of the \fBHISTSIZE\fR variable. The
804 value of \fIfirst\fR or \fIlast\fR or both is one of the following:
808 \fB[\fB+\fR]\fInumber\fR\fR
811 A positive number representing a command number. Command numbers can be
812 displayed with the \fB-l\fR option.
818 \fB\fB\(mi\fR\fInumber\fR\fR
821 A negative decimal number representing the command that was executed
822 \fInumber\fR of commands previously. For example, \fB\(mi1\fR is the
823 immediately previous command.
832 A string indicating the most recently entered command that begins with that
833 string. If the \fIold=new\fR operand is not also specified with \fB-s\fR, the
834 string form of the \fIfirst\fR operand cannot contain an embedded equal sign.
836 When the synopsis form with \fB-s\fR is used, if \fIfirst\fR is omitted, the
837 previous command is used.
839 For the synopsis forms without \fB-s\fR \fB:\fR
844 If \fIlast\fR is omitted, \fIlast\fR defaults to the previous command when
845 \fB-l\fR is specified; otherwise, it defaults to \fIfirst\fR.
851 If \fIfirst\fR and \fIlast\fR are both omitted, the previous 16 commands is
852 listed or the previous single command is edited (based on the \fB-l\fR option).
858 If \fIfirst\fR and \fIlast\fR are both present, all of the commands from
859 \fIfirst\fR to \fIlast\fR is edited (without \fB-l\fR \fB)\fR or listed (with
860 \fB-l\fR). Editing multiple commands is accomplished by presenting to the
861 editor all of the commands at one time, each command starting on a new line. If
862 \fIfirst\fR represents a newer command than \fIlast\fR, the commands is listed
863 or edited in reverse sequence, equivalent to using \fB-r\fR. For example, the
864 following commands on the first line are equivalent to the corresponding
865 commands on the second:
879 When a range of commands is used, it is not be an error to specify \fIfirst\fR
880 or \fIlast\fR values that are not in the history list. \fBfc\fR substitutes the
881 value representing the oldest or newest command in the list, as appropriate.
882 For example, if there are only ten commands in the history list, numbered 1 to
892 lists and edits, respectively, all ten commands.
902 Replace the first occurrence of string \fIold\fR in the commands to be
903 reexecuted by the string \fInew\fR.
910 When the \fB-l\fR option is used to list commands, the format of each command
911 in the list is as follows:
915 \fB"%d\et%s\en", <\fR\fIline number\fR\fB>, <\fR\fIcommand\fR\fB>\fR
921 If both the \fB-l\fR and \fB-n\fR options are specified, the format of each
926 \fB"\et%s\en", <\fR\fIcommand\fR\fB>\fR
932 If the \fIcommand\fR\fIcommand\fR consists of more than one line, the lines
933 after the first are displayed as:
937 \fB"\et%s\en", <\fR\fIcontinued-command\fR\fB>\fR
943 \fBExample 1 \fRUsing history and fc
951 2 vi passwd 2 vi passwd
960 262 ./SCCS 262 ./SCCS
964 Thu Jul 21 17:29:56 PDT 1994 Thu Jul 21 17:29:56 PDT 1994
966 % $ alias \e!='fc -e -'
969 date alias ='fc -e -'
970 Thu Jul 21 17:29:56 PDT 1994
974 .SH ENVIRONMENT VARIABLES
976 See \fBenviron\fR(5) for descriptions of the following environment variables
977 that affect the execution of \fBfc\fR: \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and
985 This variable, when expanded by the shell, determines the default value for the
986 \fB-e\fR \fIeditor\fR option's \fIeditor\fR option-argument. If \fBFCEDIT\fR is
987 null or unset, \fBed\fR(1) is used as the editor.
996 Determine a pathname naming a command history file. If the \fBHISTFILE\fR
997 variable is not set, the shell can attempt to access or create a file
998 \fB\&.sh_history\fR in the user's home directory. If the shell cannot obtain
999 both read and write access to, or create, the history file, it uses an
1000 unspecified mechanism that allows the history to operate properly. (References
1001 to history ``file'' in this section are understood to mean this unspecified
1002 mechanism in such cases.) \fBfc\fR can choose to access this variable only when
1003 initializing the history file; this initialization occurs when \fBfc\fR or
1004 \fBsh\fR first attempt to retrieve entries from, or add entries to, the file,
1005 as the result of commands issued by the user, the file named by the \fBENV\fR
1006 variable, or a system startup file such as \fB/etc/profile\fR. (The
1007 initialization process for the history file can be dependent on the system
1008 startup files, in that they can contain commands that effectively preempts the
1009 user's settings of \fBHISTFILE\fR and \fBHISTSIZE\fR. For example, function
1010 definition commands are recorded in the history file, unless the \fBset\fR
1011 \fB-o\fR \fBnolog\fR option is set. If the system administrator includes
1012 function definitions in some system startup file called before the \fBENV\fR
1013 file, the history file is initialized before the user gets a chance to
1014 influence its characteristics.) The variable \fBHISTFILE\fR is accessed
1015 initially when the shell is invoked. Any change to \fBHISTFILE\fR does not
1016 take effect until another shell is invoked.
1022 \fB\fBHISTSIZE\fR\fR
1025 Determine a decimal number representing the limit to the number of previous
1026 commands that are accessible. If this variable is unset, an unspecified default
1027 greater than or equal to 128 are used. The variable \fBHISTSIZE\fR is accessed
1028 initially when the shell is invoked. Any changes to \fBHISTSIZE\fR does not
1029 take effect until another shell is invoked.
1034 The following exit values are returned:
1041 Successful completion of the listing.
1055 Otherwise, the exit status is that of the commands executed by \fBfc\fR or
1059 \fBcsh\fR(1), \fBed\fR(1), \fBksh\fR(1), \fBksh93\fR(1), \fBset\fR(1),
1060 \fBsh\fR(1), \fBsource\fR(1), \fBattributes\fR(5),