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 am new to Mac command prompt stuff. How do you create a gzip of a folder in Mac OS X? I was told by a few folks that if you want to create a gzip of a folder you should 'tar' it first and then 'gzip' it. Is this correct?

share|improve this question

migrated from stackoverflow.com Jul 9 '10 at 12:30

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

    
This isn't a programming question? Your post is tagged with objective-c but you're asking about the command-line. –  rakuo15 Jul 9 '10 at 12:04

5 Answers 5

up vote 41 down vote accepted

Tar is the archive tool and gzip is the compression tool. In order to compress a full directory, first you need to archive it to a single file. That's what the job is tar. and then you compress the archived file. You can do both task in a single tar command with proper option.

tar -czf folder_name.tar.gz folder_name/

If you don't want to make a tar archive (may be you want to compress just a single file), then you can use gzip command directly.

gzip file.txt

It will create a compressed file named file.txt.gz

share|improve this answer
14  
It's worth mentioning what the options -czf after tar are for: c indicates that you want to create a tar archive, z applies gzip on the intermediate tar archive, and f is for the subsequent final file name folder_name.tar.gz. –  fideli Jul 9 '10 at 19:11

MacOS X is Unix so this should work (this work on GNU/Linux)

tar czvf compressed.tar.gz folder
share|improve this answer

Yes, you have do tar the directory first. The tar-command can do both:

tar -czf archiv.tar.gz mydir/

extract your archiv:

tar -xzf archiv.tar.gz
share|improve this answer

To add to the answer by @taskinoor: if you use single file version, aka

gzip file.txt

be aware that the original file (file.txt) will be removed and you'll have only file.txt.gz

I would put this as comment but dont have enough karma to do that :=)

share|improve this answer

Yes, this is correct. gzip can only compress a file. tar encodes the directory contents into a single file, which can be further compressed using gzip, bzip2, lzma or anything else.

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.