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.

Does anyone know how multiple files can be GZIP compressed?
I have lots of files in a folder and I need to compress them individually.

Actually, I've found a way to do it. GZIP command line binary does the job.

I've used gzip -r dir.

Thanks for your efforts.

share|improve this question
    
Which operating system ? –  Karolos Feb 10 '12 at 20:19
    
Win7 , sorry :) –  avetarman Feb 10 '12 at 20:20
1  
@avetarman, Please add what you did as an answer, and accept it, rather than just putting the answer in the question –  soandos Feb 10 '12 at 21:14

5 Answers 5

Try the following in powershell (after going to the correct directory):

$files = get-childitem
foreach ($file in $files) {gzip $file}

That will go through all the files in the directory, and compress all of them.

Edit: If you want to do all of the files in a directory tree (i.e. in a folder and all its subfolders) just change $files = get-childitem to $files = get-childitem -recurse

share|improve this answer
2  
This could be extended for just about any CLI-capable compression utility, including 7zip. –  music2myear Feb 10 '12 at 20:59
    
Yup. Nice and adaptable that way. (on an unrelated note, when you edit links, check them first as I have seen some missed parenthesis on some of your edits. Not a big deal, but I thought you should know) –  soandos Feb 10 '12 at 21:04
    
Thx for the heads up. –  music2myear Feb 10 '12 at 21:11

I would use a for loop. Are you concerned that the executable will be loaded many times? That should not be much, compared to the time taken to compress.

share|improve this answer
1  
Perhaps provide the code that will do this? –  soandos Feb 10 '12 at 20:35

Use 7-Zip for better compression

share|improve this answer
    
Thanks, but it only makes a single compressed archive. It doesn't treat the files individually. –  avetarman Feb 10 '12 at 20:29
    
Siva that is not an answer to the question. It is a statement of a true fact. A unrelate true fact –  Oxinabox Feb 11 '12 at 0:58

GZIP can be used to compress individual files sure... but most of the time you'll see minimal amounts of disk-space savings. Files that take up 1 sector will consume 1-full-sector of disk space, even if the file is less than the sector-size. (i.e. sector-size = 16kb, the file is 8kb... 'compressed' is 5kb... still takes up 16kb of "disk-space") The power of gzip is much more evident when you combine all the files into a single file (using tar typically) and then compress the singular archive. (combined, the "archive" can take all the files and combine them into 1 singular file on the disk... which will have less "dead-space" between sectors)

For example:

tar -czf compressed_archive.tgz folder/*

tar -c creates an archive, z uses gzip compression, and f writes the results to a file called compressed_archive.tgz. You can also switch to using bz2 compression (which does better in many cases) by simply switching the z switch to a j.

If you want to then extract files from the archive, you can simply do the reverse

tar -zxf compressed_archive.tgz

which would x extract the files that were z gzip'd, f from the archive file called compressed_archive.tgz.

share|improve this answer
    
Thanks. I don't need an archive. I was looking for compressing the files recursively. It's for a sitemap. Thanks again. –  avetarman Feb 10 '12 at 20:51

Just use the gzip alone.

by default, gzip will take any file passed to it and compress it and add the .gz extension. i.e.

gzip dir/* -r

would gzip every file in dir/* (and sub-directories).

share|improve this answer

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.