LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Why do you have to tar before gzip? (https://www.linuxquestions.org/questions/linux-newbie-8/why-do-you-have-to-tar-before-gzip-749032/)

anon091 08-20-2009 10:03 AM

Why do you have to tar before gzip?
 
Maybe i'm confused, but doesn't tar just gather everything into one file, then gzip zips that one tar'd file? couldn't you just gzip whatever files/directories you want directly? or am i thinking to Windows-ey haha

jdkaye 08-20-2009 10:08 AM

Quote:

Originally Posted by rjo98 (Post 3650958)
Maybe i'm confused, but doesn't tar just gather everything into one file, then gzip zips that one tar'd file? couldn't you just gzip whatever files/directories you want directly? or am i thinking to Windows-ey haha

I don't think gzip will preserve the directory structure intact. Most of the tarballs that I've seen have fairly elaborate structure that needs to be preserved.
Cheers,
jdk

anon091 08-20-2009 10:12 AM

ok, thanks.

pwc101 08-20-2009 10:16 AM

gzip only works on single files. If you wanted to generate an archive of an entire directory structure, you'd only be able to generate individual gzipped files. tar groups the directory structure into a single file, then gzip compresses that single file.

Creating a compressed tarball of a single file is a redundant measure, you could just gzip the single file and remove the tar overhead.

anon091 08-20-2009 10:17 AM

Makes sense, thanks!

fpmurphy 08-20-2009 10:26 AM

You can use the tar -z option to tar and gzip in one operation. Alternatively the -j option to tar and bzip2.

anon091 08-20-2009 10:26 AM

cool!

heysean 08-20-2009 01:22 PM

What are everyone's preferences regarding using gzip and bzip2?
There has to be a difference and one is going to have a better compression ratio... perhaps on certain filetypes?

Tinkster 08-20-2009 01:31 PM

bzip2 is generally better, but gzip is significantly faster.

chrism01 08-20-2009 06:51 PM

Bear in mind that both gzip
http://linux.die.net/man/1/gzip
and bzip2
http://linux.die.net/man/1/bzip2
have compression vs speed options, expressed as a num 1-9, so its best to read those links and test if you really want to know. The general assumption (which may be wrong) is that the default(!) settings are such that gzip tends to be quicker, but bzip2 tends to compress better ... your choice & YMMV.
;)

jschiwal 08-20-2009 07:26 PM

I once experimented, zero'ing out free space on a partition (/boot) and piping the output of dd through bzip2 and gzip. I was surprised that in this test, the gzip'ed image backup was smaller, but not by much. The only way to know for sure is to run test experiments yourself.

anomie 08-20-2009 07:37 PM

Quote:

Originally Posted by heysean
What are everyone's preferences regarding using gzip and bzip2?
There has to be a difference and one is going to have a better compression ratio... perhaps on certain filetypes?

At least on the size of files I'm normally working with, any differences are negligible. By force of habit I stick with gzip.

$ tar cfz ... is easier for me to remember than $ tar cfj ...


All times are GMT -5. The time now is 06:31 AM.