13 Basic Cat Command Examples in Linux

The cat (short for “concatenate“) command is one of the most frequently used commands in Linux/Unix-like operating systems. cat command allows us to create single or multiple files, view content of a file, concatenate files and redirect output in terminal or files.

In this article, we are going to find out the handy use of cat commands with their examples in Linux.

Read Also: Learn How to use ‘cat’ and ‘tac’ (Reverse of cat Command) in Linux

General Syntax of Cat Command

$ cat [OPTION] [FILE]...

1. Display Contents of File

The below example will show the contents of /etc/passwd file.

# cat /etc/passwd


2. View Contents of Multiple Files in terminal

In below example, it will display the contents of the test and test1 file in the terminal.

# cat test test1

Hello everybody
Hi world,

3. Create a File with Cat Command

We will create a file called test2 file with the below command.

# cat >test2

Awaits input from the user, type desired text, and press CTRL+D (hold down Ctrl key and type ‘d‘) to exit. The text will be written in the test2 file. You can see the content of the file with the following cat command.

# cat test2

hello everyone, how do you do?

4. Use Cat Command with More & Less Options

If a file having a large number of content that won’t fit in the output terminal and the screen scrolls up very fast, we can use parameters more and less with the cat command as shown below.

# cat song.txt | more
# cat song.txt | less

5. Display Line Numbers in File

With the -n option you could see the line numbers of a file song.txt in the output terminal.

# cat -n song.txt

1  "Heal The World"
2  There's A Place In
3  Your Heart
4  And I Know That It Is Love
5  And This Place Could
6  Be Much
7  Brighter Than Tomorrow
8  And If You Really Try
9  You'll Find There's No Need
10  To Cry
11  In This Place You'll Feel
12  There's No Hurt Or Sorrow

6. Display $ at the End of File

In the below, you can see with the -e option that ‘$‘ is shows at the end of the line and also in space showing ‘$‘ if there is any gap between paragraphs. This option is useful to squeeze multiple lines into a single line.

# cat -e test

hello everyone, how do you do?$
Hey, am fine.$
How's your training going on?$

7. Display Tab Separated Lines in File

In the below output, we could see TAB space is filled up with the ‘^I‘ characters.

# cat -T test

hello ^Ieveryone, how do you do?

Hey, ^Iam fine.
^I^IHow's your training ^Igoing on?
Let's do ^Isome practice in Linux.

8. Display Multiple Files at Once

In the below example we have three files test, test1, and test2, and able to view the contents of those files as shown above. We need to separate each file with ; (semicolon).

# cat test; cat test1; cat test2

This is a test file
This is the test1 file.
This is test2 file.

9. Use Standard Output with Redirection Operator

We can redirect the standard output of a file into a new file else existing file with a ‘>‘ (greater than) symbol. Careful, existing contents of the test1 will be overwritten by the contents of the test file.

# cat test > test1

10. Appending Standard Output with Redirection Operator

Appends in existing file with ‘>>‘ (double greater than) symbol. Here, the contents of the test file will be appended at the end of the test1 file.

# cat test >> test1

11. Redirecting Standard Input with Redirection Operator

When you use the redirect with standard input ‘<‘ (less than symbol), it uses file name test2 as input for command and output will be shown in a terminal.

# cat < test2

This is test2 file.

12. Redirecting Multiple Files Contain in a Single File

This will create a file called test3 and all output will be redirected in a newly created file.

# cat test test1 test2 > test3

13. Sorting Contents of Multiple Files in a Single File

This will create a file test4 and the output of the cat command is piped to sort and the result will be redirected to a newly created file.

# cat test test1 test2 test3 | sort > test4

This article shows the basic commands that may help you to explore the cat commands. You may refer man page of the cat command if you want to know more options.

In our next article, we will cover more advanced cat commands. Please share it if you find this article useful through our comment box below.

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

47 thoughts on “13 Basic Cat Command Examples in Linux”

  1. Hi, sir how to create multiple files in cat command (remaining examples very nice and thanks and you are doing very well lot of thanks…

  2. [edyst]>>> Used the cat command successfully!
    [edyst]>>> Used the tac command successfully!
    [edyst]>>> You used the head command correctly!
    [edyst]>>> You used the tail command correctly
    [edyst]>>> You copied the first 6 lines of avengers.txt successfully!
    [edyst]>>> You copied the last 3 lines of avengers.txt successfully!
    [edyst]>>> You reversed the contents of avengers.txt correctly
    [edyst]>>> Task executed successfully!

    whats the input ?

  3. We can use parameters more and less. They’re not parameters, you’re piping the “cat” output to those commands. Big difference.

    • I think it will give an error :/ ==> because of “ls -l” there is no such file or directory

      If not please aware us too.


Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.