How To: Login To SSH To Run One Command

In today’s article, we’re going to learn how to login to SSH to run one command. Yes, it’s another SSH article! However, this one should be relatively short. I’ve covered SSH a great deal already. This is just one more SSH trick.

SSH stands for Secure Shell and is a way to remotely control other computers. As I said in the opening paragraph, I’ve already covered a lot of SSH articles, because SSH is a tool I use regularly and it’s a tool I really like.

SSH lets me manage computers on the other side of the country without even leaving my chair. I also use SSH to manage various computers around my house. If I need to do something on a computer in another room, I can just SSH into it and do what I needed to do. It’s great!

Well, today’s SSH article is a bit different. We’re going to login to SSH to run one command. That’s all we’re going to do. We’ll login, automatically run the command, and then automatically exit the SSH connection. This is useful if you want to run a script, update, etc…

There are some previous SSH articles that you might want to read:

Install SSH to Remotely Control Your Linux Computers
Prevent SSH Root Login
Show Failed SSH Login Attempts

Alternatively, you can click to search for SSH articles. I’ve covered quite a bit of SSH material, so you can learn quite a bit from those links – even if you’re already familiar with SSH.

Well then, let’s just jump into the article… It really shouldn’t take long.

Login To SSH To Run One Command:

Like oh so many articles, and this one involving SSH, you’re going to need to start off with a terminal. You’ll also need a device that has SSH properly setup and ready to run. You can actually set SSH up on the computer you’re using and just SSH into localhost to practice this.

And, of course, if you don’t know how to open your terminal, just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, the format of the command is something like this:

For example, if I wanted to connect via SSH to run one command, and that command was to list the files in the home directory, the command would look like this:

Note: That device doesn’t face the public internet, so I don’t have SSH keys enabled on the device. So, that means I have to enter my password in the image below. With that in mind, the output of that command would look like this:

login to ssh to run one command
See? It logs into the remote device, runs one command, and exits! Pretty neat, huh?

Of course, you can make it your own and there would be one less step if you had set up SSH keys. You can also make it more complicated if you want. You could try any one of the following commands, adjusting it for your needs:

Go ahead and play around with this. If you want to login to SSH to run one command, that’s how you do it. You can make the command as simple or as complicated as you want. So long as you string it together properly, the sky’s the limit!

Like I said above, you can just install SSH on your single device and practice what you read in these SSH articles. It’s not particularly taxing. There are plenty of articles to help you along the way.

Closure:

See? It’s really not all that hard to login to SSH to run one command and then exit automatically after that command has been run. It’s another handy SSH trick that you can add to your SSH toolbox. Also, the article is longer than I anticipated. Ah well…

What comes next? I have no idea. I try to not write too many consecutive articles on the same subject. Mixing them up seems the best way to go about it, as the site’s meant to be searched and not read like a blog. I do have a bunch of SSH content, but I’ve also covered a whole lot of it already.

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.

Fix Terminal Command Mistakes

In today’s article, we’re going to cover how to fix terminal command mistakes. While this may sound complicated, it’s actually very easy. As such, it should be a pretty short article. There’s not a lot to it, so it’s not hard to cover.

When you type a command in bash using systems, the command gets saved to the ~/.bash_history file. You can then use the up arrow and use that command again without having to type it again. We’ve also covered how to delete a ~/.bash_history entry. There have been a few articles on this subject.

So, with all that, this shouldn’t be a completely foreign article. It should be something that’s more or less familiar to new people and my regular readers. Because of this, it’s going to be a pretty short article.

Amusingly, it’s not that I want to write an easy/short article today, it’s just that this topic isn’t all that complicated. I was perfectly willing to write a longer article.

So then, let’s have a short article! Let’s learn how to…

Fix Terminal Command Mistakes:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, type an incorrect command. For example, you could try entering the following command to change to the ~/Downloads directory:

As you can guess, that’s likely to throw some sort of error. The command you’re actually intending to type would have been cd ~/Downloads. Well, you can fix it and run it automatically. Try this:

Tada! It should correct the previous command and then handily run the command on your behalf. To show you what I mean, here’s an image:

