I am trying to zip an entire folder. There's this -r command to zip a folder recursively. Now this is good to zip all the files in a folder, but my predicament is I want to zip the folder in it's entirety and not its contents individually. For instance, if I have a folder E:\foo which contains 2 files zoo and bar; I want to zip E:\foo, and have a zipped file E:\foo.gz created. Please help

  • This question is confusing. The question's subject talks about "gzip", but then the question talks about "I want to zip", and then talks about a file named "foo.gz". Zipping is creating *.zip files, gzipping is creating *.gzip files. It seems people are treating the word "zip" to be "compress", because that assumption is the only way to really make Ritesh's question make any sense. If that assumption is wrong, then Retesh should re-phrase the question to clarify. If that assumption is right, then the desired goal is not a feature of gzip, so afrazier's answer is clear and right. – TOOGAM Nov 6 '15 at 17:36

You can't do what you what with gzip. It's a single stream archiver, so it has no ability to handle multiple files. If you really want to use gzip, you'll have to combine it with a second tool that can combine multiple files into a single stream that it can archive. This is tar's purpose.

The tar command line in @Alex's answer should put you on the right path. You should be able to get a Windows port of tar from the same place you got gzip.

| improve this answer | |

If you're using Linux, you'll want to use tar to invoke the gzip command, because tar will create an archive of the folder (pack it all into one file), and then gzip will zip that folder archive that has been converted to a single file. This can be accomplished with a single command:

tar cvzf file.tgz /path/to/folder

c is the create flag (create an archive) v is verbosity - shows files as they are being archived z is to use gzip - (j can be used to use bzip2 instead for better compression) f is for file - the filename of the archive you want to create should follow

Hope this helps!

| improve this answer | |
  • Did you see the "Windows" tag in the question? – DavidPostill Nov 6 '15 at 14:55
  • Please read the question again carefully. Your answer does not answer the original question. – DavidPostill Nov 6 '15 at 14:56

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.