How to Concatenate Files in Linux with cat command
In Linux cat command used to concatenate one or more files together. By default cat command reads the file and print output to the terminal.
cat file1.txt
You can save the output to a another file with output redirections.
cat file1.txt > file2.txt
If file2.txt does not exist, it will be created.
Concatenate Two or More Files with cat command
The Linux cat command can combine two or more files together. Following example will combine file1.txt and file2.txt and print output to the terminal.
cat file1.txt file2.txt
The following cat command will concatenate three files and save it as file4.txt.
cat file1.txt file2.txt file3.txt > file4.txt
To display line numbers, use the -n option.
cat -n file1.txt