Linux Cat Command Overview

Linux Cat Command is used to concatenate two or more files. It reads the text from all the files or standard intput and prints on the standard output. There are lot of practical uses of cat command. It can be used to create a new file, concatenate tow or more files, merge two files into one.

Linux Cat Command Syntax

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

Linux Cat Command Options


-A, --show-allequivalent to -vET
-b, --number-nonblanknumber nonempty output lines, overrides -n
-eequivalent to -vE
-E, --show-endsdisplay $ at end of each line
-n, --numbernumber all output lines
-s, --squeeze-blanksuppress repeated empty output lines
-tequivalent to -vT
-T, --show-tabsdisplay TAB characters as ^I
-u(ignored)
-v, --show-nonprintinguse ^ and M- notation, except for LFD and TAB
--helpdisplay this help and exit
--versionoutput version information and exit


With no FILE, or when FILE is -, read standard input.

Linux Cat Command Example

Let us look deeper into usage of Linux Cat Command with the help of some examples.

Linux Cat Command Example Case 1:

The basic way to use a cat command is to simply write

cat textfile1.txt

Linux Cat command will be reading the input from textfile1.txt and will print it to the standard output.

Linux Cat Command Example Case 2:

Most of the time cat command is used to concatenate two or more files. Let us see that will the actuall example. Linux cat command for that will be

cat text_file1.txt text_file2.txt

The above command will read from text_file1.txt and text_file2.txt. Then it will merge them and will print data from both the files on the standard output.

Linux Cat Command Example Case 3:

Let us concatenate content from two or more files and print the output in third file.

cat text_file1.txt text_file2.txt > text_file3.txt

Above command will concatenate data from text1_file.txt text2_file.txt and will print in text_file3.txt. If text_file3.txt doesnot exist than it will create the file and will save the data inside it. If it is already present and contains data than cat command will ovewrite the file and will print new data.

Linux Cat Command Example Case 4:

Linux Cat Command is also used to copy data from one file to another although you can also use Linux CP Command which also the most appropriate command for copying a file. Let us see what would be the cat command for that

cat text_file1.txt > text_file2.txt

The above command will create a new file if already not exsiting and will save the data into new file thus creating a copy of a input file.

Linux Cat Command Example Case 5:

Let us concatenate two files and than append the final data with the content of the third file. Linux Cat Command for that will be

cat text_file1.txt text_file2.txt >> text_file3.txt

Above command will concatenate the data from text_file1.txt and text_file2.txt and will append the final data with the content already in text_file3.txt.



This article is contributed by Ankur Rastogi on Sun Apr 17 2016 10:12:12 GMT+0530 (IST)

If you want to add more comments to the article or you see any thing incorrect please write a comment below and we will surely get back to you.