cat command to concatenate files in Linux
The cat is a Linux command which is widely used to create single or multiple files, view contains file, concatenate files and redirect output in terminal or files. These files are read and output in the order they appear in the command arguments.
$cat [options] filename
Commonly used options:
|-b||Starting at 1, number non-blank output lines.|
|-n||Starting at 1, number all blank and non-blank output lines.|
|-s||.suppress repeated empty output lines|
|-v Display control and non-printing characters. Control characters print as ^B for control-B. Non-ASCII characters with the high bit set display as “M-” followed by their lower 7-bit value.|
The following operators can be used with the cat command:
|>||Redirect the output of the cat command to a file rather than standard output. The destination file will be created if it doesn’t exist and will be overwritten if it does.|
|>>||Append the output of the cat command to the end of an existing file. The destination file will be created if it doesn’t exist.|
||||Send (or pipe) the output of the cat command into another command for further processing.|
cat to display the contents of file
cat to view contents of multiple files in terminal
$cat filename1 filename2 ...
cat to create a file
$cat > paperguide.txt
After this command, a cursor will blink on terminal i.e you have to write your desired contents here and after it, you need press ctrl + d to come out.
cat to merge files
$cat filename1 filename2 > filename
cat with sort command
$cat filename1 filename > filename | sort filename
using sort command your contents will be sorted alphabetically.