{{lowercase}} {{Infobox software | name = fc | logo = | screenshot = | screenshot size = | caption = | author = | developer = Various open-source and commercial developers | released = | latest release version = | latest release date = | operating system = Unix, Unix-like | platform = Cross-platform | genre = Command | license = | website = }} '''{{code|fc}}''' <!-- do not subst template: <code> tag breaks popups --> (short for '''f'''ix '''c'''ommand<ref name="rationale">{{Cite web |title=IEEE Std 1003.1-2024 - fc § Rationale |url=https://pubs.opengroup.org/onlinepubs/9799919799/utilities/fc.html#tag_20_44_18 |access-date=2025-04-22 |website=pubs.opengroup.org}}</ref>) is a shell command that lists, edits and re-executes commands previously entered in the shell. It is particularly helpful for editing complex, multi-line commands. Originally developed for Unix and standardized by POSIX, the command is available in many operating systems today.

As it is required to be "intrinsic" by POSIX,<ref>{{Cite web |title=The Open Group Base Specifications Issue 8 (IEEE Std 1003.1-2024) - fc § Application Usage|url=https://pubs.opengroup.org/onlinepubs/9799919799/utilities/fc.html#tag_20_44_16 |access-date=2025-04-22 |website=pubs.opengroup.org}}</ref> it is implemented as a builtin in the Bash, Zsh, and Almquist shells.

Invoked with no options, the command opens a text editor, allowing the user to modify the last-run command. Upon exiting the editor, the modified command is executed in the current shell.<ref>{{Cite web | url=https://stavshamir.github.io/bash/fix-history-edit-the-last-bash-command/ | title=Fix history: Edit the last bash command | date=5 January 2020 }}</ref> The editor used can be specified with the {{code|-e}} option; otherwise it is read from the ''FCEDIT'' environment variable,<ref name="envvars">{{Cite web |title=IEEE Std 1003.1-2024 - fc § Environment Variables |url=https://pubs.opengroup.org/onlinepubs/9799919799/utilities/fc.html#tag_20_44_08 |access-date=2025-04-22 |website=pubs.opengroup.org}}</ref> or, in some shells, ''EDITOR'',<ref name="bash-fc">{{Cite web |title=Bash History Builtins (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-History-Builtins.html#index-fc |access-date=2025-04-22 |website=www.gnu.org}}</ref><ref>{{Cite web |title=The Z Shell Manual § 15.6 Parameters Used By The Shell |url=https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-FCEDIT |access-date=2025-04-22 |website=zsh.sourceforge.io}}</ref><ref name="dash-builtins">{{Cite web | title=dash FreeBSD manual page § "Builtins" |url=https://man.freebsd.org/cgi/man.cgi?query=dash&manpath=FreeBSD+14.2-RELEASE+and+Ports#DESCRIPTION |access-date=2025-04-22 |website=man.freebsd.org}}</ref> with a fallback to vi or ed. Command-line options allow for quick substitution, repetition or modification of a specific command from the session history, or a range of commands from the history.

== Examples == When invoked with the <code>-l</code> option, the command lists recent lines from the session history:

<syntaxhighlight lang="console"> $ fc -l 1 pwd 2 whoami 3 ls 4 ls -a </syntaxhighlight>

When invoked with <code>-s PATTERN</code>, the command re-runs the most recent command matching ''PATTERN'':

<syntaxhighlight lang="console"> $ fc -s ls ls -a . .. .bash_logout .bashrc .profile </syntaxhighlight>

Option <code>-s</code> enables inline substitution. For example, consider that the last command {{code |ls floder}} contains a typo. The following command runs the last command with "flod" replaced with "fold":

<syntaxhighlight lang="console"> $ fc -s flod=fold ls folder </syntaxhighlight>

It is also possible to edit and re-invoke a range of commands from the history. Often, one lists commands first like:

<syntaxhighlight lang="console"> $ fc -l 1 pwd 2 whoami 3 ls 4 ls -a 5 ls -la </syntaxhighlight>

Then, to run the commands identified as 1 and 2:

<syntaxhighlight lang="console"> $ fc 1 2 pwd /home/user whoami user </syntaxhighlight>

== External links == *{{man|cu|fc|SUS|process the command history list}}

== See also == * List of POSIX commands

== References == {{Reflist}} {{Unix commands}}

Category:Standard Unix programs Category:Unix SUS2008 utilities