fc fix command or fix previous command
In Bash, fc stands for “fix command” and it is a built-in command that allows you to work with the command history. The fc command provides a way to view, edit, and re-execute commands from your command history.
Here are some common uses of the fc command:
-
Viewing command history: You can use
fc -lor simplyfcto display the list of recently executed commands. By default, it shows the most recent commands with line numbers. -
Re-executing a command: You can use
fc <line number>to re-execute a specific command from the history. For example,fc 42will execute the command on line 42 of your history. -
Editing and re-executing a command: The
fccommand allows you to edit a command before executing it. By runningfc <line number>, it will open the command in your default text editor (as specified by theFCEDITorEDITORenvironment variable). Once you make the necessary changes and save the file, the modified command will be executed. -
Executing a range of commands: If you want to execute a range of commands from your history, you can use
fc <start line number> <end line number>. This will execute all the commands between the specified start and end line numbers. -
Using a pattern to select commands:
fc -e <pattern>allows you to select and execute commands that match a specific pattern. For example,fc -e sshwill execute the most recent command from your history that contains the word “ssh”.
These are just a few examples of how the fc command can be used in Bash. It provides a convenient way to manage and interact with your command history, allowing you to quickly access and modify previously executed commands.