Easily Correct a Typo of Previous Command Using Carat (^) Symbol

Have you ever typed a command and rushed to hit Enter, only to find that you had a typo in it? While you can use the up and down arrows to navigate the command history and edit the typo, there’s an easier and faster way.

Don’t Miss: The Power of Linux “History Command” in Bash Shell

In this tip, we shall cover a simple and handy method of dealing with a command line typo, let’s suppose you wanted to see if there’s a service listening on port 22, but accidentally typed nestat instead of netstat.

You can easily replace the typo with the correct command and execute it like so:

# nestat -npltu | grep 22
# ^nestat^netstat

That’s right. Using two carat signs (they should be followed by the typo and the right word, respectively) you can correct the typo and run the command automatically afterwards.

Easily Correct a Typo of Previous Command Using Carat (^) Symbol

Correct Command Typos or Mistakes with Carat (^) Symbol

You must take note that this method only works for the previous command (most recent command executed), when you try to correct a typo for a command executed earlier on, the shell will print out an error.

Summary

This is a great tip that can help you eliminate time wasting tendencies, as you have seen, it is much easier and faster than scrolling through commands history to locate and correct a typo.

All you have to do is correct the typo using the carat signs, hit Enter button and the correct command is executed automatically.

There are possibly several other ways of correcting command line typos, it would be so interesting to learn new ones and you can share any that you have discovered with us via the comment form below.

In the next Linux tip for System administrators, we shall cover how to run a command once at a given time. Until then, stay connected to Tecmint.

Source: tecmint.com

Be the first to comment

Leave a Reply

Your email address will not be published.


*