Editing the command history

Use the fc Korn shell built-in command to list or edit portions of the command history file.

To select a portion of the file to edit or list, specify the number or the first character or characters of the command. You can specify a single command or range of commands.

If you do not specify an editor program as an argument to the fc Korn shell built-in command, the editor specified by the FCEDIT variable is used. If the FCEDIT variable is not defined, the /usr/bin/ed editor is used. The edited command or commands are printed and run when you exit the editor. Use the printenv command to display the value of the FCEDIT variable.

The following are examples of how to edit the command history:
  • If you want to run the command:
    cd /usr/tmp
    which is very similar to command line 933, at the prompt, type the following:
    fc 933
    At this point, your default editor appears with the command line 933. Change include/sys to tmp, and when you exit your editor, the edited command is run.
  • You can also specify the editor you want to use in the fc command. For example, if you want to edit a command using the /usr/bin/vi editor, at the prompt, type the following:
    fc -e vi 933
    At this point, the vi editor appears with the command line 933.
  • You can also specify a range of commands to edit. For example, if you want to edit the commands 930 through 940, at the prompt, type the following:
    fc 930 940
    At this point, your default editor appears with the command lines 930 through 940. When you exit the editor, all the commands that appear in your editor are run sequentially.