correcting an erroneous terminal command
See? It changes ‘cds’ to ‘cd’ and runs the command on your behalf. Pretty nifty, huh?!?

Yup, it just takes a couple of carets and spelling the proper command. It’s not all that hard to fix terminal mistakes. Just to be clear, bash will store both the original mistaken command and the properly fixed command in your ~/.bash_history. But, you can still use the arrow key to go back to either in the future. Of course, you can always delete the bash history entry if you want.

Closure:

See? It is indeed a short article after all. It’s not all that complicated to fix terminal command mistakes, so it’s easy to cover. It’s that how to fix terminal command mistakes is just not something that many Linux users, especially new users, know they can do. Well, you can – and it’s really simple.

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.

How To: Get CDROM/DVD Information From The Linux Terminal

In today’s article, we’re going to learn how to get CDROM/DVD information from the Linux terminal. What we’ll be doing is getting hardware information. It should be a brief article, as we’re just going to cover two commands.

I won’t even need to detail the various options, as we’re just after the hardware information. I’d say it’s going to be a short article, but that has a way of blowing up in my face and those articles sometimes end up longer than the “regular” articles! You get what you get. If  you don’t like it, write an article or two for me!

This particular article is actually based on one of my unix.stackexchange.com answers that didn’t get much notice, even though it was the accepted answer. Frankly, in modern days there’s not much need to know this information, as optical disks become a thing of the past. I decided to place the content here, hoping it’s easier for people using search engines. People still use optical media.

As you may know, most of my traffic comes from search engines. That’s the primary motivation for moving this answer here. I’m also motivated by laziness! I want a nice and easy day, for reasons I’ll probably detail in the next meta article. I also want it more easily indexed.

If you don’t know much about your CDROM/DVD player/recorder, then this would be a good article for you. In fact, even if you do know the basics, this is still probably a good article for you. You can learn a lot with a few simple commands. You’ll see…

So then, let’s learn how to get CDROM/DVD information from the Linux terminal. Sure, there’s probably a GUI way to do this, but let’s just stick to the terminal – after all, every Linux user has a terminal available. Plus, I don’t know a GUI method.

How To: Get CDROM/DVD Information:

In today’s article, we’re going to learn how to get CDROM/DVD information from the Linux terminal. What we’ll be doing is getting hardware information. This will require an open terminal. So, to open a terminal, just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, you may need to install the first application we’ll be using. The first application we’ll be using is ‘wodim’, an application used to write data to an optical disk. If you’re using a major distro, it’s in your default repositories. If you’re using apt, then install it with:

Of course, adjust that command to suit the distro you’re using, be it yum or even zypper. Then, run the following command:

Consult the output. That’s it. It should be obvious. Also, if you get any errors from this command, along with the second command I’ll share, remove any disks from the drive. 

For the second command to find CDROM/DVD information, and cdrecord is more likely to be installed by default, you need only to use this command:

Note the similar flags. It’s pretty much the same as you’re going to get with wodim, except cdrecord has a chance of being installed already. I don’t think I’ve come across a distro with wodim installed by default, but I could be wrong. I have come across distros with cdrecord installed by default. So, there’s that.

If I’m wrong and a distro exists with wodim installed by default, be sure to yell at me in the comment section! I’ve been wrong before, so this won’t be a first. I’m a big boy, I can handle it! Also, I’m kinda curious, so please do let me know in a comment.

Anyhow, enjoy the output from either command. They’ll tell you a bunch of information about your optical drives. Both of the commands will help you get CDROM/DVD information. Pick the one you like best and run with it. It’s your computer, you do what you want!

Closure:

As you can see, it’s pretty easy to get CDROM/DVD information from the Linux terminal. As you can also see, you have yet another article! There sure have been a lot of ’em. Again, I reach out to see if you’d like to write an article. I sure could use a break! We’ll soon cross the 300 articles mark! I am very grateful to those who have already helped. 

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.

How To: Compress And Decompress .bz2 Files

In today’s article, we’re going to discuss how to compress and decompress .bz2 files. This is something you may eventually need to know, so I’ll cover it here. I’ll just cover the basics, as most folks won’t need to know anything more than the basics. This should actually be a fairly short and direct article. There’s not a whole lot to it.

