The fc Command

fc stands for either “find command” or “fix command,” since it does both jobs. Use fc -l to list history commands and fc -e to edit them. See the fc entry in the section Built-in Commands in Built-in Commands for more information.

Examples

$ history             List the last 16 commands
$ fc -l 20 30         List commands 20 through 30
$ fc −l −5            List the last five commands
$ fc -l cat           List all commands since the last command beginning with cat
$ fc -l 50            List all commands since command 50
$ fc -ln 5 > doit     Save command 5 to file doit
$ fc -e vi 5 20       Edit commands 5 through 20 using vi
$ fc -e emacs         Edit previous command using emacs

Interactive line editing is easier to use than fc, since you can move up and down in the saved command history using your favorite editor commands (as long as your favorite editor is either vi or Emacs!). You can also use the Up and Down arrow keys to traverse the command history and the right and left arrow keys to move around in the command line.

Get Linux in a Nutshell, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.