LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 10:03 AM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
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, 10:08 AM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

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, 10:12 AM   #3
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
ok, thanks.
 
Old 08-20-2009, 10: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, 10:17 AM   #5
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

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

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, 10:26 AM   #7
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
cool!
 
Old 08-20-2009, 01: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, 01:31 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
bzip2 is generally better, but gzip is significantly faster.
 
Old 08-20-2009, 06:51 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 07:26 PM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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, 07: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



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 02:20 AM
When to use tar , gzip and tar+gzip ? tofee Linux - Newbie 4 03-31-2006 05:59 AM
tar and gzip c0c0deuz Linux - General 2 10-31-2002 03:04 PM
dd, tar and gzip nabil Linux - General 3 01-18-2002 04:51 PM
Need Serious Help With Tar And Gzip!! Please! rootlinux Linux - General 2 12-16-2001 01:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:49 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
Open Source Consulting | Domain Registration