Skip to content

fc command in MacOS

The MacOS fc command allows you to edit and re-execute your previously executed commands in the terminal. With options to open the command in your default editor, you can quickly make changes and run it again. This command provides a convenient way to correct mistakes or modify previous commands without retyping entire lines.

fc Syntax:

Terminal window
fc [-e editor] [-nlr] [first [last]]

MacOS fc Options:

OptionDescription
-eSet the editor to be used
-nSuppress line numbers
-lList lines, but do not execute
-rReverse the order of the lines

fc Parameters:

ParameterDescription
firstFirst command to edit/re-execute
lastLast command to edit/re-execute

How to use fc command:

Edit and Execute Previous Command

Terminal window
fc

Opens the default text editor to edit and execute the most recent command.

Edit Previous Command by Number

Terminal window
fc 123

Opens the default text editor to edit and execute the command with the specified number (e.g., 123).

Edit Range of Previous Commands

Terminal window
fc 100 105

Opens the default text editor to edit and execute the commands in the range from 100 to 105.

Edit Command Starting with a Specific String

Terminal window
fc ssh

Opens the default text editor to edit and execute the most recent command starting with “ssh”.

Edit and Re-Execute Previous Command

Terminal window
fc -s

Edits and re-executes the most recent command after editing in the default text editor.

Execute Previous Command Without Editing

Terminal window
fc -e -

Executes the most recent command without opening the default text editor for editing.

Edit Previous Command in Specific Editor

Terminal window
fc -e vim

Opens the specified editor (e.g., vim) to edit and execute the most recent command.

Display Help Information

Terminal window
fc --help

Shows the help information and usage details for the fc command.

How do I use fc in MacOS?

To use the fc command in MacOS, execute the following command:

Terminal window
fc --option <value>

How can I edit a previous command using fc in MacOS?

To edit a previous command using the fc command in MacOS, run the following command:

Terminal window
fc <command>

How can I execute a specific command from my history using fc in MacOS?

To execute a specific command from your history using the fc command in MacOS, use the following syntax:

Terminal window
fc -s <keyword>

How do I list a range of commands using fc in MacOS?

To list a range of commands using the fc command in MacOS, enter the following command:

Terminal window
fc -l <start_command_number> <end_command_number>

How can I repeat the last command in the history using fc in MacOS?

To repeat the last command in the history using the fc command in MacOS, simply type:

Terminal window
fc -e -

How do I reverse the order of commands in the view using fc in MacOS?

To reverse the order of commands in the view when using the fc command in MacOS, run the following command:

Terminal window
fc -R

How can I execute the last command that started with a specific word using fc in MacOS?

To execute the last command that started with a specific word using the fc command in MacOS, use the following command:

Terminal window
fc <word>

How do I edit and execute the last command using fc in MacOS?

To edit and execute the last command using the fc command in MacOS, simply type:

Terminal window
fc

How can I search for a command in the history using a pattern with the fc command in MacOS?

To search for a command in the history using a pattern with the fc command in MacOS, enter the following command:

Terminal window
fc -e -i <pattern>

Applications of the fc command

  • Editing and re-executing previous commands
  • Fixing errors in previous commands
  • Accessing and editing command history
  • Scripting and automating command line tasks