Tags: zsh, fc command, command history
This gist provides useful examples and tips on how to utilize the fc command in zsh (Z Shell) to interact with and manipulate your command history effectively.
-
Editing the Previous Command: Open the last command in your default editor to make changes before re-execution.
fc -
Repeating a Specific Command: Execute a specific command from the history without opening an editor.
fc -s 15 -
Deleting a Range of Commands: Delete a range of commands from the history, such as deleting commands 10 to 20.
fc -e : -l 10 -r 20 -d
-
Repeating the Previous Command with sudo: Execute the previous command with sudo privileges.
fc -s sudo !!
-
Editing a Range of Commands: Open a specific range of commands in an editor for modification.
fc -e <editor> -l 5 -r 10
-
Executing the Previous Command with Additional Arguments: Repeat the last command but with some modifications.
fc -s "$(fc -ln -1 | sed 's/original/replacement/')"
-
Executing the nth-to-last Command: Execute the command that is, for example, three commands before the last command.
fc -s -3 -
Deleting the Last Command: Delete the last command from your history.
fc -e : -1
This command deletes the last command from the command history using the
fccommand. The:represents the null editor, and-1specifies the last command.