fc

fc is a small utility that allows you to list, edit and re-execute previous commands entered in an interactive shell. This utility should be included by default with Linux.

Options

  • -e changes the editor to use
  • -l lists the commands instead of calling the editor.
    • -n Removes the command numbers when using -l
    • -r Reverse the order of the listing -l of the edition -e
  • -s re-execute without calling the editor

Usage

The following command opens the editor with the history lines 420 to 423.


$ fc 420 423

The following command execute the lines 420 to 423 without editing.


$ fc -s 420 423

The following command lists the commands 420 to 423 without showing the lines' number and reverse the order


$ fc -l -n -r 420 423

Change the editor

By default, fc will use your system's default editor. Vi is often the system's default and it might give you some trouble. You can use the -e flag to change the browser.


fc -e vim 420 423

To make sure you don't forget the flag or to change it permanently for your user, you can modify your bashrc file.


vim ~/.bashrc

Add the following line. Replace vim by your favorite editor (emacs, nano, etc.)


alias fc="fc -e vim"

Links

Radio Channels

Electronic