Linux Command - cat

cat - print and concatenate files.

Syntax

1
cat [OPTION] [FILE]...

Description

Concatenate FILE(s), or standard input, to standard output.

Option Description
-n –number Number all output lines including blank lines

Example

1
cat file1
1
cat -n file1

concatenate files into a single file

1
cat file1 file2 > file3

concatenate files and append to file3

1
cat file1 file2 > file3

clean up the contents in file1

1
cat /dev/null > file1

Pass a multi-line string to a file

You can sometimes see cat command use together with heredoc

1
2
3
4
cat <<EOF > print.sh
#!/bin/bash
echo "Hello World"
EOF

concatenate and print files in reverse order

1
tac file1

tac is the reverse of cat.

Reference