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.

Subscribe to Newsletter!
Get notified when new articles are published!
We promise to never share your email!
icon

Author: 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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.