Linux cat command Help and Examples

Linux command cat stands for “catenate”.

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

  • Pint 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

0 Comments

Submit a Comment

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

Related Articles