Raveen Kumar

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:

  1. Viewing command history: You can use fc -l or simply fc to display the list of recently executed commands. By default, it shows the most recent commands with line numbers.

  2. Re-executing a command: You can use fc <line number> to re-execute a specific command from the history. For example, fc 42 will execute the command on line 42 of your history.

  3. Editing and re-executing a command: The fc command allows you to edit a command before executing it. By running fc <line number>, it will open the command in your default text editor (as specified by the FCEDIT or EDITOR environment variable). Once you make the necessary changes and save the file, the modified command will be executed.

  4. 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.

  5. 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 ssh will 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.

#Linux #Bash #Coreutil