Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Google   


fc command in ksh shell

The internal fc command provides access to your history file. The Korn shell creates a history file containing the commands you have previously entered during your current login session. You use the fc utility to:

*  Display the contents of the history file.
*  Edit (Visually) the contents of the history file.
*  Reexecute previous commands stored in the history file.

Following is the general format of the ksh version of fc command.

     fc      [ -e editor ] [ -lnr ] [ first [ last ] ]
     fc -e - [ old=new ]   [ command ]

history is an alias for fc -l

r is an alias for fc -e -.

The r command is called the repeat command. It searches for a string in the history file that matches the given argument and then executes the entire line in which the string was found.

Options

The following list describes the options and their arguments that may be used to control how fc functions.

First format  
-e editor Use editor editor to edit the commands in the history file. The editing of the history file is referred to as in-line command editing. If you do not specify the -e option, fc checks the value of the FCEDIT variable for an editor name. If FCEDIT is not defined then /bin/ed is used. Valid editors are vi, emacs, gmacs, and ed.
-l List the contents of the history file.
-n Suppress the command numbers when displaying the commands from the history file.
-r Reverse the order of the commands in the history file when they are listed.
-first Beginning command. The number of lines to go back from the last command to start listing out the history file. For example,
                     fc -l -25 # last 25 commands
                     history -25
-last Ending command. The number of lines to go back from the last command to end listing out the history file. For example,
                     fc -l -n -25 -5 # 25 commands ago down to 5 commands ago
                     history -n -25 -5
Second Format  
-e - Reexecutes the previous command in the history file. If you do not specify a command or partial command, then the last command you executed is re- executed. This command is the r alias (alias r="fc -e -").

Arguments

The following list describes the arguments that may be passed to the fc command.

First Format  
first List commands starting at line first in the history file. For instance,
                     fc -l 1 # list all commands (starting from line 1
                     history 1 
last List commands up to line last in the history file. For example,
                     fc -l 20 30
                      history 20 30
  displays lines 20 through 30 of the history file.
Second Format  
old=new Substitutes old string for new string in the appropriate command before reexecuting it.
command The command to reexecute from the history file. Command may be one of the following:
*  Positive number denoting the event number associated with a command.
*  Negative number subtracted from the current command number. The event number of the subtraction is executed.
*  A string. The latest command starting with the string is executed. For instance,
            fc -e c
or 
            r c

searches the history file for the last command that began with a c. 
*  If no command is specified then the previous command is executed.

Variables

There are two variables that control the location and size of the history file. The HISTFILE variable informs the shell where to locate the history file. For example,

     HISTFILE=$HOME/.history

places the history file in your HOME directory in the .history file. If you do not specify a path in the HISTFILE variable, the default for the location is $HOME/.sh_history.

The HISTSIZE variable is used to set the number of commands that are stored in the history file. If you do not set the HISTSIZE variable to some number it defaults to 128. Therefore, the history file will contain the last 128 commands you have entered.

The FCEDIT variable is used to define the editor used to edit your history file. The possible editors are vi, emacs, gmacs, and ed.


 

OPTIONS

OPERANDS

OUTPUT

EXAMPLES

ENVIRONMENT VARIABLES

EXIT STATUS


Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

Last modified: February 28, 2008