Using The cat Command

There are many files on your dedicated server that can give you valuable information about the current running condition, errors, or general status.  Files like those in the /proc directory, for example, can provide you with vital system information.  Nevertheless, it is not a good idea to just open files like that in a text editor, especially when you can display the information right in your console with no trouble at all.

The “cat” command gives you the ability to read the contents of text files without intruding into them or risking accidentally making changes with a text editor.  The simplest way read a file with cat is to type “cat” followed by the filename.

cat mydoc.txt

Long files will present you with a problem.  Cat will not stop once it has started displaying the contents, and the top of the document will scroll quickly up and off the screen right before your eyes.  To remedy this, you can append “less” to the output so that you will be able to page through the document.

cat mydoc.txt | less

You may also decide to save the output information to a file that you can download and view offline.  To do this, type cat followed by an output redirection operator.

cat /proc/cpuinfo > /home/user/cpu-information.txt

cat is also helpful for concatenation (from which it derives its name) or stringing together multiple files.  If you ever need to combine files, this is a great way to do it.

cat file1 file2 file3

Again, the output will be displayed on the screen, but you can easily send that output to a file.

cat file1 file2 file3 > output.txt

For more information about cat, type “man cat” from the command line or view the manual online.