Misplaced Pages

fc (Unix)

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Fc" Unix – news · newspapers · books · scholar · JSTOR (August 2013) (Learn how and when to remove this message)
fc
Developer(s)Various open-source and commercial developers
Operating systemUnix, Unix-like
PlatformCross-platform
TypeCommand

fc is a standard program on Unix and Unix-like operating systems that lists, edits and reexecutes commands previously entered to an interactive shell. fc is a builtin command in the Bash and Zsh shells and is an initialism for "fix command". It is particularly helpful for editing complex, multi-line commands. The editor can be specified by setting the EDITOR (changes the default editor) or the FCEDIT environment variable.

Examples

Flag -l used to list previous command history, with example showing command ls as item 1001 in the user's history.

$ fc -l
1001 ls

Flag -s with this index would then recall the history command from 1001:

$ fc -s 1001
ls

Though more powerfully, -s enables inline substitution.

$ ls floder # user typo
$ fc -s ^floder^folder^ # Command revised and runs with correction
ls folder

Most powerfully, executing fc on its own edits the last command executed. Editor can be specified on command line (-e) or via environment variable FCEDIT. User is thus able to fully modify the last command executed via the editor, upon exiting will execute the resultant command.

$ fc # Change 'ls' to 'ls -la' in editor and exit
ls -la

See also

References

  1. "Fix history: Edit the last bash command". 5 January 2020.

External links

Unix command-line interface programs and shell builtins
File system
Processes
User environment
Text processing
Shell builtins
Searching
Documentation
Software development
Miscellaneous
Stub icon

This Unix-related article is a stub. You can help Misplaced Pages by expanding it.

Categories: