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

Take Your Linux Skills to the Next Level All courses, certifications, ad-free articles & community — from $8/mo
Join Root →
Ad-free access to all premium articles
Access to all courses: Learn Linux, AI for Linux, Bash Scripting, Ubuntu Handbook, Golang and more.
Access to Linux certifications (RHCSA, RHCE, LFCS and LFCA)
Access new courses on release
Get access to weekly newsletter
Priority help in comments
Private Telegram community
Connect with the Linux community
From $8/mo · or $59/yr billed annually · Cancel anytime

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.

Correct Command Typos or Mistakes with 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.

Root Plan
Premium Linux Education for Serious Learners

Take Your Linux Skills to the Next Level

Root members get full access to every course, certification prep track, and a growing library of hands-on Linux content — with new courses added every month.

What You Get
Ad-free access to all premium articles
Access to all courses: Learn Linux, AI for Linux, Bash Scripting, Ubuntu Handbook, Golang and more.
Access to Linux certifications (RHCSA, RHCE, LFCS and LFCA)
Access new courses on release
Get access to weekly newsletter
Priority help in comments
Private Telegram community
Connect with the Linux community
Gabriel Cánepa
Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

11 Comments

Leave a Reply
  1. @All,
    Feel free to use this tip if it is helpful. If you feel more comfortable using the arrow keys and correcting the command, feel free to do so as well. This was just a tip :)

    Reply
  2. Very good to know! Thanks a lot! We can even do more simpler than that.
    For instance:
    $ nestat -npltu | grep 22
    $ ^ne^net

    Reply
  3. I see the benefit if you are using many pipes or parameters, but it still only works for the most recent command. I think I would still simply use the up arrow once and a correction rather than typing the carat mistype, carat, and correct command.

    Reply
  4. Seems like it would be simpler to type the correct command. Instead of a carat, the mistype, a carat, and then the correct command

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Root Plan Premium Linux Education for Serious Learners

Before You Go - Upgrade Your Linux Skills

Root members get everything in one place, with new courses added every month.

What You Get
Ad-free access to all premium articles
Access to all courses: Learn Linux, AI for Linux, Bash Scripting, Ubuntu Handbook, Golang and more.
Linux certifications: RHCSA, RHCE, LFCS and LFCA
Access new courses on release
Weekly newsletter, priority support & Telegram community
Join Root Today and Start Learning Linux the Right Way
Structured courses, certification prep, and a community of Linux professionals - all in one membership.
Join Root Plan →
$8/mo · or $59/yr billed annually