cat command in Linux / Unix




Linux cat command.

cat  command is used to show the content of a files and also to combine several files together in one file.

The cat command does not accept directories as input.

cat command syntax

cat filename [-n] [-b] [-u] [-s] [-v] Allows look, modifying or combining a file

cat [file.txt] [file2.txt] > [file3.txt] Reads file1.txt and file2.txt and combines those files to make file3.txt

cat command options

cat command main options:

option description
cat dumps the file content on terminal
cat -n displays line numbers to all lines of displayed content
cat -b displays line numbers to non blank lines of displayed content
cat -E displays $ at the end of line of displayed content
cat -s replaces blank lines to one line
cat -T displays ^I instead of tabs
cat [file.txt] [file2.txt] .. dumps the content from all files together on terminal
cat [file.txt] [file2.txt] > [file3.txt] Reads file1.txt and file2.txt and combines those files to make file3.txt

cat command examples

For exampe we have a file named sample.txt which contains the following content :

sample.txt


Now let us practice some cat commands with this file.

 

cat – View text file data:

 


cat -n – displays line numbers to all lines of displayed content:

 


cat -b – displays line numbers to non blank lines of displayed contentt:

 


cat -E – displays $ at the end of line of displayed content:

 


cat -s – replaces blank lines to one line:

 


cat -T – displays ^I instead of tabs:

 


cat [file.txt] [file2.txt] > [file3.txt]> – Reads file1.txt and file2.txt and combines those files to make file3.txt:

Let us say we have two text files sample.txt and sample2.txt.

First let us see the content of both the files

Now to display the content of both the file we can give the following command. The result will be the dump of both the files.

 

Now to combine the content of these two files and save the combined content to the third file, give the following commands.

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com