If you don’t already know, .bz2 files are bzip2 files. You’ll find that bzip2 is an opensource compression program that gets some regular usage, and you’ll sometimes find downloaded files that are compressed with this format. You may also, for compatibility reasons, want to compress files with bzip2 to share with other users who are already set on using the .bz2 format.

For the curious, the bzip2 man pages define this particular application as (and, as always, I highly encourage folks to read the man pages themselves – this one being a bit more complicated than others):

bzip2, bunzip2 – a block-sorting file compressor

Again, we’re going to just cover how to compress and decompress .bz2 files in this article. That’s all we’re going to do. You don’t tend to come across too many files compressed with bzip2, but they do show up from time to time.

Because of that, we’re going to cover how to compress and decompress those files in this article. It’s gotta get covered eventually, so it might as well be now. Read on!

Compress And Decompress .bz2 Files:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

You might actually not have bzip2 installed. It’s not always installed by default. Fortunately, as far as I can tell, it shares the same name in every major distro, that is ‘bzip2‘. So, just go ahead and install it like you’d install any other software. For example, if you’re using Fedora, your command would look similar to:

See? I didn’t use Ubuntu as the default example! We’re mixing everything up today! (Use apt if you’re using a distro with apt, like Debian or Ubuntu and derivatives.)

At this point, you should probably have a .bz2 file to work on for the sake of the article. Seeing as I have no idea what you’ve already downloaded, we should probably start with you making one – just so you can see how to decompress it. 

To compress a file with bzip2, the command looks like (See the detailed warning below this command, do not use this command without reading the warning!):

That will create a file with the same filename but make a .bz2 file. However, this is a destructive act. If you use the above command, the original file will be deleted! If you wish to keep the original file, you need the -k (keep) flag. That looks like:

That command will not remove the original file, as would be the default. Obviously, the -z flag means ‘zip’.

If you want to decompress a file with bzip2, the command looks like:

This will extract the file(s) into the current directory. Of course, the -d means ‘decompress’. This is not a destructive operation. The original and extracted files will remain on your file system.

As you can see, it’s not all that difficult to compress and decompress .bz2 files. You might go years not seeing any files in that format, but you’re eventually going to bump into one and now you know  how to deal with it in the terminal – and how to respond in kind.

Closure:

And there you have it. You have yet another article. We’re getting close to 300 articles at this point, so it has been a long journey. If you feel like writing an article, let me know! Anyhow, you can now compress and decompress .bz2 files easily enough, and that was the point of the article.

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.

How To: Make Google Chrome Use Less RAM (And Other Browsers)

In today’s article, we’re going to explore one way to make Google Chrome use less RAM. This is also useful for other browsers and will reduce CPU usage as well. This will be a shorter article (I was wrong), outside of the norm for the articles I tend to write.

This article has an update:

How To: Make Google Chrome Use Less RAM (UPDATE)

Though, to be fair, the efficacy of this depends a great deal on how you use your browser. If you’re a light browser user, this probably isn’t the article for you. Otherwise, if  you’re anything like me, read on!

See, right this very minute, I have 108 open tabs in this browser. On top of that, I have three browser instances open. I do different things in different browsers, as a way to both organize myself and to keep things compartmentalized. Even with gobs of RAM, the browsers consume a ton of resources.

While I do make use of bookmarks, I also have a lot of open tabs that I return to with some regularity. Eventually, you’ll have to restart Chrome, assuming you also don’t reboot as often as I do. Browsers just consume more and more resources, ’cause the concept of a simple webpage is gone as everyone uses the latest libraries and insists on being interactive.

This increasing resource usage equally true with Firefox, Chromium, Opera, Brave, etc… If you have enough tabs open, it’s gonna consume a bunch of resources, continuing to use more as time passes. This can lead to a system, or just browser instance, that slows down or even becomes unresponsive. It can even cause the system to freeze entirely.

Well, if you try this one simple trick (Ha! I crack me up!) then you can probably resolve this issue. This article will tell you how!

Make Google Chrome Use Less RAM:

