1history(1) User Commands history(1)
2
3
4
6 history, fc, hist - process command history list
7
9 /usr/bin/fc [-r] [-e editor] [first [last]]
10
11
12 /usr/bin/fc -l [-nr] [first [last]]
13
14
15 /usr/bin/fc -s [old=new] [first]
16
17
18 csh
19 history [-hr] [n]
20
21
22 ksh
23 fc -e - [old=new] [command]
24
25
26 fc -s [old = new] [command]
27
28
29 fc [-e ename] [-nlr] [first [last]]
30
31
32 ksh93
33 hist [-lnprs] [-e editor][-N num][first[last]]
34
35
37 /usr/bin/fc
38 The fc utility lists or edits and reexecutes, commands previously
39 entered to an interactive sh.
40
41
42 The command history list references commands by number. The first num‐
43 ber in the list is selected arbitrarily. The relationship of a number
44 to its command does not change except when the user logs in and no
45 other process is accessing the list, at which time the system can reset
46 the numbering to start the oldest retained command at another number
47 (usually 1). When the number reaches the value in HISTSIZE or 32767
48 (whichever is greater), the shell can wrap the numbers, starting the
49 next command with a lower number (usually 1). However, despite this
50 optional wrapping of numbers, fc maintains the time-ordering sequence
51 of the commands. For example, if four commands in sequence are given
52 the numbers 32 766, 32 767, 1 (wrapped), and 2 as they are executed,
53 command 32 767 is considered the command previous to 1, even though its
54 number is higher.
55
56
57 When commands are edited (when the -l option is not specified), the
58 resulting lines is entered at the end of the history list and then
59 reexecuted by sh. The fc command that caused the editing is not entered
60 into the history list. If the editor returns a non-zero exit status,
61 this suppresses the entry into the history list and the command reexe‐
62 cution. Any command-line variable assignments or redirection operators
63 used with fc affects both the fc command itself as well as the command
64 that results, for example:
65
66 fc -s -- -1 2>/dev/null
67
68
69
70
71 reinvokes the previous command, suppressing standard error for both fc
72 and the previous command.
73
74 csh
75 Display the history list. If n is given, display only the n most recent
76 events.
77
78 -r Reverse the order of printout to be most recent first rather than
79 oldest first.
80
81
82 -h Display the history list without leading numbers. This is used to
83 produce files suitable for sourcing using the -h option to the
84 csh built-in command, source(1).
85
86
87 History Substitution:
88 History substitution allows you to use words from previous command
89 lines in the command line you are typing. This simplifies spelling cor‐
90 rections and the repetition of complicated commands or arguments. Com‐
91 mand lines are saved in the history list, the size of which is con‐
92 trolled by the history variable. The history shell variable can be set
93 to the maximum number of command lines that is saved in the history
94 file, that is:
95
96 set history = 200
97
98
99
100 allows the history list to keep track of the most recent 200 command
101 lines. If not set, the C shell saves only the most recent command.
102
103
104 A history substitution begins with a ! (although you can change this
105 with the histchars variable) and can occur anywhere on the command
106 line; history substitutions do not nest. The ! can be escaped with \ to
107 suppress its special meaning.
108
109
110 Input lines containing history substitutions are echoed on the terminal
111 after being expanded, but before any other substitutions take place or
112 the command gets executed.
113
114 Event Designators:
115 An event designator is a reference to a command line entry in the his‐
116 tory list.
117
118 !
119
120 Start a history substitution, except when followed by a space char‐
121 acter, tab, newline, = or (.
122
123
124 !!
125
126 Refer to the previous command. By itself, this substitution repeats
127 the previous command.
128
129
130 !n
131
132 Refer to command line n.
133
134
135 !-n
136
137 Refer to the current command line minus n.
138
139
140 !str
141
142 Refer to the most recent command starting with str.
143
144
145 !?str?
146
147 Refer to the most recent command containing str.
148
149
150 !?str? additional
151
152 Refer to the most recent command containing str and append addi‐
153 tional to that referenced command.
154
155
156 !{command} additional
157
158 Refer to the most recent command beginning with command and append
159 additional to that referenced command.
160
161
162 ^previous_word^replacement^
163
164 Repeat the previous command line replacing the string previous_word
165 with the string replacement. This is equivalent to the history sub‐
166 stitution:
167
168 Repeat the previous command line replacing the string previous_word
169 with the string replacement. This is equivalent to the history sub‐
170 stitution:
171
172 !:s/previous_word/replacement/.
173
174 To re-execute a specific previous command and make such a substitu‐
175 tion, say, re-executing command #6:
176
177 !:6s/previous_word/replacement/.
178
179
180
181 Word Designators:
182 A `:' (colon) separates the event specification from the word designa‐
183 tor. 2It can be omitted if the word designator begins with a ^, $, *, −
184 or %. If the word is to be selected from the previous command, the sec‐
185 ond ! character can be omitted from the event specification. For
186 instance, !!:1 and !:1 both refer to the first word of the previous
187 command, while !!$ and !$ both refer to the last word in the previous
188 command. Word designators include:
189
190 # The entire command line typed so far.
191
192
193 0 The first input word (command).
194
195
196 n The n'th argument.
197
198
199 ^ The first argument, that is, 1.
200
201
202 $ The last argument.
203
204
205 % The word matched by (the most recent) ?s search.
206
207
208 x−y A range of words; −y abbreviates 0−y.
209
210
211 * All the arguments, or a null value if there is just one word
212 in the event.
213
214
215 x* Abbreviates x−$.
216
217
218 x− Like x* but omitting word $.
219
220
221 Modifiers:
222 After the optional word designator, you can add a sequence of one or
223 more of the following modifiers, each preceded by a :.
224
225 h Remove a trailing pathname component, leav‐
226 ing the head.
227
228
229 r Remove a trailing suffix of the form
230 `.xxx', leaving the basename.
231
232
233 e Remove all but the suffix, leaving the
234 extension.
235
236
237 s/oldchars/replacements/ Substitute replacements for oldchars. old‐
238 chars is a string that can contain embedded
239 blank spaces, whereas previous_word in the
240 event designator can not.
241
242 ^oldchars^replacements^
243
244
245
246 t Remove all leading pathname components,
247 leaving the tail.
248
249
250 & Repeat the previous substitution.
251
252
253 g Apply the change to the first occurrence of
254 a match in each word, by prefixing the
255 above (for example, g&).
256
257
258 p Print the new command but do not execute
259 it.
260
261
262 q Quote the substituted words, escaping fur‐
263 ther substitutions.
264
265
266 x Like q, but break into words at each space
267 character, tab or newline.
268
269
270
271 Unless preceded by a g, the modification is applied only to the first
272 string that matches oldchars. An error results if no string matches.
273
274
275 The left-hand side of substitutions are not regular expressions, but
276 character strings. Any character can be used as the delimiter in place
277 of /. A backslash quotes the delimiter character. The character &, in
278 the right hand side, is replaced by the text from the left-hand-side.
279 The & can be quoted with a backslash. A null oldchars uses the previous
280 string either from a oldchars or from a contextual scan string s from
281 !?s. You can omit the rightmost delimiter if a newline immediately fol‐
282 lows replacements; the rightmost ? in a context scan can similarly be
283 omitted.
284
285
286 Without an event specification, a history reference refers either to
287 the previous command, or to a previous history reference on the command
288 line (if any).
289
290 ksh
291 Using fc, in the form of
292
293 fc -e − [old=new] [command],
294
295
296
297
298 or
299
300 fc -s [old=new] [command],
301
302
303
304
305 the command is re-executed after the substitution old=new is performed.
306 If there is not a command argument, the most recent command typed at
307 this terminal is executed.
308
309
310 Using fc in the form of
311
312 fc [-e ename] [-nlr ] [first [last]],
313
314
315
316
317 a range of commands from first to last is selected from the last HIST‐
318 SIZE commands that were typed at the terminal. The arguments first and
319 last can be specified as a number or as a string. A string is used to
320 locate the most recent command starting with the given string. A nega‐
321 tive number is used as an offset to the current command number. If the
322 -l flag is selected, the commands are listed on standard output. Other‐
323 wise, the editor program -e name is invoked on a file containing these
324 keyboard commands. If ename is not supplied, then the value of the
325 variable FCEDIT (default /bin/ed) is used as the editor. When editing
326 is complete, the edited command(s) is executed. If last is not speci‐
327 fied, it is set to first. If first is not specified, the default is the
328 previous command for editing and −16 for listing. The flag -r reverses
329 the order of the commands and the flag -n suppresses command numbers
330 when listing. (See ksh(1) for more about command line editing.)
331
332 HISTFILE If this variable is set when the shell is invoked, then the
333 value is the pathname of the file that is used to store the
334 command history.
335
336
337 HISTSIZE If this variable is set when the shell is invoked, then the
338 number of previously entered commands that are accessible
339 by this shell is greater than or equal to this number. The
340 default is 128.
341
342
343 Command Re-entry:
344 The text of the last HISTSIZE (default 128) commands entered from a
345 terminal device is saved in a history file. The file $HOME/.sh_history
346 is used if the HISTFILE variable is not set or if the file it names is
347 not writable. A shell can access the commands of all interactive shells
348 which use the same named HISTFILE. The special command fc is used to
349 list or edit a portion of this file. The portion of the file to be
350 edited or listed can be selected by number or by giving the first char‐
351 acter or characters of the command. A single command or range of com‐
352 mands can be specified. If you do not specify an editor program as an
353 argument to fc then the value of the variable FCEDIT is used. If FCEDIT
354 is not defined then /bin/ed is used. The edited command(s) is printed
355 and re-executed upon leaving the editor. The editor name − is used to
356 skip the editing phase and to re-execute the command. In this case a
357 substitution parameter of the form old=new can be used to modify the
358 command before execution. For example, if r is aliased to a´fc -e − a´
359 then typing `r bad=good c' re-executes the most recent command which
360 starts with the letter c, replacing the first occurrence of the string
361 bad with the string good.
362
363
364 Using the fc built-in command within a compound command causes the
365 whole command to disappear from the history file.
366
367 ksh93
368 hist lists, edits, or re-executes commands previously entered into the
369 current shell environment.
370
371
372 The command history list references commands by number. The first num‐
373 ber in the list is selected arbitrarily. The relationship of a number
374 to its command does not change during a login session. When the number
375 reaches 32767 the number wraps around to 1 but maintains the ordering.
376
377
378 When the l option is not specified, and commands are edited, the
379 resulting lines are entered at the end of the history list and then re-
380 executed by the current shell. The hist command that caused the editing
381 is not entered into the history list. If the editor returns a non-zero
382 exit status, this suppresses the entry into the history list and the
383 command re-execution. Command line variable assignments and redirec‐
384 tions affect both the hist command and the commands that are re-exe‐
385 cuted.
386
387
388 first and last define the range of commands. Specify first and last as
389 one of the following:
390
391 number A positive number representing a command number. A + sign
392 can precede number.
393
394
395 -number A negative number representing a command that was executed
396 number commands previously. For example, -1 is the previous
397 command.
398
399
400 string string indicates the most recently entered command that
401 begins with string. string should not contain an =.
402
403
404
405 If first is omitted, the previous command is used, unless -l is speci‐
406 fied, in which case it defaults to -16 and last defaults to -1.
407
408
409 If first is specified and last is omitted, then last defaults to first
410 unless -l is specified in which case it defaults to -1.
411
412
413 If no editor is specified, then the editor specified by the HISTEDIT
414 variable is used if set, or the FCEDIT variable is used if set, other‐
415 wise, ed is used.
416
418 The following options are supported:
419
420 -e editor Uses the editor named by editor to edit the commands. The
421 editor string is a utility name, subject to search via the
422 PATH variable. The value in the FCEDIT variable is used as
423 a default when -e is not specified. If FCEDIT is null or
424 unset, ed is used as the editor.
425
426
427 -l (The letter ell.) Lists the commands rather than invoking
428 an editor on them. The commands is written in the sequence
429 indicated by the first and last operands, as affected by
430 -r, with each command preceded by the command number.
431
432
433 -n Suppresses command numbers when listing with -l.
434
435
436 -r Reverses the order of the commands listed (with -l ) or
437 edited (with neither -l nor -s).
438
439
440 -s Re-executes the command without invoking an editor.
441
442
443 ksh93
444 ksh93 supports the following options:
445
446 -e editor Specify the editor to use to edit the history command. A
447 value of - for editor is equivalent to specifying the -s
448 option.
449
450
451 -l List the commands rather than editing and re-executing
452 them.
453
454
455 -N num Start at num commands back.
456
457
458 -n Suppress the command numbers when the commands are listed.
459
460
461 -p Write the result of history expansion for each operand to
462 standard output. All other options are ignored.
463
464
465 -r Reverse the order of the commands.
466
467
468 -s Re-execute the command without invoking an editor. In this
469 case an operand of the form old=new can be specified to
470 change the first occurrence of the string old in the com‐
471 mand to new before re-executing the command.
472
473
475 The following operands are supported:
476
477 first Selects the commands to list or edit. The number of previous
478 last commands that can be accessed is determined by the value of
479 the HISTSIZE variable. The value of first or last or both is
480 one of the following:
481
482 [+]number A positive number representing a command number.
483 Command numbers can be displayed with the -l
484 option.
485
486
487 −number A negative decimal number representing the com‐
488 mand that was executed number of commands previ‐
489 ously. For example, −1 is the immediately previ‐
490 ous command.
491
492
493 string A string indicating the most recently entered
494 command that begins with that string. If the
495 old=new operand is not also specified with -s,
496 the string form of the first operand cannot con‐
497 tain an embedded equal sign.
498
499 When the synopsis form with -s is used, if first
500 is omitted, the previous command is used.
501
502 For the synopsis forms without -s :
503
504 o If last is omitted, last defaults to
505 the previous command when -l is spec‐
506 ified; otherwise, it defaults to
507 first.
508
509 o If first and last are both omitted,
510 the previous 16 commands is listed or
511 the previous single command is edited
512 (based on the -l option).
513
514 o If first and last are both present,
515 all of the commands from first to
516 last is edited (without -l ) or
517 listed (with -l). Editing multiple
518 commands is accomplished by present‐
519 ing to the editor all of the commands
520 at one time, each command starting on
521 a new line. If first represents a
522 newer command than last, the commands
523 is listed or edited in reverse
524 sequence, equivalent to using -r. For
525 example, the following commands on
526 the first line are equivalent to the
527 corresponding commands on the second:
528
529 fc -r 10 20 fc 30 40
530 fc 20 10 fc -r 40 30
531
532
533 o When a range of commands is used, it
534 is not be an error to specify first
535 or last values that are not in the
536 history list. fc substitutes the
537 value representing the oldest or new‐
538 est command in the list, as appropri‐
539 ate. For example, if there are only
540 ten commands in the history list,
541 numbered 1 to 10:
542
543 fc -l
544 fc 1 99
545
546 lists and edits, respectively, all
547 ten commands.
548
549
550 old=new Replace the first occurrence of string old in
551 the commands to be reexecuted by the string new.
552
553
554
556 When the -l option is used to list commands, the format of each command
557 in the list is as follows:
558
559 "%d\t%s\n", <line number>, <command>
560
561
562
563 If both the -l and -n options are specified, the format of each command
564 is:
565
566 "\t%s\n", <command>
567
568
569
570 If the commandcommand consists of more than one line, the lines after
571 the first are displayed as:
572
573 "\t%s\n", <continued-command>
574
575
577 Example 1 Using history and fc
578
579 csh ksh
580
581 % history $ fc -l
582 1 cd /etc 1 cd /etc
583 2 vi passwd 2 vi passwd
584 3 date 3 date
585 4 cd 4 cd
586 5 du . 5 du .
587 6 ls -t 6 ls -t
588 7 history 7 fc -l
589
590 % !d $ fc -e - d
591 du . du .
592 262 ./SCCS 262 ./SCCS
593 336 . 336 .
594
595 % !da $ fc -e - da
596 Thu Jul 21 17:29:56 PDT 1994 Thu Jul 21 17:29:56 PDT 1994
597
598 % $ alias \!='fc -e -'
599
600 % !! $ !
601 date alias ='fc -e -'
602 Thu Jul 21 17:29:56 PDT 1994
603
604
606 See environ(5) for descriptions of the following environment variables
607 that affect the execution of fc: LC_CTYPE, LC_MESSAGES, and NLSPATH.
608
609 FCEDIT This variable, when expanded by the shell, determines the
610 default value for the -e editor option's editor option-
611 argument. If FCEDIT is null or unset, ed(1) is used as the
612 editor.
613
614
615 HISTFILE Determine a pathname naming a command history file. If the
616 HISTFILE variable is not set, the shell can attempt to
617 access or create a file .sh_history in the user's home
618 directory. If the shell cannot obtain both read and write
619 access to, or create, the history file, it uses an unspeci‐
620 fied mechanism that allows the history to operate properly.
621 (References to history ``file'' in this section are under‐
622 stood to mean this unspecified mechanism in such cases.) fc
623 can choose to access this variable only when initializing
624 the history file; this initialization occurs when fc or sh
625 first attempt to retrieve entries from, or add entries to,
626 the file, as the result of commands issued by the user, the
627 file named by the ENV variable, or a system startup file
628 such as /etc/profile. (The initialization process for the
629 history file can be dependent on the system startup files,
630 in that they can contain commands that effectively preempts
631 the user's settings of HISTFILE and HISTSIZE. For example,
632 function definition commands are recorded in the history
633 file, unless the set -o nolog option is set. If the system
634 administrator includes function definitions in some system
635 startup file called before the ENV file, the history file
636 is initialized before the user gets a chance to influence
637 its characteristics.) The variable HISTFILE is accessed
638 initially when the shell is invoked. Any changes to HIST‐
639 FILE does not take effect until another shell is invoked.
640
641
642 HISTSIZE Determine a decimal number representing the limit to the
643 number of previous commands that are accessible. If this
644 variable is unset, an unspecified default greater than or
645 equal to 128 are used. The variable HISTSIZE is accessed
646 initially when the shell is invoked. Any changes to HIST‐
647 SIZE does not take effect until another shell is invoked.
648
649
651 The following exit values are returned:
652
653 0 Successful completion of the listing.
654
655
656 >0 An error occurred.
657
658
659
660 Otherwise, the exit status is that of the commands executed by fc or
661 hist.
662
664 See attributes(5) for descriptions of the following attributes:
665
666
667
668
669 ┌─────────────────────────────┬─────────────────────────────┐
670 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
671 ├─────────────────────────────┼─────────────────────────────┤
672 │Availability │SUNWcsu │
673 └─────────────────────────────┴─────────────────────────────┘
674
676 csh(1), ed(1), ksh(1), ksh93(1), set(1), set(1F), sh(1), source(1),
677 attributes(5), environ(5)
678
679
680
681SunOS 5.11 2 Nov 2007 history(1)