Command Line

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:

uptime

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:

lshw

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:

sudo !!

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.

Closure:

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.

KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

View Comments

Recent Posts

Enable/Disable Your Network Interface

Today we'll cover one way to enable or disable your network interface in the Linux…

6 months ago

Check Your NIC Speed In The Terminal

Today's exercise is a nice and simple exercise where we check your NIC speed in…

6 months ago

Easily Monitor Your Wireless Connection

Have you ever wanted to easily monitor your wireless connection? Well, now you can learn…

6 months ago

Count The Files In A Directory

I think I've covered this before with the ls command but this time we'll count…

6 months ago

Get System Information With The ‘uname’ Command In Linux

Today we'll be learning about a basic Linux command that's known as 'uname' and it…

6 months ago

hardinfo Has Been Rebooted As hardinfo2

If you've used hardinfo in the past, it may interest you to know that hardinfo…

6 months ago