That's a great question! Since cat stands for concatenate (which means to link things together in a chain), combining files is exactly what it was designed to do.
Here is how you can use cat to combine multiple files:
1. Displaying Multiple Files Together
If you simply want to see the contents of two files joined together on your terminal screen, you list them one after another:
cat file1 file2
This will print everything in file1 first, followed immediately by everything in file2.
2. Merging into a New File
Most of the time, you'll want to save that combined content into a brand-new file. To do this, you use the output redirection symbol (>):
cat file1 file2 > combined_file.txt
- The system takes the contents of
file1andfile2. - The
>symbol tells Linux: "Don't print this to the screen; instead, put it intocombined_file.txt."
3. Appending to an Existing File
If you want to add the contents of one file to the end of an existing file (without deleting what's already there), you use the double arrow (>>):
cat file2 >> file1
This takes the content of file2 and "glues" it to the bottom of file1.
Try it out in your VM!
You can create two quick files and merge them right now:
echo "Hello" > part1echo "World" > part2cat part1 part2 > togethercat together
You will see that the file together now contains both words!