[Linux] fc command — Life saver!

Matthew Boyd
Oct 14, 2020

--

So you’re typing a very long command manually into command line. You finish writing your command and at the end, you enter the command. Of course, as with everything, it doesn’t go as smoothly as you expect and you get an error. Luckily, you don’t have to ponder what’s wrong as you spot it immediately, however it’s in the dead centre of the command, so you have to go back with the arrow keys to get there… or do you 😯

The fc command will allow you to edit your previous command in your chosen text editor, which you can update with the following command (Ubuntu) sudo update-alternatives --config editor . So lets see this in action.

Let’s say that I’m creating a command to curl localhost on a specific port:

But once I typed my command, I see that I left out the “t” in localhost! 😢

Now if we type fc we can easily amend this!

It opens our command in vim as this is my default text editor, and all I have to do is 2f:which will get us to the colon after s and then press i to get into insert mode and add the missing “t” value, save and quit :wq and the command will automatically execute with the correct value!

--

--

Matthew Boyd
Matthew Boyd

Written by Matthew Boyd

Learning, and posting my findings!

No responses yet