cat – Unix and Linux Command with Examples
DESCRIPTION:
cat command is one of the basic utility in UNIX operating system to concatenate files.
USAGE:
cat command is used to
- View the full content of the file in the screen.
- copy the file
- append the content of the file to another file
OPTIONS & USE CASES:
Totally there are 11 options to use with cat command. These options may or may not be available for different versions of UNIX operating systems. Below you can find all the 11 cat command options with example. Here I took a file named cat_example.txt as an example.
cat -A cat_example.txt ABC DEF GHI JKL MNO PQR STU VWX YZ
Â
-A or –show-all
This option shows all the non-printing characters (^ and M-), TABS as ^I and shows $ at end of the each line. In short, this option equals to -vET options. Both –A and –show-all provides same result.
-A = –show-all = -vET
Example: Tabs are displayed as ^I character and $ is displayed at end of the each line. Mostly ^M (Ctrl+M) occurs when the text file is transferred in the binary mode.
Read More: Find and remove ^M (control+M) characters in unix
$
cat -A cat_exampleÂ.txt ABC^IDEF^IGHI^M$ ^M$ JKL^IMNO^IPQR^M$ ^M$ ^M$ STU^IVWX^IYZ^M$
-b or –number-nonblank
This option used to display line numbers only in the non-empty lines.
$ cat -b cat_example.txt
1 ABC DEF GHI 2 JKL MNO PQR 3 STU VWX YZ
-e
It is equivalent to –vE option. It displays all the non-printing characters (^ and M-) and displays $ at the end of each line
-e = -vE
$ cat -e cat_example.txt ABC DEF GHI^M$ ^M$ JKL MNO PQR^M$ ^M$ ^M$ STU VWX YZ^M$
-E, –show-ends
Displays $ symbol at the end of each line.
$ cat -E cat_example.txt ABC DEF GHI$ $ JKL MNO PQR$ $ $ STU VWX YZ$
-n, –number
Displays line number in all the lines even it is a empty line.
$ cat -n cat_example.txt 1 ABC DEF GHI 2 3 JKL MNO PQR 4 5 6 STU VWX YZ
-s, –squeeze-blank
It combines more than one empty lines to one empty line. In the below example, you can see 4th and 5th empty lines are combined to one empty line.
$ cat –s cat_example.txt ABC DEF GHI JKL MNO PQR STU VWX YZ
-t
This option shows all the non-printing characters (^ and M-) and TABS as ^I. It is equivalent to –vT.
$ cat -t cat_exampleÂ.txt ABC^IDEF^IGHI^M ^M JKL^IMNO^IPQR^M ^M ^M STU^IVWX^IYZ^M
-T, –show-tabs
Displays TAB space as ^I in the file.
$ cat -T cat_exampleÂ.txt ABC^IDEF^IGHI JKL^IMNO^IPQR STU^IVWX^IYZ
-v, –show-nonprinting
Displays the non-printing characters (^ and M-) in the files.
$ cat -e cat_example.txt ABC DEF GHI^M ^M JKL MNO PQR^M ^M ^M STU VWX YZ^M
– -help
It displays the manual page of cat command which includes usage, options and example of cat command. It just displays the help infirmation and exit.
$ cat --help
– -version
Displays version, license and author of cat command. Like –help option, it too displays the version information and exit.
$ cat --version
You have any doubts or feedback? Let us know in the comments below.
Thanks for the detailed description with examples. Keep going…
Thanks JamunaRani…