How About A Brief Overview Of The Cat Command?

This is just a brief overview of the cat command. There are all sorts of ways to use the cat command, and I’m just going to cover some of the most common ways – the ways you’re most likely to use the command in day to day activities.

You’ll find ‘cat’ popping up in various tutorials and may find it being used for all sorts of things. As a command, it has existed since the earliest days of Unix (about 50 years ago, as of the time of this writing) and it gets used still today. If you check the man page, you’ll see that cat describes itself as:

cat – concatenate files and print on the standard output

But I find the Wikipedia description to be even better, at least more descriptive:

cat is a standard Unix utility that reads files sequentially, writing them to standard output.

If you’re curious, ‘concatenate’ just means linking stuff together in a chain or series – but ‘cat’ is more frequently used just to read the contents of a file by writing them to the standard output.

You can use this output in a number of ways, though this article aims to be just a fairly brief article, just an overview of the cat command. I haven’t written it yet, but i expect it to be reasonably brief!

An Overview Of The Cat Command:

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.

Next, I want you to run the following commands:

That just downloads a text file with some random numbers in it. It’s harmless. Now, let’s view it in the terminal:

If you don’t want to display all the results at once, just try piping it to the ‘less’ command. You can do that because cat handily outputs to the standard output. It’s just:

Alright, that was fun! Let’s try something nifty.

That will take the output of the cat command and add it to a document that you just created at the same time. So, if you want to see your handiwork, just try this command:

You’ll see the contents of ‘rnd-num.txt’ are now in the new file. If you use > it overwrites the contents of the file, but if you use >> it appends the content to the new file. To test that again, try this:

Now, if you cat the ‘new-file.txt’ you’ll see that it has twice as many lines as it did have. If you want to see it for certain, cat will helpfully add line numbers! Try this:

Then run (and it should show 100 lines):

Or, for even more fun, you can actually combine those (or just show the output from multiple files without the -n flag) with this:

Anyhow, those are a few examples as an overview of the cat command. Use the man cat command to learn more about it.

Closure:

And there’s another article! Thanks for reading! For a bonus, you can also use cat like touch and create a new file, like so:

When you use ls you’ll see the new file has been created called ‘example.txt’. Tada! Really, read the man page and learn all the wonderful things you can do with the cat command. This has been just a brief overview of the cat command, and there’s so many more nifty things that can be done.

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 Count The Running Processes In Linux

This article will show you how to count the running processes on your Linux system. Like many articles, it will show you how to use some tools that you may not yet know about.

The tools in question will be ‘ps‘ and ‘wc‘. The ‘ps’ command reports the current processes and the ‘wc’ stands for word count and has uses beyond just counting individual words, as this article will show you.

If you’re curious, the man page describes them as:

ps – report a snapshot of the current processes.

And:

wc – print newline, word, and byte counts for each file

We will be using both of these tools, not just to just count the running processes, but also to expose you to these tools. After all, it’s really not all that important to count the running processes. I suppose if you have resource constraints, but it’s not so important the number of running processes – but how computationally expensive those processes are.

So, this should actually be a pretty short article and it’s definitely in the beginner territory. If you’re an advanced user, it’s likely that you’ll have at least some familiarity with these tools. Even if you’re an expert, have some fun and read on!

Count The Running Processes:

Like many other articles on this site, we start with an open terminal. You can open your terminal with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With the terminal now open, we’ll start with the ‘ps’ command. Running just ‘ps’ is pretty useless, so be sure to check man ps for more information. Instead, we’ll run it with the -e flag to show every running process.

Tada! That shows you every running process. Now, let’s see the same command with the -U flag. You can’t just use the -U flag by itself, it requires a username. So, try this to show all the processes being run by a specific user:

Where you see <user>, put your username. In my case, the command would look like ps -U kgiii – and don’t forget that it is case sensitive and lowercase letters are all you can use in your username. Anyhow, that command will show the running processes owned by the user ‘kgiii’.

So, all that is well and good. How about we now count them? To do that, you just need to add a pipe and wc -l. We’ve used a pipe before, and the pipe is one of the greatest concepts in Linux – as it allows you to take the output from one command and pipe it into a new command.

Using the information above, we would then try:

And to count the processes from a specific user, you’d just use:

An example output of the latter would look something like this:

A count of processes owned by user 'kgiii'.
Counting the processes owned by user ‘kgiii’. A nice even 200, strangely enough.

That’s about it, really. You can check the man pages for both ‘ps’ and ‘wc’ to learn more about them, but this would be how I’d count the running processes on my Linux boxes. 

Closure:

There you have it, another article – this one telling how to count the running processes. Hopefully, we all learned a little something today and hopefully we’ll all learn a little something new in two days – which is when the next article should come out.

We’re approaching the halfway point in this year-long project. It has been good fun and I’ve learned a great deal. If I had to speculate, I would guess that this project will keep going beyond the one year mark, though maybe with a more lenient publishing schedule!

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 Play Around With The ‘MV’ Command

Today, we’re going to play with the ‘mv’ command, just as the headline implies. It’s a pretty easy command for anything you’re likely to do with it, and it’s a great way to accomplish some pretty neat things in the terminal.

So, let’s start with the ‘mv command. Right away, when we check the man page, it shows you one of its greatest features. It defines itself as:

mv – move (rename) files

And right away you see that it does more than just move files. It also seems to be a command that newer folks don’t use. Maybe they’re afraid of it? Maybe it just doesn’t get enough love? I dunno, but I know it’s a pretty great command. This article is gonna cover it.