For once, you don’t have to open a terminal for this article!

Instead, crack open Google Chrome – or any other major browser. This works for most of the popular browsers. As long as it’s in the Chrome or Firefox family, you should be able to use this extension.

I guess I should call this a review. It kinda is. 

As I was saying in the intro, my browsers were consuming too many resources. They’d chew up RAM, sometimes chew up CPU, and generally take more resources than I felt they needed to.

I knew what I wanted to do, so I went looking for a browser extension that’d let me do what I wanted. I tried a few extensions that did what I wanted, but settled on the add-on/extension called “Auto Tab Discard“. 

Auto Tab Discard is available for both Google Chrome and Firefox. What it does is, after a certain amount of time (which you set) it ‘discards’ tabs. This is handier than you might think!

Auto Tab Discard unloads unused tabs from memory, reducing RAM consumption by an immeasurable (but about 60% in my case) amount – as well as reducing CPU usage, though CPU usage is usually pretty minimal for non-interactive tabs that aren’t currently open.

You can set the time for this, meaning you can make Auto Tab Discard discard tabs after being inactive for 15 minutes, for example. If this was a blanket statement, then the browser extension would be pretty useless – but it’s not. After all, you probably don’t want all tabs to be automatically discarded.

To that end, you can also set certain tabs to never be discarded. You basically whitelist the domain and those tabs will not be discarded automatically with Auto Tab Discard. On top of that, and this is moderately important, you can tell Auto Tab Discard to *not* discard tabs that have audio or video playing.

For example, you can load up a YouTube playlist and let it run in the background and Auto Tab Discard will let it remain resident in memory. This also works for tabs just playing audio. As near as I can tell, this feature works fine – and I’ve been using the extension for well over a month now.

That’s how I use Auto Tab Discard. You can also manually choose to discard a tab. If you need to, you can even tell Auto Tab Discard to discard everything but the current tab. You can note discarded tabs by the ‘zz’ in the changed tab title. There are a ton of options that let you customize Auto Tab Discard for yourself. Click on the extension’s icon to see a bunch of other options for Auto Tab Discard.

Hands down, this is the best extension I could find that would make Google Chrome use less RAM and CPU. As a bonus, it’s also available for Firefox!

Bonus:

While doing all this testing, I decided to solve another problem. Any time I’d open a YouTube tab, even by mistake, it would automatically start playing the video. That was really annoying – especially as I was now discarding those tabs and they’d automatically load when I clicked on a tab by mistake.

For this problem, and I have a lot of YouTube tabs open, I managed to find “Stop Autoplay For YouTube“. I only make use of the version for Google Chrome, but I’m sure something exists for Firefox. For some reason, it doesn’t seem to always work, but it works often enough for me. It’s still annoying, but far less often.

I just haven’t trialed anything in Firefox because Firefox isn’t one of my favorite browsers. Because of this, I’m reluctant to recommend any specific extension. I’m sure there’s a browser add-on for Firefox that will stop YouTube from autoplaying videos. If you do find a good one, feel free to recommend it as a comment.

But, for Google Chrome (and Chromium, of course) I find the Stop Autoplay For YouTube to be a handy extension, doing useful things. If your browsing habits are anything like mine, you too might find it useful. If you don’t have 20 YouTube tabs open (technically actually discarded with Auto Tab Discard) like I do, you’ll find it helpful when you mis-click and a YouTube video starts playing automatically.

Closure:

Well, that was a different article. Today’s article is going to be useful to a subset of people, some of whom will be using operating systems other than Linux. Hopefully more people will learn how to make Google Chrome use less RAM, even if they’re using Windows or a Mac. You can even use Auto Tab Discard in the Microsoft Bing browser, for that tiny subset of users who do use that browser on Linux.

Automatically discarding tabs makes computing so much nicer and it means I don’t have to change my ways all that much. I just let tabs get discarded and that means my RAM usage is a whole lot less than it used to be. The browsers accounted for well over 60% of my RAM.

So, if you’re anything like me, this will help you reduce the resources used by your browsers. And, if you’re anything like my, at least 90% of your computing time will be spent in your browser.

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.

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.