Edit and re-execute previous commands from your command history.
Syntax fc [-e ename] [-nlr] [first] [last]
fc -s [pat=rep] [cmd] Key -e Editor_Name -n Suppress the command numbers when listing. -l List the commands to standard output. -r Reverse the order of the commands. first String (or number) representing the first command to retrieve from history last String (or number) representing the last command to retrieve from history pat Pattern (string to find) rep Replace (new string) cmd command to retrieve from history (string or number)
First , last and cmd may be specified as a string to locate any command(s) in the history list that begin with that string.
Alternatively they may be given as a number, a numeric index into the history list.
If a negative number is given, this will be used as an offset from the current command -1= last command, -3= third last command etc.
In the first form (fc [-nlr]) a range of commands from first to last is selected from the history list.
In the second form (fc -s) command cmd from the history is re-executed, optionally after each instance of pat is replaced by rep.
Repeat = r
useful alias to use with fc is this:
Alias r="fc -s"
With that alias in place, typing r cc will run the last command beginning with cc
typing r will repeat (re-execute) the last command.
typing r ssh will repeat the last ssh command.
typing r -3 will repeat the third last command.
If last is not specified it is set to the current command for listing (so that fc -l -10 prints the last 10 commands) and to first otherwise.
If first is not specified it is set to the previous command for editing and -16 for listing.
If the -l option is not given, the editor given by ename is invoked on a file containing those commands. If ename is not given, the value of the FCEDIT variable is used, and the value of EDITOR if FCEDIT is not set. If neither variable is set, vi is used. When editing is complete, the edited commands are echoed and executed.
If the first form is used, the return value is 0 unless an invalid option is encountered or first or last specify history lines out of range.
If the -e option is supplied, the return value is the value of the last command executed or failure if an error occurs with the temporary file of commands.
If the second form is used, the return status is that of the command re-executed, unless cmd does not specify a valid history line, in which case fc returns failure.
Move the files Song-1a.mp3 and Song-2b.mp3 to the Archive directory:
$ mv Song-1a.mp3 Archive
$ fc -s 1a=2b
Execute an ls Green after fixing the typo on the seond line:
$ Alias r="fc -s"
$ ls Greeen
$ r Greeen=green ls gre
fc is a bash built in command.
"Power tends to corrupt, absolute power corrupts absolutely" ~ Lord Acton
history - Command History
© Copyright SS64.com 1999-2013
Some rights reserved