LinuxCommandLibrary

fc

list, edit, and re-execute shell commands

TLDR

Edit and rerun last command

$ fc
copy
List recent commands
$ fc -l
copy
List commands with numbers
$ fc -ln [10] [20]
copy
Rerun command by number
$ fc -s [15]
copy
Edit specific command
$ fc [20]
copy

SYNOPSIS

fc [options] [first] [last]

DESCRIPTION

fc is a shell builtin for listing, editing, and re-executing commands from history. It opens commands in an editor for modification before execution, enabling quick fixes to previous commands.
The command can list history entries, open single commands or ranges in an editor, and directly re-execute commands with optional text substitution. The default editor is taken from FCEDIT, EDITOR, or vi.
fc is particularly useful for fixing typos in long commands or re-running complex pipelines with modifications.

PARAMETERS

FIRST

First command (number or string).
LAST
Last command in range.
-l
List commands without editing.
-n
Suppress command numbers in listing.
-r
Reverse order of listing.
-s [OLD=NEW]
Rerun command, optionally with substitution.
-e EDITOR
Use specified editor.

CAVEATS

Only works with interactive shell history. Editing spawns external editor. Substitution syntax is limited. History must be enabled.

HISTORY

fc (fix command) is a POSIX-specified shell builtin present in Korn shell, Bash, and Zsh. It originated in the Korn shell as a way to edit and re-execute command history entries.

SEE ALSO

history(1), bash(1), zsh(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community