The fc and hist Commands
"fc" stands for either
“find command” or “fix command,” since it does both jobs. Use
fc -l to list history commands
and fc -e to edit them. See the
fc entry in the later section “Built-in Commands
(Bash and Korn Shells),” for more information.
In ksh93, the fc command has been renamed hist, and alias
fc=hist is predefined.
Examples
$historyList the last 16 commands $fc -l 20 30List commands 20 through 30 $fc -l -5List the last 5 commands $fc -l catList all commands since the last command beginning with cat $fc -l 50List all commands since command 50 $fc -ln 5 > doitSave command 5 to file doit $fc -e vi 5 20Edit commands 5 through 20 using vi $fc -e emacsEdit previous command using emacs
The following only work in the Korn shell, which predefines the r alias:
$rReexecute previous command $r catReexecute last cat command $r doc=DocSubstitute, then reexecute last command $r chap=doc cReexecute last command that begins with c, but change string chap to doc
For both shells, the interactive line-editing is easier to use than fc, since you can move up and down in the saved command history using your favorite editor commands (as long as your favorite editor is either vi or Emacs!). Current versions of both shells also let you use the Up and Down arrow keys to traverse the command history.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access