One of the most basic commands you'll use on Linux is cat. It may seem mysterious at first, but it's actually simple to use.

Here's how to use the cat command on Linux, and when not to use it.

What Is cat?

cat is a very old utility that dates back to the original implementation of Unix. The name might seem strange, but it's short for "concatenate." It's a fancy term for sticking a bunch of stuff together. "Stuff" in this context means files. cat is a utility for sticking a bunch of text files together. Most people use it to print files to the screen or into another file.

The GNU implementation is part of the coreutils package installed by default on most Linux distros, but there is also a version on BusyBox that's common on minimal or live distros.

Using cat With Standard I/O

cat command with standard I/O

cat operates on standard input and output. This means that it will accept text input from the keyboard or another program using I/O redirection and that you can use its output with another program using pipelines:

        cat | some_program
    

Bear in mind that many other Linux commands accept standard I/O as well, so you may not need to actually use cat in pipelines. More on this later.

It also accepts files as arguments from the command line. You can print an entire file to the terminal using:

        cat file.txt
    

You can also print multiple files using cat:

        cat file1 file2
    

This is the "concatenate" part of cat.

Called by itself, cat will wait for you to type text and press Enter, then echo whatever you typed back at the terminal until you press Ctrl + D. You can also redirect the text into a file using the redirection operator:

        cat > some_file
    

Useless Use of cat

Given that cat is such a basic utility, it's easy to get carried away with using it with pipelines. Randal Schwartz, best known for his books on Perl, created the Useless Use of cat (UUOC) "award" (as seen on Era Eriksson's home page) and would occasionally hand them out on Usenet.

The main qualification for a UUOC is using cat to pipe output to a command that already takes standard input or files as arguments. Since so many Unix and Linux commands do that, using cat to pipe standard output or a single file is a waste of time. You should check the manual page for any command you want to use and make sure it accepts standard input so you don't "win" this award.

If you're going to be looking at long files, you're better off using a pager like Most or a text editor.

cat: A Basic but Indispensable Linux Tool

cat may be a basic command, but like a lot of basic Linux tools, it's handy for printing text files and sending output to other programs. If you want a little more color in your terminal, you might want to consider lolcat, another filter-based program that generates rainbow-colored text in your terminal.