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?
migrated from stackoverflow.com Jul 9 '10 at 12:30
This question came from our site for professional and enthusiast programmers.
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.
It will create a compressed file named file.txt.gz
MacOS X is Unix so this should work (this work on GNU/Linux)
tar czvf compressed.tar.gz folder
Yes, you have do tar the directory first. The tar-command can do both:
extract your archiv:
To add to the answer by @taskinoor: if you use single file version, aka
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 :=)
Yes, this is correct.
If somebody is still finding this question when searching "gzip in Mac", I wrote a guide that it may be useful to somebody else. Here it goes:
The most basic command will compress the file
If you don't want to lose your original file, then you need to pipe the output of
We can also compress from standard input, so we can compress the output of other commands.
OS X also comes with the
To restore a file to it's uncompressed natural state you can use gzip or other of the wrappers. The decompression mode of gzip is called with the
We can also pipe the decompressed file to the standard output to save it to another file.
Another quick way of reading the content of a gzip to standard output is
But fear not!
This is very useful if you need to check the content of a file really quick, and you can even save the output of zcat to a file, just as easy.
I hope you find my guide useful :)