Linux Command: cat

Published on September 29, 2021 at 8:03 am by LEW

Introduction

The cat (short for concatenate) command is a standard utility command in Linux Distributions. It reads a file to stdout, the display in most cases. The main uses of cat are to quickly view the content of a file or to pipe the file to another command.

Syntax and Function

The syntax of the cat command is:

cat [options] [file]

The cat command sends the content of a file(binary, ASCII, or UNICODE) to the terminal.Concatenation is limited to ASCII text files only.

Example

To display the content of a file, you only have to issue the cat command with the file name.

cat testfile.txt

if cat is typed by itself it will simply echo stdin to stdout, meaning everything you type will be echoed back tot he display.

There are several directory structures where cat is very useful, like /proc and /sys. These directories contain a lot of system information. Some useful examples of viewing this information are below.

cat /proc/meminfo
cat /proc/cpuinfo

To copy or append a file with cat. You would just need to redirect stdout.

cat myfile1.txt > myfile2.txt
cat myfile1.txt >> myfile2.txt

Options

The cat command has a few useful options when viewing file content. The most common are

Conclusion

The cat command is a quick way of viewing the content of a file. It is useful for exploring the /proc and /sys directories.

It can also be used to copy files by redirecting stdout.

Add New Comment

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