Append Multiple Files Into One File
Sometimes, you might have a bunch of files, and you want to put all their stuff into one file. It could be logs you want to look at together or many text files you want to edit as one. On Linux, there are different ways to do this, and I’ll tell you about four of them.
Using the cat command
Open a terminal (like a command window) and go to the folder where your files are.
Use the ‘ls’ command to see your files.
Type this command, replacing “file1” and “file2” with your file names:
$ cat file1 file2 >> combined_file
Using the echo command
Open a terminal and go to the folder with your files.
Type these commands, replacing “file1” and “file2” with your file names:
$ echo " " >> combined_file $ echo "Contents of file1:" >> combined_file $ cat file1 >> combined_file $ echo " " >> combined_file $ echo "Contents of file2:" >> combined_file $ cat file2 >> combined_file
Using the sed command
Open a terminal and go to the folder with your files.
Type this command, replacing “file1” and “file2” with your file names:
$ sed '$ a ' file1 file2 >> combined_file
Using the paste command
Open a terminal and go to the folder with your files.
Type this command, replacing “file1” and “file2” with your file names:
$ paste file1 file2 >> combined_file
Conclusion
These are four ways to put the content of many files into one file on Linux. Each way has its good points and not-so-good points. Pick the one that suits your needs best. Doing this can save you time and make it easier to handle lots of data at once.