0% found this document useful (0 votes)
2 views8 pages

RHEL 7 Cat Command

The document provides an overview of the 'cat' command in Linux and Unix, detailing its functionalities such as displaying, reading, creating, and concatenating text files. It includes syntax, various command options, and practical examples for using the command effectively. Additionally, it covers related commands and options for modifying output, such as displaying line numbers, suppressing empty lines, and redirecting output.

Uploaded by

abhisheksafeeka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

RHEL 7 Cat Command

The document provides an overview of the 'cat' command in Linux and Unix, detailing its functionalities such as displaying, reading, creating, and concatenating text files. It includes syntax, various command options, and practical examples for using the command effectively. Additionally, it covers related commands and options for modifying output, such as displaying line numbers, suppressing empty lines, and redirecting output.

Uploaded by

abhisheksafeeka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Cat Linux Unix Command

Cat :

 Display text file on screen


 Read text file
 Create a new text file
 File concatenation
 Modifying file

Syntax of cat command :

# cat <options> <File>

Cat command options :

Option Description

-A --show-all Equivalent to -vET.

-b --number-nonblank Number nonempty output lines. This


option overrides -n

-e Equivalent to -vE.

-E --show-ends Display $ at end of each line.

-n, --number Number all output lines.

-s, --squeeze-blank Suppress repeated empty output lines.

-t Equivalent to -vT.

-T, --show-tabs Display TAB characters as ^I.

-v, --show- Show nonprinting i.e. use ^ and M-


nonprinting notation, except for LFD and TAB.

--help Display this help and exit.

--version Output version information and exit.


1 . The cat commands to view content of a file on the standard output
(stdout) cat [filename]

[[agoutam@rhel7 ~]$ cat file1


Linux
Unix
Solaris
HPUX
AIX
[agoutam@rhel7 ~]$

2. To display multiple files using cat


cat [filename] [filename] ...

[agoutam@rhel7 ~]$ cat file1 file2 file3


Linux
Unix
Solaris
HPUX
AIX
Suse
Fedora
CentOS
OEL
Ubuntu
Hosting
Machine
[agoutam@rhel7 ~]$

3 . cat command without filename arguments

if we don’t specify any arguments in the cat command then it will read
the inputs from the keyboard attached to the system. Type some text
after entering the cat command, output will be copy of input provided.

[agoutam@rhel7 ~]$ cat


without argument filename line is written
without argument filename line is written

4 .-n command line option :To display contents of a file preceding


with line numbers
cat -n [filename]
[agoutam@rhel7 ~]$ cat -n file1
1 Linux
2 Unix
3 Solaris
4 HPUX
5 AIX
[agoutam@rhel7 ~]$

5 . To create file using cat command


cat > [name-of-new-file]

[agoutam@rhel7 ~]$ cat > createfile


File is created

Blank line above


next word separated by TAB

above 2 line contain 2 empty line

6 . To Display Multiple Files at Once

Three files test, file1 and file2 and able to view the contents of
those file as shown above. We need to separate each file with ; (semi
colon).

[agoutam@rhel7 ~]$ cat file1 ; cat file2 ; cat file3


Linux
Unix
Solaris
HPUX
AIX
Suse
Fedora
CentOS
OEL
Ubuntu
Hosting
Machine
[agoutam@rhel7 ~]$

7 . To copy the contents of one file to another file .When run, the
command requires you to enter the information on the terminal Once
you're done press CTRL+d
cat [filename-whose-contents-is-to-be-copied] > [destination-filename]

[agoutam@rhel7 ~]$ cat createfile > destinationfile


[agoutam@rhel7 ~]$ cat destinationfile
File is created

Blank line above


next word separated by TAB

above 2 line contain 2 empty line


[agoutam@rhel7 ~]$

8 . -E command line option :To make cat highlight end of lines. The
tool does this by displaying $ at the end of each line. ‘$‘ shows at
the end of line and also in space showing ‘$‘ if there is any gap
between paragraphs. This options is useful to squeeze multiple lines
in a single line.
cat -E [filename]

[agoutam@rhel7 ~]$ cat -E createfile


File is created $
$
Blank line above $
next word separated by TAB$
$
$
above 2 line contain 2 empty line$
[agoutam@rhel7 ~]$

9 . -s command line option : To make cat suppress repeated empty lines


cat -s [filename]

[agoutam@rhel7 ~]$ cat -s createfile


File is created

Blank line above


next word separated by TAB

above 2 line contain 2 empty line


[agoutam@rhel7 ~]$
10 .-T command line option :To make cat display tab characters as ^I
cat -T [filename]

[agoutam@rhel7 ~]$ cat -T createfile


File is created

Blank line above


next word separated by^ITAB

above 2 line contain 2 empty line


[agoutam@rhel7 ~]$

11 .tac command line option : The cat command to display content in


reverse order. This can be done using the tac command line option
tac [filename]

[agoutam@rhel7 ~]$ cat file1


Linux
Unix
Solaris
HPUX
AIX
[agoutam@rhel7 ~]$
[agoutam@rhel7 ~]$ tac file1
AIX
HPUX
Solaris
Unix
Linux

12 . -A command line option :The -E and -T option together, then


instead of writing -ET in the command, you can just use the -A command
line option.
cat -A [filename]

[agoutam@rhel7 ~]$ cat -A createfile


File is created $
$
Blank line above $
next word separated by^ITAB$
$
$
above 2 line contain 2 empty line$
[agoutam@rhel7 ~]$
13 .Appending the contents of one file to another.

Using double greater than symbol ‘>>‘ in cat command we can append the
contents of one file to another :

[agoutam@rhel7 ~]$ cat file1


Linux
Unix
Solaris
HPUX
AIX
[agoutam@rhel7 ~]$ cat file2
Suse
Fedora
CentOS
OEL
Ubuntu
[agoutam@rhel7 ~]$ cat file1 >> file2
[agoutam@rhel7 ~]$ cat file2
Suse
Fedora
CentOS
OEL
Ubuntu
Linux
Unix
Solaris
HPUX
AIX
[agoutam@rhel7 ~]$

14 .Redirecting the output of multiple files into a Single File.

[agoutam@rhel7 ~]$ cat file1


Linux
Unix
Solaris
HPUX
AIX
[agoutam@rhel7 ~]$ cat file3
Hosting
Machine
[agoutam@rhel7 ~]$ cat file1 file3 >file12merge
[agoutam@rhel7 ~]$ cat file12merge
Linux
Unix
Solaris
HPUX
AIX
Hosting
Machine
[agoutam@rhel7 ~]$

15 .Getting input using standard input operator.

[agoutam@rhel7 ~]$ cat < file1


Linux
Unix
Solaris
HPUX
AIX
[agoutam@rhel7 ~]$

16 .Sorting the output of multiple files into a single file

[root@linuxtechi ~]# cat linux_text linux_distributions /etc/passwd |


sort > linux_sort

17 .-v option in the cat command :To show the non-printing characters
in the output. This option become useful when we are suspecting the
CRLF ending lines, in that case it will show ^M at the end of each
line.
[root@linuxtechi tmp]# cat -v test_file

18 Display the output of a file using page wise.


[root@linuxtechi ~]# cat /etc/passwd | more
[agoutam@rhel7 ~]$ cat /etc/passwd |less

You might also like