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!
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:
sudo dnf install bzip2
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!):
bzip2 -z <file_name>
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:
bzip2 -zk <file_name>
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:
bzip2 -d <file_name>.bz2
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.
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.
Today we'll cover one way to enable or disable your network interface in the Linux…
Today's exercise is a nice and simple exercise where we check your NIC speed in…
Have you ever wanted to easily monitor your wireless connection? Well, now you can learn…
I think I've covered this before with the ls command but this time we'll count…
Today we'll be learning about a basic Linux command that's known as 'uname' and it…
If you've used hardinfo in the past, it may interest you to know that hardinfo…