cat [man page] – concatenate files and print on the standard output


cat [OPTION] [FILE]... 

Frequently used options

-n, --number        number all output lines 


cat read content of a file(s) and print then on standard output which is in many cases our terminal. Lets suppose that our file samba.txt contain text:

Samba file and printer sharing is supported by all Linux Distributions: Suse Linux, Debian Linux,
Mandrake Linux, Red Hat Linux, Fedora Linux, Gentoo Linux

When we cat file cat.txt cat will read content of a file a spit it out to stdout:

cat samba.txt 

cat will read content of a file
As a description of this command suggest we can also concatenate two files. Our second file ubuntu.txt contain:

and Ubuntu Linux. 

Lets see what happens when we cat both files at once:

$ cat samba.txt ubuntu.txt 

cat both files at once
Now we can use cat to concatenate two files and create new file samba_support.txt.

$ cat samba.txt ubuntu.txt > samba_support.txt 

concatenate two files with cat command
With use of pipe we can redirect output of cat command to another command such us bc:

$ echo '2+2' > '2+2.txt' $ cat 2+2.txt | bc 

redirect output of cat command
by -n option we also tell cat to number lines:

$ cat -n samba_support.txt 

cat can number lines