Home » Linux Command » Linux cat command Help and Examples

Linux cat command Help and Examples

Update on:
Sep 4, 2021

Linux command cat stands for “catenate”.

The cat is one of the simple and most commonly used commands in Linux. It is used to:

  • Print text from files
  • Copy text from files to a new file
  • Append contents of a text file to the end of another text files, and combine them

You can check here for cat command syntax and options.

Cat command examples

Example 1 – Displaying text files

The most popular and most straightforward way to use cat command is to apply for displaying or printing file content on the screen.

$ cat example.txt

If you have entered two file names in command, will show the content of those two files as if they were a single file.

$ cat example1.txt example2.txt

Example 2 – Copy a text file

We usually use cp command to copy a file, but we can use cat command also to make copies of text files.

To copy text files using cat command we can use output redirect operator so that we can redirect the output of a file to another new file and it will copy the entire content to a new text file.

To output redirection use symbol “>” like below command

$ cat example.txt > newexample.txt

Similarly, we can catenate more than one file into a single file.

$ cat example1.txt example2.txt > newexample.txt

Example 3 – Append a text file’s contents to another text file

If you use the cat command to copy content into the old destination file, it will overwrite your old data from the destination file. So, instead of overwriting destination file, you can also append the content of source file to destination file using the redirection operator symbol “>>” like below command.

$ cat example1.txt >> example2.txt

Related Posts

The 30 most useful Linux commands

This article will introduce some practical and common Linux or Unix command , which is the Linux system administrators normally use the command . This article is not a complete list, but a brief list of commands that can be useful...

15 Practical examples of tcpdump command

15 Practical examples of tcpdump command

The tcpdump is the most essential and powerful command-line network packet sniffing tool. We use it to analyze network packets, capture or filter TCP/IP packets that transferred and received over the network on a specific network interface. It is available in almost...

15 Useful “df” Commands to Check Disk Space in Linux

15 Useful “df” Commands to Check Disk Space in Linux

There are several Linux tools available on the internet to check disk space utilization; we can use any of them. But, Linux has a best built-in command-line utility called “df”. The “df” is the short form of “disk filesystem”, we can get detailed information on used...

15 Practical examples of echo command

15 Practical examples of echo command

If you are writing a bash script, you know echo command very well. It is use to display text lines on an output screen or a file. The echo command is the most common command used by all Linux users, and it is built-in Linux command. echo command syntax: echo...

Follow Us

Our Communities

More on Linux Command

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

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

20 − four =

Shares