Merge files in Linux

Introduction

About what kinds of files there are in Linux and what else besides merging you can do with them read in the article «Files in Linux»

Merging files

Files in Linux can be merged in different ways. In this article you will learn how to do it with the commands cat and echo

cat

To merge the file one with the file two it is enough to run

cat one two

You can merge several files at once.

Consider three files one , two , three with the following contents

one

Cool bookstore: Book24

two

Best hotels: Booking.com

three

Official Samsung Store: Samsung

Let us merge them and check the result - it appears in the console just as with two files

cat one two three

Cool bookstore: Book24
Best hotels: Booking.com
Official Samsung Store: Samsung

Now let us merge the files into one new file big

cat one two three > big
vi big

Cool bookstore: Book24 Best hotels: Booking.com Official Samsung Store: Samsung

To the new file big we can append the file one

cat big one

Cool bookstore: Book24
Best hotels: Booking.com
Official Samsung Store: Samsung
Cool bookstore: Book24

echo

The file two can be written to the end of the file one

echo $(<two) >> one

Merging .pdf files

This section is in a separate article

«Merging .pdf files»

Article author: Andrei Olegovich