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:
MacOS fc Options:
Option | Description |
---|---|
-e | Set the editor to be used |
-n | Suppress line numbers |
-l | List lines, but do not execute |
-r | Reverse the order of the lines |
fc Parameters:
Parameter | Description |
---|---|
first | First command to edit/re-execute |
last | Last command to edit/re-execute |
How to use fc command:
Edit and Execute Previous Command
Opens the default text editor to edit and execute the most recent command.
Edit Previous Command by Number
Opens the default text editor to edit and execute the command with the specified number (e.g., 123).
Edit Range of Previous Commands
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
Opens the default text editor to edit and execute the most recent command starting with “ssh”.
Edit and Re-Execute Previous Command
Edits and re-executes the most recent command after editing in the default text editor.
Execute Previous Command Without Editing
Executes the most recent command without opening the default text editor for editing.
Edit Previous Command in Specific Editor
Opens the specified editor (e.g., vim) to edit and execute the most recent command.
Display Help Information
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:
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:
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:
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:
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:
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:
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:
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:
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:
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