Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

fc - process command history list

&pagelevel(4)&pagelevel

The commands issued from an interactive POSIX shell are stored in a history file which can be accessed using the built-in fc command. fc allows you to:

  • edit individual command lines from the history file before they are executed (Format 1)

  • list command lines on standard output (Format 2)

  • change commands before they re-execute, without editing the history file (Format 3)


Syntax


Format 1:fc[ -r][ -e editor][ first[ last]]
Format 2:fc -l[ -nr][ first[ last]]
Format 3:fc -s[ old=new][ first]



Format 1:fc[ -r][ -e editor][ first[ last]]


-r

The commands are made available in reverse order.

-e editor

editor is the name of the editor to be used. If the editor name is not supplied, the value of the variable FCEDIT is used. If FCEDIT is not set, the default editor /usr/bin/ed is invoked.

first[ last]

The range of commands from first to last in the last HISTSIZE commands typed at the terminal is selected for editing and subsequent execution. The first and last arguments may be specified as numbers or as strings.

[+]number

A positive number representing a command number; command numbers can be displayed with the -l option.

-number 

A negative decimal number representing the command that was executed by this many commands previously. For example, -1 is the immediately preceding command.

string

A string is used to select the most recently entered command that begins with this string.


first and last specified

All commands entered between first and last are selected for editing. If first is a more recent command than last, the commands are listed for editing in reverse order (as with option -r).

last not specified

The value for first is used.

first and last not specified

The last (most recent) command is edited.


Format 2:fc -l[ -nr][ first[ last]]


-l

The commands and command numbers are merely written to standard output and can neither be edited nor executed.

-n

Command numbers are suppressed when listed with -l.

-r

Commands are listed in reverse order.

first[ last]

The range of commands from first to last in the last HISTSIZE commands typed at the
terminal is selected for editing and subsequent execution. The first and last arguments
may be specified as numbers or as strings.

[+]number

A positive number representing a command number; command numbers can be displayed with the -l option.

-number

A negative decimal number representing the command that was executed by this many commands previously. For example, -1 is the immediately preceding command.

string

A string is used to select the most recently entered command that begins with this string.


first and last specified

All commands entered between first and last are listed. If first is a more recent command
than last, the commands are listed for editing in reverse order (as with option -r).

last not specified

The previous command is listed.

first and last not specified

The previous 16 commands are listed.


Format 3:fc -s[ old=new][ first]


-s

The commands are re-executed. No editor is invoked.

old=new

The command is modified before being executed. The command is re-executed after new has been substitued for old.

first

All commands since first are executed. See Format 2 for a detailed description.

first not specified
The previous command is used.

Error

sh: /bin/ed: not found
The shell variable FCEDIT is not set to ed.

Variable

HISTFILE

If this variable is set when the POSIX shell is invoked, its value is the path name of the file that will be used to store the command history (see the section “Command re-entry”).

HISTSIZE

If this variable is set when the POSIX shell is invoked, the shell will remember the commands you enter (command history). The number of previously entered commands that are accessible by this shell will be greater than or equal to the given number. The default is 128.

FCEDIT

The name of the standard editor for the built-in fc command.

Locale

The following environment variables affect the execution of fc:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

Example 1

Listing the previous 16 commands: 

$ ls -l

$ fc -s ls=fc

:

is identical to 

$ fc -1

Example 2

Re-executing the previous command: 

$ fc -s

is identical to 

$ fc -s -- -1