Cat


From Linuxconfig.org

Jump to: navigation, search

.. back to the list of Linux Commands

Name

cat - concatenate files and print on the standard output

Synopsis - man page

cat [OPTION] [FILE]...

Frequently used options

-n, --number 
      number all output lines

Examples

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
Image:cat01.gif

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
Image:cat02.gif

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

$ cat samba.txt ubuntu.txt > samba_support.txt
Image:cat03.gif

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
Image:cat04.gif

by -n option we also tell cat to number lines:

$ cat -n samba_support.txt
Image:cat05.gif

.. back to the list of Linux Commands

Personal tools
Linux Commands