The fc
command in Bash is used to list, edit, and re-execute commands from the shell’s history. It allows users to modify previous commands before running them again, making it a powerful tool for improving efficiency in the command line.
The basic syntax of the fc
command is as follows:
fc [options] [arguments]
-l
: List the commands in the history.-r
: Reverses the order of the commands when listing.-s
: Re-execute the command without opening an editor.-n
: Suppress the command numbers when listing.To list the last 10 commands from your history:
fc -l -n -10
To edit the command with history number 42:
fc 42
This will open the command in your default text editor for modification.
To re-execute the last command without editing:
fc -s
To list the last 5 commands in reverse order:
fc -r -l -5
fc -s
to quickly rerun the last command without needing to edit it, which can save time.fc
will open commands in that editor for editing.fc
with other commands like grep
to filter through your command history for specific tasks. For example, fc -l | grep 'git'
will show all previous Git commands.