cat
Last Updated on Tuesday, 09 June 2009 11:26
| Article Index |
|---|
| 1. Name |
| 2. Synopsis |
| 3. Frequently used options |
| 4. Examples |
1. Name
cat [man page] - concatenate files and print on the standard output2. Synopsis
cat [OPTION] [FILE]...
3. Frequently used options
-n, --number number all output lines
4. 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,When we cat file cat.txt cat will read content of a file a spit it out to stdout:
Mandrake Linux, Red Hat Linux, Fedora Linux, Gentoo Linux
cat samba.txt

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

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

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

by -n option we also tell cat to number lines:
$ cat -n samba_support.txt















