Copy Multiple Files Into One File


Recommended Posts

Hi guys

I was wondering if it is possible to copy the contents of several files into a new file?

I have 3 files conf1.txt, conf2.txt, conf3.txt

I want to put the contents of all 3 files into one file; masterconf.txt

Is this possible? If so, can someone give me the syntax?

I tried a few different cp commands, but without the desired results.I haven't seen this covered in Google, only copying multiple files into one directory, etc..

Thanks!

Edit:

I've found batch files from Googling, but that's not exactly what I am looking for, and my feeble mind doesn't understand them. :unsure:

Edited by DumbTerminal
Link to post
Share on other sites

I am not sure I am following. Do you want to put them in something like a zip file? in linux there is the tar file.

the idea would be to make a directory, and call it for example: conf_files, then move all of your .txt files to the directory called conf_files.

now to tar up the files into one file do the following command

tar -cf conf_files.tar conf_files

edit added later//

if you just want to make one long text file. you could do this

cat {conf1.txt,conf2.txt,conf3.txt} >> newfile.txt

Edited by shanenin
Link to post
Share on other sites
I am not sure I am following. Do you want to put them in something like a zip file? in linux there is the tar file.

the idea would be to make a directory, and call it for example: conf_files, then move all of your .txt files to the directory called conf_files.

now to tar up the files into one file do the following command

tar -cf conf_files.tar conf_files

<{POST_SNAPBACK}>

No, I wanted to copy all of the information in the 3 seperate configuration files into one single configuration file.

I just copied the info from the 3 files individually and pasted it into one file.

I was just thinking it would be cool if there were a quicker, easier way to do that.

Thanks for responding

Link to post
Share on other sites
I ammended my first post, with what you wnated to do

<{POST_SNAPBACK}>

Sweet, thanks very much

I thought I had a bookmark on how to do that, but I couldn't find it.

I forgot about using cat to write out contents...

I learn so much (sometimes TOO much) about CLI everyday.

I have several conf files I want to experiment with, and this will probably save me literally hours!

Thanks again. :matrix:

Link to post
Share on other sites

you could also have done it manually, one file at a time

cat conf1.txt > new_file.txt
cat conf2.txt >> new_file.txt
cat conf3.txt >> new_file.txt

using one '>' will cause the info for cat conf1.txt to erase and start a new file. using two '>>' will cause the file to be ammened to the end.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...