DEV Community

Richard
Richard

Posted on

So you made a typo in the console...

So here is a cool thing you can do in #bash or in any #cli or #commandline that I am aware of.

Here is an example, lets create an arbitrary BASH command with a nice obvious typo in it. I'll create some generic files:

touch cyan-swatch.txt maagenta-swatch.txt yellow-swatch.txt black-swatch.txt
Enter fullscreen mode Exit fullscreen mode

Oops, I made a boo-boo, see it? I mis-spelled the word magenta.

So, most people know you can press the ↑ up-arrow and it will show your last-typed command. But then you have to scroll alllll the way over to where you made the typo and manually remove the extra letter or whatever it is you have to do. But there is a better way!

Wouldn't it be cool if there was a way to tell the CLI, "Hey, I need you to replace this thing with this thing in my last command."

Here it is:

^maagenta^magenta
Enter fullscreen mode Exit fullscreen mode

This command will take the last command, substitute the first string maagenta with magenta, and run the command again.

Latest comments (0)