How can I combine several files into one?

1

3

How can I collect several files into a single file?

I tried GZip, but could only get it to create separate files.

It does not have to be compressed.

rezx

Posted 2012-05-12T11:50:32.320

Reputation: 185

I'm not entirely sure what you're asking, but the typical format for creating an archive (without compression) containing many files in Linux is tar. It is then possible to compress the tar file. I believe commands such as gzip are supposed to work on single files and must be combined with tar for multiple files, e.g. .tar.gz would be a compressed (gzipped) tar.

– Bob – 2012-05-12T11:59:37.627

thats what i want collect all files in one file how to do it by tar? – rezx – 2012-05-12T12:04:52.520

@rezx: "Use tar" is an answer to your posed question. To find out how it works, issue man tar. – Daniel Andersson – 2012-05-12T12:16:08.817

founded ' tar cvf output_filename.tar /path/to/dir1 ' ^_^ – rezx – 2012-05-12T12:17:31.850

u may vote to delete the post. – rezx – 2012-05-12T12:22:33.230

Answers

5

Simply use cat:

cat file1 file2 file3 > output

If you want to combine all files in the current directory:

cat * > output

If you need to adjust the order of the files in the output, use echo first to get all filenames:

echo *

Then supply them in the desired order to cat.

Der Hochstapler

Posted 2012-05-12T11:50:32.320

Reputation: 77 228

not work well, but i try this tar cf x.tar * – rezx – 2012-05-12T14:36:28.407

@rezx: Well, cat just combines the files into a single target (as requested). It doesn't store any information to get the original files back. If you want a file archive, then, yes, tar is a much better choice ;) – Der Hochstapler – 2012-05-12T14:39:33.380

cool, but what if i hve 50 files i cant write every file name, cant i use . ? – rezx – 2012-05-12T15:39:26.700

@rezx: cat * > output – Der Hochstapler – 2012-05-12T16:23:43.983

@ oliver, work perfect :) – rezx – 2012-05-12T19:11:32.413