How does `cat` combine multiple files?

QuestionsQuestions8 SkillsProDec, 18 2025
0144

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 file1 and file2.
  • The > symbol tells Linux: "Don't print this to the screen; instead, put it into combined_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:

  1. echo "Hello" > part1
  2. echo "World" > part2
  3. cat part1 part2 > together
  4. cat together

You will see that the file together now contains both words!

0 Comments

no data
Be the first to share your comment!