A Little About The ‘echo’ Command

That’s right, in today’s article we’re going to learn a little about the ‘echo’ command. We’ll barely be scratching the surface of the ‘echo’ command. There are so many ways to use ‘echo’ that we simply can’t fit it all into an article. Do, read on!

So, what is ‘echo’? Well, basically, the ‘echo’ command is a command that tells the computer to output text – be it in the terminal or using standard output to add that text to a file. It’s useful for regular people, but you’ll find it’s most commonly used in things like bash scripting

That sort of thing, scripting, is outside the scope of this article – and probably beyond the scope of the entire site. Maybe I’ll get to it, but those would end up being long articles, or articles written in parts. Besides, I’m not really all that good with scripting. (If you are good with scripting and would like to write some articles, do let me know.)

This is how the man page describes the ‘echo’ command:

echo – display a line of text

That’s indeed what it does. When you combine it with things like variables, you open up a whole new world. I don’t actually have a very good article about variables, other than existing variables. I should probably have said article.

Anyhow, we’ll just be scratching the surface of the ‘echo’ command. There are all sorts of ways to use ‘echo’, but we’re just going to use it in ways that a new Linux user might use it. Some basic familiarity is probably a good thing.

The ‘echo’ Command:

This article requires an open terminal. 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. Otherwise, just open your terminal like you normally would.

So, how you start with this ‘echo’ command:

You can also add quotes, and in some cases probably should:

You can also use the > operand and echo the text to a file. Like so:

Read: How To: Write Text To A File From The Terminal with “>” and “>>”

However, that’s not all you can do with the ‘echo’ command. You can also automatically fill in the information by way of environment variables. For example, try this:

Or you can try:

Read: How To: Show All Environment Variables

See? It’s good that I’ve written so many articles. I get to refer to ’em and save us all a bunch of time. So, be sure to visit those articles – especially if you’re a new user. If you’ve forgotten something, you can ‘echo’ the variable to be reminded.

Bonus:

This next bit is really just some information you’re gonna need down the road. I can sense it! This is a bit advanced for some of you, and you won’t need this until later in your Linux journey, but others will see this and suddenly understand the potential. If you’re new, you’ll get there.

The first thing we’re going to do is set a variable. It’s actually very easy to set your own variables in Linux. In this case, we’ll use:

Now, let’s just ‘echo’ the variable you just created:

Or, even better, you can then try:

See? It will output the variable when you echo it. You can create all the variables you’ll realistically ever need. 

You can actually format the output from the ‘echo’ command. For example, the -e flag with the \n separator. An example command looks like:

You can format the text in a variety of ways, just read the man page. You can do quite a lot with the ‘echo’ command and you should definitely check the man page if you’re interested in exploring all the possibilities:

There’s a ton of ways to use ‘echo’ (and with it variables) for those with a clever mind. When you do move on to learn about scripting, you’ll learn that it’s a basic tool used for all sorts of things, in all sorts of clever ways.

Closure:

And there you have it. You have a new article. This time, we’ve covered just the slightest bit of the ‘echo’ command. It’s enough to get your mind working, or so I hope. It’s enough to get a slight taste of the potential and to understand why you may want to be familiar with it.

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.

A Little About The ‘lspci’ Command

Today’s article is going to be another article where we get back to the basics, where we’ll learn a little about the ‘lspci’ command. As far as articles go, this one should be both fairly brief and easy to understand. To learn more about the ‘lspci’ command, read on! 

I am going to be writing some articles that cover the basics. I decided to not write them all at once, but to intersperse them with other articles. So far, we’ve had:

A Little About The ‘lsusb’ Command
A Little About The ‘lscpu’ Command

Well, this time around we’re going to cover ‘lspci’. 

So, what is ‘lspci’? We can find no better source than the man pages, which helpfully describe ‘lspci’ as:

lspci – list all PCI devices

Well, we see that it lists PCI devices, but what are those? PCI is another way hardware components talk with the CPU. If you have a fancy graphics card, it’s probably PCI-based (but likely PCI-X). If you’re really curious, PCI stands for “Peripheral Component Interconnect” but think of it as a way hardware can talk to the central processing unit.

So, the ‘lspci’ command will list things attached to the computer on the PCI bus. This is remarkably similar to the ‘lsusb’ command, though PCI can have a USB device attached to it through a hub.

Anyhow, that’s what PCI is and that’s what ‘lspci’ is meant to do. So, with that in mind, let’s just belly-flop into the article!

The ‘lspci’ Command:

You’ll find that ‘lspci’ is a terminal-based command. As such, you’ll have to have a terminal window open. If you don’t know how to open your default terminal emulator, just press CTRL + ALT + T and your default terminal should open.

We will not be covering everything that can be done with the ‘lspci’ command. We might have time and space (this time around), there’s really no reason to dive deeper into the ‘lspci’ command. We’re just going to cover the basics – because that’s all you’ll realistically have to worry about.

With your terminal now open, just run the command with no flags (but with sudo, ’cause ‘lspci’ wants elevated permissions to operate):

If you want a more verbose output, you can do that. Your choices are -v, -vv, and -vvv with ever-increasing amounts of verbosity. That can be pretty handy. Try this command to experience the most verbose output:

Where you might find the ‘lspci’ command most useful would be when you already know the class and category of information you want returned. When you use ‘lspci’ with ‘grep’, it gets more useful. For example, to learn about your memory:

See? It’s pretty straightforward. You’ll get this. I’m sure of it! (See 2nd edit below.)

As you can see, there’s quite a bit that you can do with the ‘lspci’ command. It’s a pretty handy command and we’ve just covered the ways you’re most likely to use ‘lspci’. 

EDIT: Fixed some information. I had somehow started to include lshw commands.
EDIT: So, this article was horribly written. Now it’s just short. I conflated ‘lspci’ with ‘lshw’ somehow – probably ’cause they’re next to each other in my notes. I’m just going to leave it as it is now.

Closure:

There it is, another new article! This time, we’re learning a little about the ‘lspci’ command. It’s a handy command to have learned, as you’ll eventually want to know about the hardware using the PCI bus. When that day does come, you’ll be able to use the command. Also, I’m ahead of schedule with pre-written articles.

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.

Let’s Have Christmas In The Terminal

Today’s article is just another fun article. In this article, we’re going to learn how to have Christmas in the terminal. You won’t learn much of anything useful, but you may have some mild entertainment. Read on!

As you know, a lot of these articles are things you can do in a terminal. So, what’s better than making a Christmas tree in the terminal? It seems like a reasonable article to write, as today’s article will have been published on Christmas Day.

Not everyone who reads this site will be among those who celebrate Christmas. Personally, I’m an atheist that kinda appreciates the Buddhist philosophies. I celebrate Christmas as an excuse to share good times with friends and family, a chance to give back to those who have enriched my life.

So, if you don’t celebrate Christmas, that’s fine. You don’t have to participate in this article. You could also just call it a Holiday Tree, I suppose. Hopefully you’ll use this opportunity to show your appreciation for those around you, even if you celebrate Festivus!

Alright, that’s enough ‘serious’ stuff for one article. Let’s just get into how to have Christmas in the terminal!

Christmas In The Terminal:

As the title implies, and like so many other articles, you’re gonna need an open terminal in order to have Christmas in the terminal. So, open your terminal of choice. 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, download a handy script to get started:

Next, we’ll make that file executable:

Now, we’ll run the program/execute the script:

The end result should look a whole lot like this:

That video should not autoplay. You’ll have to press the play button on your own. I too dislike any videos that webmasters deem should be automatically played. I assume you dislike that as well. So… You’re welcome!

Anyhow, there you have it… You have a Christmas tree in your terminal, just as the title suggested you would. Happy Holidays!

Closure and Some Thanks:

When I started this site, I was excited if I got twenty visitors in a single day. Well, the site has grown a whole lot since then. It has become an important part of my life and the thanks goes to you for reading, commenting, encouraging, providing feedback, etc… Without all that, I’d have never kept it up this long. So, thanks!

As for Christmas, I hope you’re all having a great day today. If you want to give me one gift, get offline (after rating the article, of course) and spend some time letting your friends and family know how much you appreciate them. It’s a good day to do so, even if you don’t particularly care for the holiday.

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.

Show A Random Fortune When You Open Your Terminal

In today’s article, which should be a short one, we’re going to learn how to show a random fortune when you open your terminal. This should be pretty quick and easy, easy enough for anyone to follow. Read on, my delightful readers!

NOTE: You gotta be using bash for this, as evidenced by the use of ~/.bashrc.

Why this article? Well, I am having some connectivity issues and I want to ensure I get you a nice article while I have the connection to do so. I don’t want to count on enough time to write a longer article.

Besides, it’s another good day for a fun article. I am 99% confident that this article will teach you nothing of value! And that’s okay. It’s just you having fun – and having fun is always a good idea. So, this article will just be a bit more of that, some more fun…

First, you should read the previous article and follow the directions. That’s gonna be necessary for the next part. After all, you can’t get a random fortune when you open your terminal unless you’ve installed some software to do that. So, read this article:

How To: Display Your Fortune In The Terminal

Did you read that? Did you install ‘fortune’? Good… Now we can get into this article!

How To: Show A Random Fortune When You Open The Terminal:

Sorry about the ugly headline. Gotta optimize for Google, I guess.

This article requires an open terminal, like oh so many other articles on this site. Just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, we’re going to edit the ~/.bashrc file to make it show a fortune when you open the terminal. We’ll be using nano to do so, and that’s an easy enough process.

NOTE: You don’t need sudo for this, as you already own this file.

With nano opening your ~/.bashrc file for editing, you just need to scroll to the very bottom. When you get to the bottom of the file, just add the following line:

Next, you need to save the file. To save the file with nano, press CTRL + X, then Y, and then ENTER.

Now, you need to reload your bash profile. That looks like:

Now, that should reload the terminal and profile, showing you a ‘fortune’ quote. If you want to be really sure, or if doesn’t show you a fortune, just close your terminal and open it back up again. When you open your terminal again, it should definitely show you a fortune. See? Pretty easy! It’s darned near magical!

Closure:

And there you have it. You now know how to show a random fortune when you open your terminal. ‘Snot all that hard, now is it? If I’ve gotta bang out an article with intermittent connectivity, we might as well have fun with it! Thanks for reading and we’ll get some more serious content coming up – or will we?!? I should have decent connectivity soon. It can’t stay down forever, can it?

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.

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