Linux Cat Command With Examples

Concatenate or simply cat is very useful command in Linux and Unix systems. Cat have the ability to create files, concatenate files or redirect output. In this tutorial we will look different useful examples for daily usage for system administrators.

Syntax

Syntax of Linux cat command is standard like most of the Linux tools.

1

cat[OPTION]...[FILE]...

Man and Help

Man page can be get like below.

1

$man cat

Man and Help

Print Content

The most popular way to use cat command is printing contents of a file.

1

$cat myshell.sh

Print Content

Print Content of Multiple Files

cat command accepts multiple parameters as file name to print all contents of provided files.

1

$cat myshell.sh myscan

Create File

An empty file will be created when cat output is directed to the file name like below. After redirect control character should be send to close file.

1

$cat>new_file

And then

1

Ctrl+d

Create File

Use With More and Less Commands

While working more than one text file with more or less commands cat provides practical solution to pipe all files contents.

1

$cat myshell.sh myscan|less

Display Line Numbers

While printing file contents with cat the line numbers can be shown to direct line specification.

1

$cat-nmyshell.sh

Display Line Numbers

Display $ End Of Line

Cat provides $ as end of line separator.

1

$cat-emyshell.sh

Display $ End Of Line

Display Tab Separated Lines

There is also an option to separatetabbed lines with -T parameter like below.