Compress multiple files

Hi Friends,

Can anyone help me out with compressing multiple files.
I have multiple files in directory , I have to compress these into a single file,
I tried using
gzip -r outfile.gz file1 file2 file3.

It is not working

Thanks in advance for your help
S :slight_smile:

gzip -c file1 file2 > foo.gz

however this will compress better:

cat file1 file2 file3 | gzip -c > foo.gz

[quote=reborg]

gzip -c file1 file2 > foo.gz

Thank you very much for your quick reply.
I have tried this command
here it is compressing the two files in to a single file,
If we unzip this file it is chowing as a single file ,
instead can this be upzipped in to two files.

then, for standard unix utilities, you must first "tar" the files into a single file, then compress.

Check the man pages on tar and gzip. You will want to use the "-c" parameter, if you want to do this as a single step.

Otherwise, get pkzip for your machine/version of unix, and use it.

Generally, I think its:

Create a tar file: tar cvf <tar.filename> <files.to.tar.up>
Extract a tar file: tar xvf <tar.filename>
Check the contents of a tar file: tar tvf <tar.filename>

To use tar and gzip/compress together, you will have to use the pipe '|'.

Like this:
To compress:

tar -cf - list_of_file_names | gzip > output_file.tar.gz

To uncompress:

gzip -dc output_file.tar.gz | tar -xf -