Create & Extract bz2 Archives 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.
Thanks you for your nice tips!
my understanding in the above was tar doesn’t really compress, it just bundles individual files together?
tar -cvf files.tar * Creates uncompressed archive
tar -cvzf files.tar.z * Creates compressed archive
tar -cvjf files.tar.bz2 Creates bz2 compressed archive
You already compressed the file with the first command. It may actually make the file bigger with the second command.
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
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.
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
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.
Could you share a link to the wallpaper with the ocean and lightning? Thanks in advance!
tar -cfjv should do it