In today’s article, we’re going to discuss how to compress and decompress .bz2 files. This is something you may eventually need to know, so I’ll cover it here. I’ll just cover the basics, as most folks won’t need to know anything more than the basics. This should actually be a fairly short and direct article. There’s not a whole lot to it.
If you don’t already know, .bz2 files are bzip2 files. You’ll find that bzip2 is an opensource compression program that gets some regular usage, and you’ll sometimes find downloaded files that are compressed with this format. You may also, for compatibility reasons, want to compress files with bzip2 to share with other users who are already set on using the .bz2 format.
For the curious, the bzip2 man pages define this particular application as (and, as always, I highly encourage folks to read the man pages themselves – this one being a bit more complicated than others):
bzip2, bunzip2 – a block-sorting file compressor
Again, we’re going to just cover how to compress and decompress .bz2 files in this article. That’s all we’re going to do. You don’t tend to come across too many files compressed with bzip2, but they do show up from time to time.
Because of that, we’re going to cover how to compress and decompress those files in this article. It’s gotta get covered eventually, so it might as well be now. Read on!
Compress And Decompress .bz2 Files:
This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.
You might actually not have bzip2 installed. It’s not always installed by default. Fortunately, as far as I can tell, it shares the same name in every major distro, that is ‘bzip2‘. So, just go ahead and install it like you’d install any other software. For example, if you’re using Fedora, your command would look similar to:
See? I didn’t use Ubuntu as the default example! We’re mixing everything up today! (Use apt if you’re using a distro with apt, like Debian or Ubuntu and derivatives.)
At this point, you should probably have a .bz2 file to work on for the sake of the article. Seeing as I have no idea what you’ve already downloaded, we should probably start with you making one – just so you can see how to decompress it.
To compress a file with bzip2, the command looks like (See the detailed warning below this command, do not use this command without reading the warning!):
That will create a file with the same filename but make a .bz2 file. However, this is a destructive act. If you use the above command, the original file will be deleted! If you wish to keep the original file, you need the
-k (keep) flag. That looks like:
That command will not remove the original file, as would be the default. Obviously, the
-z flag means ‘zip’.
If you want to decompress a file with bzip2, the command looks like:
This will extract the file(s) into the current directory. Of course, the
-d means ‘decompress’. This is not a destructive operation. The original and extracted files will remain on your file system.
As you can see, it’s not all that difficult to compress and decompress .bz2 files. You might go years not seeing any files in that format, but you’re eventually going to bump into one and now you know how to deal with it in the terminal – and how to respond in kind.
And there you have it. You have yet another article. We’re getting close to 300 articles at this point, so it has been a long journey. If you feel like writing an article, let me know! Anyhow, you can now compress and decompress .bz2 files easily enough, and that was the point of the article.