🇮🇷 Iran Proxy | https://www.wikipedia.org/wiki/Fc_(Unix)
Jump to content

fc (Unix)

From Wikipedia, the free encyclopedia
fc
DevelopersVarious open-source and commercial developers
Operating systemUnix, Unix-like
PlatformCross-platform
TypeCommand

fc (short for fix command[1]) 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,[2] 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.[3] The editor used can be specified with the -e option; otherwise it is read from the FCEDIT environment variable,[4] or, in some shells, EDITOR,[5][6][7] 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

[edit]

When invoked with the -l option, the command lists recent lines from the session history:

$ fc -l
1	 pwd
2	 whoami
3	 ls
4    ls -a

When invoked with -s PATTERN, the command re-runs the most recent command matching PATTERN:

$ fc -s ls
ls -a
.  ..  .bash_logout  .bashrc  .profile

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

$ fc -s flod=fold
ls folder

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

$ fc -l
1	 pwd
2	 whoami
3	 ls
4    ls -a
5    ls -la

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

$ fc 1 2
pwd
/home/user
whoami
user
[edit]

See also

[edit]

References

[edit]
  1. ^ "IEEE Std 1003.1-2024 - fc § Rationale". pubs.opengroup.org. Retrieved 2025-04-22.
  2. ^ "The Open Group Base Specifications Issue 8 (IEEE Std 1003.1-2024) - fc § Application Usage". pubs.opengroup.org. Retrieved 2025-04-22.
  3. ^ "Fix history: Edit the last bash command". 5 January 2020.
  4. ^ "IEEE Std 1003.1-2024 - fc § Environment Variables". pubs.opengroup.org. Retrieved 2025-04-22.
  5. ^ "Bash History Builtins (Bash Reference Manual)". www.gnu.org. Retrieved 2025-04-22.
  6. ^ "The Z Shell Manual § 15.6 Parameters Used By The Shell". zsh.sourceforge.io. Retrieved 2025-04-22.
  7. ^ "dash FreeBSD manual page § "Builtins"". man.freebsd.org. Retrieved 2025-04-22.