Linux and Unix fc and history command
Quick links
About fc and history
Syntax
Examples
Related commands
Linux and Unix main page
The 'fc' utility lists or edits and re-executes, commands previously entered to an interactive sh.
The 'history' utility allows you to use words from previous command lines in the command line you are typing. This simplifies spelling corrections and the repetition of complicated commands or arguments.
CSH - C SHELL
history [-h] [-r] [n]
| ! | Start a history substitution, except when followed by a space character, tab, newline, = or (. |
| !! | Runs the last command that you ran. |
| !10 | Re-run line number 10 in the history. |
| !-n | Refer to the current command line minus n. |
| !?str? | Refer to the most recent command containing str (string). |
| !str | Re runs the last command that you ran that starts with str (string). |
KSH - KORN SHELL
fc [-e editor] [-n] [-l] [-r] [-s] [ first [ last ] ]
| -e editor | Use the editor named by editor to edit the commands. The editor string is a utility name, subject to search via the PATH variable. The value in the FCEDIT variable is used as a default when -e is not specified. If FCEDIT is null or unset, ed will be used as the editor. | ||||||
| -n | Suppress command numbers when listing with -l. | ||||||
| -l | List the commands rather than invoking an editor on them. The commands will be written in the sequence indicated by the first and last operands, as affected by -r, with each command preceded by the command number. | ||||||
| -r | Reverse the order of printout to be most recent first rather than oldest first. | ||||||
| -s | Re-execute the command without invoking an editor. | ||||||
| first [last] | Select the commands to list or edit. The number of previous commands that can be accessed is determined by the value of the HISTSIZE variable.
The value of first or last or both will be one of the following:
|
Fc:
fc -l
Would list the history of commands on the computer similar to the following:
2 grep --help
3 bg
4 fg
5 pine
6 cd public_html
7 rm index.html
8 sz index.html
9 ls -laxo
10 chmod 755 index.htm
fc -e - ls
Would execute the last ls command.
History:
history
Typing history alone would give results similar to the following:
2 grep --help
3 bg
4 fg
5 pine
6 cd public_html
7 rm index.html
8 sz index.html
9 ls -laxo
10 chmod 755 index.htm
!ls - Would execute the last ls command.
!! - Would execute the last command executed.
See the Unix shortcut page for additional shortcuts that can be used in Unix / Linux.
