/ factorpad.com / tech / linux-essentials / bzip2-command.html
An ad-free and cookie-free website.
Beginner
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
Files.
bzip2
allows you to compress and
decompress files.
-options | description |
---|---|
-h ,
--help |
Print help screen |
-k ,
--keep |
Keep input file |
-v ,
--verbose |
Report percent reduction in file size |
Recall from the two videos on gzip
and 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)
.
The 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
--help
. The
-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
them.
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
compression stats.
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?
On video70.txt.bz2
that we just created. And an
ls -og
and we should see two files.
Okay now you know how to use bzip2
.
And you know the syntax for commands, options and arguments.
One last tip about the bzip2
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 bzip2
command.
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.
gunzip
command,
hit Back.xz
, click Next./ factorpad.com / tech / linux-essentials / bzip2-command.html
A newly-updated free resource. Connect and refer a friend today.