This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes Extracting a bin file and a tar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Extracting a bin file and a tar file" Watch "Extracting a bin file and a tar file" New topic

Extracting a bin file and a tar file

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10033


What is the difference between extracting a bin file and a tar.gz file? For example when I downloaded java, I got them as binaries and I user a sh ./ to unpack the contents. When I downloaded Maven, it was of the tar.gz form and used a tar utility to unpack the contents. What exactly is the difference between these two formats?

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778

Jothi Shankar Kumar wrote:What exactly is the difference between these two formats?

(my highlighting)

Precise differences are unlikely to be forthcoming, as there is no precise definition for a "bin" format file (at least in the way that Sun are using it here - there are other "bin" files that have more precise definitions).

Non precise ...

The tar format (tape archive) just provides a way of storing one or more files and directories into a single archive file (or device). That is all it allows - it does not specify licensing terms or anything else that you might typically find in a distribution.

For something like Maven, this is fine. The license is contained as a file within the archive, and you can read it at your leisure anytime after installing it.

For the Java distribution provided by Sun, this is not the case. They want you to explicitly look at the license agreement and accept it before you can install it. In theory, some software being distributed might also need to have a special user or group installed on your computer, and/or install daemons.

To meet these needs, it makes sense to have a file that can work on any Linux system, regardless of what has already been installed. In the Microsoft world, this might be considered an executable file (*.exe or *.msi) that contains the distribution within itself.

So that really is all the bin file is - an archive (possibly a tar archive) that is contained within an executable that knows how to process it and potentially do other work as well.

As an example, consider the following file:

(You can run this without any problems on your computer - it doesn't actually do anything other than list the contents of a tar file that is contained within lines 5 - 7. If you want to try it, just copy all 8 lines into a file and name it something like "". Then run "sh ./" - you should see output showing you the contents of my file).

In this example, all my work is done in line 4:
  • cat << EOF simply concatenates all the lines between line 5 (the line following the cat command) and 7 (the line before the EOF on line 8) and sends the output to ...
  • base64 -d which converts the plain-text data in those 3 lines back into the binary tar format, and then sends that to ...
  • tar -tzvf - the tar command that tells us what is in the gzipped archive in verbose mode for the file it has just been passed (indicated by the -)

  • If that was all I was doing, I could have just provided you with the tar file directly. However I wanted you to press "Enter" first, and that is what lines 1 & 2 get you to do.

    Hopefully you can see from this simple example how this can be used to create a distribution that can easily be sent to a customer that can do more than just provide the raw distribution. In theory the archive contained in lines 5 - 7 could contain something that my script could have executed after extracting it.

    (If you really want to see what is in that archive, change the "tzvf" in line 4 to an "xzvf" (where the 'x' is for extract) and re-run it. This will create the "txt" file in the same directory where you run the script)

    The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
    Joe Harry
    Ranch Hand

    Joined: Sep 26, 2006
    Posts: 10033

    That was a very good explanattion. Thank you!
    I agree. Here's the link:
    subject: Extracting a bin file and a tar file
    It's not a secret anymore!