An ad-free and cookie-free website.
Learn to compress and decompress files at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux bzip2 Command Summary with Examples (4:13)
Our seventieth word, or command to memorize is
bzip2 from our category
bzip2 allows you to compress and
|Print help screen
|Keep input file
|Report percent reduction in file size
Recall from the two videos on
gunzip we saw a first compression
algorithm. Now we'll evaluate another, promising better results.
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s).
bzip2 command has
14 options and the argument is the file or list to
compress, and note, filename extensions here are .bz
or more commonly .bz2.
Like most commands, help is available with double-dash
-k option keeps the input file and
-v shows file compression details.
So why is
bzip2 an important command?
Well, at times you're given compressed files with .bz
or .bz2 extensions and you need to know how to handle
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go. As in the last video, we created a file from the
man command on
gunzip and wrote it to a file called
video69a.txt, copied it to
video69b.txt and then gzipped it.
So let's see the compression stats on the file using
gunzip -l video69b.txt.gz.
And then we notice that it compressed it at 64%, so that's our bogey and what we're trying to beat.
Next, let's use that same starting file, so
video69b.txt, and copy it to
video70.txt. And then zip it using
bzip2 -v to see the contents and
See, we have it at 67%, so a little bit better.
And then an
ls -og video70* just to
see what's out there.
And notice we only have that new file (meaning it replaces the input file with the new).
And last, let's decompress using
bunzip2 -k to keep the file, right?
that we just created. And an
ls -og and we should see two files.
Okay now you know how to use
And you know the syntax for commands, options and arguments.
One last tip about the
command. So just as with the
gzip/gunzip combo, the
bzip2 manual page is shared between
the compression and decompression commands, so check that out.
Okay, thanks for visiting today. I hope this was a helpful
introduction to the
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
Our group is democratizing knowledge and data so everyone has the power to make better financial decisions. Subscribe, follow and contribute to be a part of it.
xz, click Next.
A newly-updated free resource. Connect and refer a friend today.