1

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.

  • 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 May 12 '12 at 11:59
  • thats what i want collect all files in one file how to do it by tar? – rezx May 12 '12 at 12:04
  • @rezx: "Use tar" is an answer to your posed question. To find out how it works, issue man tar. – Daniel Andersson May 12 '12 at 12:16
  • founded ' tar cvf output_filename.tar /path/to/dir1 ' ^_^ – rezx May 12 '12 at 12:17
  • u may vote to delete the post. – rezx May 12 '12 at 12:22
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.

  • not work well, but i try this tar cf x.tar * – rezx May 12 '12 at 14:36
  • @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 May 12 '12 at 14:39
  • cool, but what if i hve 50 files i cant write every file name, cant i use . ? – rezx May 12 '12 at 15:39
  • @rezx: cat * > output – Der Hochstapler May 12 '12 at 16:23
  • @ oliver, work perfect :) – rezx May 12 '12 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.