Create & Extract bz2 Archives in Mac OS X

May 29, 2012 - 10 Comments

bzip2 archive in Mac OS X

The Bzip archive format is generally more effective at compressing than zip and gzip, and while the default Archive Utility or the excellent all-purpose Unarchiver tool will handle unarchiving bzip2 files with ease, you will have to venture to the command line if you want to create a bzip archive in Mac OS X.

Creating a BZ2 Archive:
bzip2 -z filetocompress

The output of this command is the compressed file, it does not create a compressed copy of the file. To clarify with the example above, you’d see a file named “filetocompress.bz2” within the working directory and the original “filetocompress” would be missing.

Remember that bzip2 does not bundle files, it just compresses them. If you want to add a group of files to a bzip archive you’d want to use tar beforehand. Some versions of tar even support creating bz2 archives natively with the -j flag, but that doesn’t appear to be implemented in Mac OS X.

Of course you can also decompress bz2 archives from the command line with either the bzip2 or bunzip2 commands:

bzip2 -d file.bz2

Or bunzip2:

bunzip2 archivefile.bz2

Or just double-click the bz2 file in the Finder.

.

Related articles:

Posted by: William Pearson in Command Line, Mac OS, Tips & Tricks

10 Comments

» Comments RSS Feed

  1. Koemsie Ly says:

    Thanks you for your nice tips!

  2. Joshwah says:

    my understanding in the above was tar doesn’t really compress, it just bundles individual files together?

    • Dan in NH says:

      tar -cvf files.tar * Creates uncompressed archive
      tar -cvzf files.tar.z * Creates compressed archive
      tar -cvjf files.tar.bz2 Creates bz2 compressed archive

    • Dan in NH says:

      You already compressed the file with the first command. It may actually make the file bigger with the second command.

    • Dan in NH says:

      Original tar on xenix and unix didn’t compress so you had to compress it first and then you would tar it. But under Linux and MAC OS X they use gtar even though it may be called tar. If gtar doesn’t come with the UNIX the administrator has probably downloaded gnutools and compiled and installed them on their system so they can get the functinality of compressing the files during the tar process as well as all the other neat gnu utilities.

      tar -cvf files.tar * Creates uncompressed archive
      tar -cvzf files.tar.z * Creates compressed archive
      tar -cvjf files.tar.bz2 Creates bz2 compressed archive

  3. someguy says:

    I apple’s typical idiotic style /usr/bin/tar is not GNU tar. I recommend creating an alias in your bashrc so that when you type tar it calls /usr/bin/gnutar. This will fix many problems.

  4. Joshwah says:

    i have never tried this and thought i would give it a shot.. i can get the end result, but there is zero compression happening, am i doning something wrong??

    tar -cvzf CPT.tar.gz CPT
    bzip2 -z CPT.tar.gz

    Cheers

    • Amigalander says:

      What kind of file is CPT? You probably won’t get any compression from zip or bzip if the file is already compressed, for example, a jpeg file. Try it on a text file.

      Both Apple tar and gnutar have zip type compression options built in.

  5. Greg says:

    Could you share a link to the wallpaper with the ocean and lightning? Thanks in advance!

  6. constantine says:

    tar -cfjv should do it

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site