Rerun The Previous Terminal Command

Today’s article should be simple enough, where we’ll just be covering how to rerun the previous terminal command. This will be something many new Linux users won’t know about, and may come in handy. If you want to learn how to rerun the previous terminal command, read on!

This is another one of those short articles where I just try to share something basic in hopes of people seeing it. The more advanced Linux users are already aware of this command, but new users are unlikely to know unless they’ve been reading books or taking lessons online somewhere.

So, what we’ll be doing is running a terminal command – but we’re also going to show you how you can use this to modify a previous terminal command. I’ll try to give you an example of when you might want to do so.

It will not be complicated. It should also be remarkably short. I really don’t think I can fluff this out to be all that long… 

So then, let’s learn how to rerun the previous terminal command…

Rerun The Previous Terminal Command:

Obviously, this is going to require an open terminal. That’s easy enough. Just open your favorite terminal or just press CTRL + ALT + T and your default terminal should open.

With your terminal open, let’s check your uptime. To do that, you just run this command, like so:

If you wanted to run the command over again, there are a number of ways to do so. But, we’ll be using ‘!!’ to run it over again. To run uptime over again, just enter this command:

Sure enough, it runs the uptime command all over again. See? You’ve already learned how to rerun the previous terminal command. But, wait, there’s more!

Let’s say you wanted to check out your hardware and you ran this command:

If you pay attention to the output from that command, it suggests you run the program with elevated permissions, like with sudo. To rerun the previous terminal command as sudo, you can just run:

Pretty neat, huh? You can do alsost anything before rerunning the previous terminal command, like changing the directory, making a directory if you forgot to, or adding a command you forgot the first time.


Well, there you have it. It’s another article! I couldn’t make this a longer article, try as I might. That’s okay, you’ve now learned how to rerun the previous terminal command and how to modify it. A short article is better than no article, which is nice!

NOTE: Yes, you can do it in reverse. If you type ‘sudo‘ and hit the enter button, you can then type ‘!! lshw‘ and run the command as ‘sudo lshw‘. It’s pretty neat and not something everyone is aware of. Well, now you know – and knowledge is power!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.