LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   options with tar -j -z are optional (https://www.linuxquestions.org/questions/linux-general-1/options-with-tar-j-z-are-optional-777869/)

Aquarius_Girl 12-24-2009 07:02 AM

options with tar -j -z are optional
 
Hi,

I tried to untar bz2 and gz files with

tar -xf x.tar.bz2
tar -xf y.tar.gz

on OpenSuse 11.2

Both worked properly without -j or -z options !
When i search the net, I saw that every document writer is bent on specifying the -j and -z options with the respective files !

does it improve the quality or performance coz. i didnt see any one doing a tar without these options ??

MTK358 12-24-2009 08:29 AM

That works for me on Fedora.

It must automatically detect the .bz2 of .gz extension, or maybe bz2 or gz's magic number. That's actually very convenient for me because I often get confused with those 'j' and 'z' flags.

And there is no way that performance is reduced, because a 'gz' file and a 'tar' file are completely unrelated formats.

Unlike the Windows .zip format leads you to think, compression and archiving are completely separate tasks.

It's just that bzip2 and gzip are only compression formats. That is, they just compress a single stream of bytes, and they do not have the functionality to store information about a directory tree in there.

tar is just an archiving format. It's only purpose is to turn a directory tree into a single file/stream of bytes, that can later be decoded back into a directory tree. It is not a compression algorithm.

You can actually sometimes see bzip2 or gzip being used without tar to compress a single file.

raju.mopidevi 12-24-2009 08:45 AM

Quote:

Originally Posted by anishakaul (Post 3803479)
Hi,

Both worked properly without -j or -z options !

It doesn't matter that whether you place option to compress/uncompress using specified options.

The magic lies in the name of the file.

Tar automatically selects the compression format as gunzip or bunzip using the file name.



that is if you want to compress some files
Code:

$tar -cvf myfiles.tar.bz *.jpg
Here I didn't specified bunzip option ( i.e. tar -cjvf ....) but output was compressed with bunzip format.

similarly for gunzip
Code:

$tar -cvf myfiles.tar.gz *.jpg
compressed using gunzip format,eventhough I didn't specified gunzip option ( i.e. tar -czvf ...)


This hold for extracting also.

gnashley 12-24-2009 09:39 AM

Since a few versions ago(1.16/1.18 ?), tar autodetects the compression type according to the filename.

knudfl 12-24-2009 09:40 AM

The ' tar ' flags changed five years ago ...

From /usr/doc/tar-1.15.1/NEWS , slack 10.2
Quote:

version 1.15 - Sergey Poznyakoff, 2004-12-20

* Compressed archives are recognised automatically, it is no longer
necessary to specify -Z, -z, or -j options to read them. Thus, you can
now run `tar tf archive.tar.gz'.
So now you can just do : 'tar xvf <archive>' with tar.gz an tar.bz2 .

No more jxvf or zxvf is required . !
.....

gnashley 12-24-2009 11:15 AM

I backported that functionality to tar-1.13 for use with pkgtools -along with the switches for supporting bzip2, lzma and xz.

SaintDanBert 12-24-2009 01:01 PM

Quote:

Originally Posted by gnashley (Post 3803587)
...
src2pkg
...

I looked at your src2pkg links. It seems pretty interesting.
Sadly, I'm an *-buntu guy and not slackware. I might fetch your sources and see how much hackery is needed to create a DEB file ... no where is that box of round tuits?

Cheers,
~~~ *<;-}( )( )//

MTK358 12-24-2009 03:03 PM

Funny that this gz/bz2 auto-detecting functionality doesn't seem to be mentioned in my man page for tar, even though my version of tar does have the functionality.

Aquarius_Girl 12-24-2009 10:32 PM

Thanks to all of u for throwing light on the subject !

Quote:

Originally Posted by knudfl
The ' tar ' flags changed five years ago ...

From /usr/doc/tar-1.15.1/NEWS , slack 10.2
Quote:
version 1.15 - Sergey Poznyakoff, 2004-12-20

* Compressed archives are recognised automatically, it is no longer
necessary to specify -Z, -z, or -j options to read them. Thus, you can
now run `tar tf archive.tar.gz'.
So now you can just do : 'tar xvf <archive>' with tar.gz an tar.bz2 .

No more jxvf or zxvf is required . !
.....

I tried to uncompress the bz2 and gz files without -j, -z options on openSuse 10.3, It didn't work, openSuse 10.3 was not released 5 years back but much later, it is surprising why tar doesn't work without these options on it !!

gnashley 12-25-2009 02:50 AM

MTK358, tar is a GNU program so it is documented with an info page. Any man-page you have for tar is leftover from 10 years ago, or added by your distro. That reminds me to check and make sure mine has been updated with the last changes I made.

SaintDanBert, just since the latest version released last week, src2pkg does support creating debs, rpms and other formats and is available as an installable package in all these format also.

You can get the debian package here:
http://distro.ibiblio.org/pub/linux/...2.0-16_all.deb

I'd be very glad to hear any feedback from you as it hasn't been tried on most other systems yet. Please email me directly if you have any problems, suggestions or comments: amigo AT ibiblio.org
Gilbert

knudfl 12-25-2009 08:41 AM

Post # 9
Quote:

I tried to uncompress the bz2 and gz files without -j, -z options on openSuse 10.3,
It didn't work, openSuse 10.3 was not released 5 years back but much later,
it is surprising why tar doesn't work without these options on it !!
Suse 10.3 has tar-1.17 , no 'j' or 'z' flag needed, unless you changed 'tar'.
Code:

knudfl@linux:~/tmp/2test-tar> tar xvf test-tar+bz2-1.17.tar.bz2
1
2
3
knudfl@linux:~/tmp/2test-tar> tar xvf test-tar+gz-1.17.tar.gz
1
2
3

This test was made on Suse 10.3, I also used it yesterday : tar xvf !
.....

MTK358 12-25-2009 11:44 AM

Quote:

Originally Posted by gnashley (Post 3804169)
MTK358, tar is a GNU program so it is documented with an info page. Any man-page you have for tar is leftover from 10 years ago, or added by your distro.

What? GNU does not have man pages?

Isn't it easier to type "man tar" than navigate all those menus?

Worst of all, I never, ever saw a Linux tutorial or instructions using info pages! I hardly ever heard of them! How was I supposed to know that info even exists?

gnashley 12-25-2009 01:58 PM

'man info'?? No, sorry, it's true. Official GNU programs frown on having man-pages since they have the 'wonderful' in-house tool called 'texinfo'. Don't get me wrong -I am no proponent of it -hate it in fact. And after 10 years using Linux, I... well I still have not been able to figure out how to use info to get any info! The trouble is that some programs have no man-pages at all, so you are stuck with on-line help or convertors. I am building a new system from scratch, and what I am gonna do is use one of the usable replacements, like pinfo or some info2html solution.

MTK358 12-25-2009 03:28 PM

Why did they invent info when there already was man?

And still, I've NEVER heard of info before, except just once on some obscure web page I happened to get on accidentally. How is the average user even supposed to know about it?

SaintDanBert 12-25-2009 09:28 PM

Quote:

Originally Posted by gnashley (Post 3804566)
'man info'?? No, sorry, it's true.
...

Years ago ... yes, we had computers back then ... I got a pretty bound, dead tree edition of the "AT&T Unix ..." documentation. I started reading and very little made sense. While shuffling pages I stumbled across text that explained
  • the books were printed copies of the official man pages
  • the pages were in alpha order within each section 'man (1)..." then 'man (2) ..." etc.

At that point I noticed that I was reading in the 'G' part of this book for an item titled "Getting Started."

Sometimes you just gotta know ... [lol]
~~~ 0;-Dan


All times are GMT -5. The time now is 05:39 AM.