Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have 100 files: cvd1.txt cvd2.txt ... cvd100.txt

How to gzip 100 files into one .gz file so that after I gunzip it, I should have cvd1.txt, cvd2.txt ... cvd100.txt separately?

Thanks for your help

share|improve this question

migrated from stackoverflow.com Sep 12 '11 at 22:05

This question came from our site for professional and enthusiast programmers.

4 Answers 4

up vote 9 down vote accepted

if you have zip,

zip myzip.zip cvd*.txt

Don't need to tar them first.

share|improve this answer
1  
@Kurumi- Do Windows programmes such as Winzip or 7-zip recognise .zip files? –  Tony Mar 29 '11 at 1:45
1  
@Tony. I believe they do. I tested the 7-zip linux version with zip and able to extract. If you want, there is also GNU zip for windows. –  kurumi Mar 29 '11 at 2:06

gzip by itself does not know anything about file structure. To do what you want, you need to first put the files into some kind of container file (e.g. a tar structure, or similar) and then gzip that. tar has z and j (for bzip2) switches on GNU platforms to do this.

share|improve this answer
1  
The switch is actually 'z' ('x' is for extract). Nice you mentioned 'j'/bzip2 - much tighter compression. –  Tony Delroy Mar 29 '11 at 2:09
    
whoops, fixed. thanks! –  Joe Mar 29 '11 at 6:30

You'll want to use tar, like so:

tar -czvf file.tar.gz cvd*.txt

tar puts the files together, while gzip then performs the compression.

Quoth the gzip manpage:

If you wish to create a single archive file with multiple members so that members can later be extracted independently, use an archiver such as tar or zip. GNU tar supports the -z option to invoke gzip transpar‐ ently. gzip is designed as a complement to tar, not as a replacement.

share|improve this answer

You want to tar your files together and gzip the resulting tar file.

tar cfvz cvd.tar.gz cvd*.txt

To untar the gzip'd tar file you would do:

tar xfvz cvd.tar.gz -C /path/to/parent/dir

This would extract your files under the /path/to/parent/dir directory

share|improve this answer
3  
if you name the file with the extension .tgz, (short for tar gz), then Windows programs will recognize it as something that winzip etc can process as is. Congrats to SiegeX for your 10K! –  shellter Mar 29 '11 at 1:29
    
@shelter good comment. Thanks for the kind words –  SiegeX Mar 29 '11 at 1:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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