Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives.

Fish Shell is preferred to Bash/Zsh. The following content is for Bash/Zsh only.

fzf.history is a better alternative to fc’s core functionality (edit and re-execute command).

Tips & Traps

  1. In Linux shells like Bash and Zsh, fc is a built-in command that stands for “Fix Command”. Its primary purpose is to let you edit and re-execute commands from your history using $EDITOR.

  2. fc -l 1 might throw the error -bash: fc: history specification out of range in bash (some people say that this won’t be an issue in zsh as zsh is smart enough to handle specification out of range but I haven’t verified it yet) if the (absolute) first bash history command has been pruned (due to large number of history commands). HISTTIMEFORMAT="" history | sed -E 's/^[ ]*[0-9]+[ ]*//' is a more robust command for the same purpose.

CommandAction
fcEdit the last shell command using $EDITOR and send it for execution.
fc 123Edit and execute command number 123 from history.
fc gitEdit and execute the last command starting with "git".
fc -lList all history commands.
fc -lnList all history commands without numbers.
fc -ln 100 110List commands from 100 to 110 without numbers.
fc -ln -5List the last 5 historical commands without numbers.
fc -sRe-execute the last command without editing.
fc -s old=newRe-execute the last command, replacing old with new.
fc -s old=new gitRe-execute the last git command, replacing old with new.