Linux cmd to copy file to an existing file without overwriting it

4.6k views Asked by At

Now I am having two files. File A and file B. Both files contain of information inside. I am having issues on how to copy the information in file A to file B without removing or overwriting the information in file B by using Linux command prompt.

File A:

1
2
3

File B:

A
B

What i want to achieve by using Linux prompt: File B:

A
B
1
2
3

Please advice me on how should I do it, thank you!

1

There are 1 answers

0
Some programmer dude On BEST ANSWER

How about concatenating the files?

Like

$ cat A >> B

The cat command will display the contents of file A, but the redirection operator (>>) will cause the output to be appended to the end of file B.

Or if you don't want to change the contents of either file, you can use the cat command to create a third file (cat actually stands for conCATenate):

$ cat A B > C

The above command will display the contents of file A followed by the contents of file B, with the output redirected (with >) to create a new file C which will contain the contents of file A and B.