Let’s mix things up a little! Why don’t you open your terminal and we’ll start from the same page. Enter the following commands into your terminal, one after the other, pressing enter between each one.

Now, assuming I’ve done that properly and you’ve followed along, you should have made some files, a couple of directories, and your ‘pwd‘ (print working directory) is ~/Documents/tmp.

See? Now we’re all on the same page, and this is a fine time to start an article about the ‘mv’ command!

Play With The ‘MV’ Command:

So, for once, I don’t have to start this section by telling you how to open your terminal! You should have it open from the preparation we did in the intro! That’ll save some time…

So, with that terminal open, I want you to enter the following:

That should move the ‘file1.txt’ to the test directory. If you want to actually verify this, just go like:

Which should show you that the file has in fact been moved. Let’s go back to that same tmp directory and verify that it’s no longer there.

And you’ll see that file1.txt is no longer there in the tmp directory. And, seeing as you’re back in the right directory, let’s rename a file using the ‘mv’ command. Try this:

This will have renamed the file2.txt to changed.txt and you can once again verify that the former has been renamed to the new filename changed with the ls command.

Finally, with one more trick up its sleeve, you can both change the name and move the file at the same time. To do so, you’d just go with:

If you then run ls in both the pwd and test directory, you’ll see all the changes have been made, exactly as intended. If you need to, open your graphical file manager and verify it visually, but you can just as easily use the ls command and verify it all.

For fun, if you want to delete all those, you can move to the ~/Documents directory (cd .. or cd ../..) and use this command:

That’ll clean up any sign that we’d been there and done this exercise. There’s more to the ‘mv’ command and, as always, be sure to check the man page for more usage instructions (to learn things like the -f switch). But, these are the most common ways you’ll use the ‘mv’ command and I wanted you to have a basic familiarity with it.

Closure:

And there you have it… It’s something a little different, as I felt it important that we start from the same place. I also figured I’d try a little bit of a different writing style for this one. If I can’t have fun, why do it? Either way, it’s yet another article. It’s one step closer to the year-long commitment I’ve made. (It’s gonna be a long year.)

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: Find The RAM Total In The Terminal

Today’s article will show you how to find the RAM total, because that’s basic information everyone might want to know. If you don’t already know how much RAM you have, this is a good article for you. If you’re like me and need to be reminded from time to time, this is also a good article for you!

You might have a computer that doesn’t run as fast as you want, and having not enough RAM may be a cause. Before you install a distro, you should know that distro’s minimum requirements, of which RAM is often one such prerequisite. Maybe you’re upgrading RAM and really want to make sure you know what you have inside? Dunno, but there are reasons why you might want to find the RAM total.

Not all my articles are long, and that includes this one. This one should be pretty quick and easy, suitable for folks just starting out who want to know how much RAM they have.

Find The RAM Total:

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 the terminal open, we’ll just use the free command. It looks like this:

The output is obvious and will look similar to this:

free -m in action
The output should be fairly obvious to all readers. The total RAM is listed in the output.

That’s the output from a fairly standard device. It should be obvious, but the column you’re looking for is under ‘total’ and you’re looking for the big number/top row.

You can also check /proc/meminfo for more information. Run the following command for a bunch of data about your installed RAM:

If you take a look at the output, you’ll be looking for the row starting with “MemTotal” in the results. Of course, you can just use ‘grep’ to pull out just the information you want. Try it with this command:

That should do it. It should give you an output that has just the row you’re looking for. Feel free to change ‘MemTotal’ to another row, but remember that it’s case sensitive – like most of Linux.

Closure:

There are surely other ways to find the RAM total, but those are a couple of easy ways to toss into your growing toolbox. This is also another article in the books. It’s just a short article, but it’s an article nonetheless. 

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: Restart TeamViewer From The Terminal

In a previous article, I wrote about TeamViewer, and this article will teach you how to restart TeamViewer from the terminal. The reality is, I like TeamViewer quite a bit but it has a nasty habit of failing during the authentication step.

The only way to make it work, without visiting the device in person, is to restart it. I actually do this with SSH, but it’ll work in the terminal. So, you’re doing it from the terminal – you’re just doing it remotely and using SSH to do that.

Well, no… I have no idea how you’ll be doing it. After all, you might choose to do it locally – where this will also work. So, is it really from the terminal? Yes. It just depends on which terminal, I suppose!

Anyhow, this is just a short article. If you’re physically at the computer, why are you using TeamViewer?!? If you’re physically at the computer, you can just restart it with the GUI – or you can use the terminal. 

Restart TeamViewer From The Terminal:

So, if you’re at the device, just open the terminal. If you’re not at the device and TeamViewer isn’t authenticating, just connect to it with SSH. We’ll assume you’ve already set up SSH and know how to connect. If you don’t, then go back and read the SSH link in the 2nd paragraph. You need to use the following commands. 

To stop the TeamViewer service, run:

To restart the TeamViewer service, run:

If you want to just run one command, you can do that too! Just run:

The latter command is probably the easiest, and TeamViewer fails often enough for me to have taken the time to alias the restart command. As far as I can tell, there’s no rhyme or reason for it to no longer authenticate, but that’s what happens.

Closure:

As I use it often enough, I figure this is worth sharing with the world. It’s not a very long article, but it is indeed an article. Hopefully this helps someone who’s having similar authentication errors. As near as I can tell, just restarting the service fixes it and I’d say that the authentication fails every other day, sometimes more and sometimes less. Thanks for reading!

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.