LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-20-2009, 11:03 AM   #1
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Rep: Reputation: 46
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
 
Old 08-20-2009, 11:08 AM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Quote:
Originally Posted by rjo98 View Post
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
 
Old 08-20-2009, 11:12 AM   #3
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
ok, thanks.
 
Old 08-20-2009, 11:16 AM   #4
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
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.
 
Old 08-20-2009, 11:17 AM   #5
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
Makes sense, thanks!
 
Old 08-20-2009, 11:26 AM   #6
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 297

Rep: Reputation: 62
You can use the tar -z option to tar and gzip in one operation. Alternatively the -j option to tar and bzip2.
 
Old 08-20-2009, 11:26 AM   #7
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
cool!
 
Old 08-20-2009, 02:22 PM   #8
heysean
LQ Newbie
 
Registered: Aug 2009
Posts: 6

Rep: Reputation: 0
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?
 
Old 08-20-2009, 02:31 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
bzip2 is generally better, but gzip is significantly faster.
 
Old 08-20-2009, 07:51 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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.
 
Old 08-20-2009, 08:26 PM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
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.
 
Old 08-20-2009, 08:37 PM   #12
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
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 ...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
About tar and gzip commands satimis *BSD 2 05-29-2007 03:20 AM
When to use tar , gzip and tar+gzip ? tofee Linux - Newbie 4 03-31-2006 06:59 AM
tar and gzip c0c0deuz Linux - General 2 10-31-2002 04:04 PM
dd, tar and gzip nabil Linux - General 3 01-18-2002 05:51 PM
Need Serious Help With Tar And Gzip!! Please! rootlinux Linux - General 2 12-16-2001 02:39 PM


All times are GMT -5. The time now is 04:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration