How to Use the Linux cat and tac Commands

Share
  • June 17, 2019

Fatmawati Achmad Zaenuri/Shutterstock.com

The cat and tac commands display the contents of text files, but there’s more to them than meets the eye. Dive a little deeper and learn some productive Linux command line tricks.

These are two simple little commands, often dismissed as being just that—too simple to be of any real use. But once you know the different ways you can use them, you’ll see that they are perfectly capable of doing their fair share of the heavy lifting when it comes to working with files.

The cat Command

cat is used to examine the contents of text files, and to join parts of files together to form a larger file.

At one time—back in the era of the dial-up modem—binary files were often broken into several smaller files to make downloading easier. Instead of downloading one large file, you pulled back each smaller file. If a single file failed to download correctly, you would just retrieve that one file again.

Of course, you then needed a way to reconstitute the collection of smaller files back into the single working binary file. That process was called concatenating. And that’s where cat came in and where it gets its name from.

Broadband and fiber connections have caused that particular need to fade—much like screechy dial-ups sounds—so what’s left for cat to do today? Quite a lot actually.

Displaying a Text File

To have cat list the contents of a text file to a terminal window, use the following command.

Make sure the file is a text file. If you try to list the contents of a binary file to the terminal window, the results will be unpredictable. You might end up with a locked terminal session or worse.

cat poem1.txt

cat poem1.txt in a terminal window

Read the remaining 99 paragraphs

Source : How to Use the Linux cat and tac Commands