FactorPad
Faster Learning Tutorials

Linux gzip command summary with examples

gzip allows you to compress and decompress files.
  1. Purpose - Learn what gzip is for an how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with gzip.
  4. A tip - Finish off with one more insight.
Paul Alan Davis, CFA, November 5, 2016
Updated: July 24, 2018
In this tutorial, 68 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Next

~/ home  / tech  / linux essentials  / gzip command


The Linux gzip command

Beginner

Learn to compress and decompress files at the Linux command line.

Video Tutorial

Linux gzip command summary with examples (4:01)

Videos can also be accessed from the YouTube Playlist.

Video Script

The Command and Why You Need It

Our sixty-eighth word, or command to memorize is gzip from our category Files.

gzip allows you to compress and decompress files.

Recall from the last four videos on software packages and most are compressed, so now we'll focus our attention on file compression.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The gzip command has 18 options and the argument is the file or list to compress. Several data compression algorithms exist, so it may get confusing. And then also note that related commands include gunzip and zcat.

Like most commands, help is available with double-dash --help. The -d option decompresses files and -v shows percent reduction.

So why is gzip an important command? Well, bandwidth and resources are limited, so getting to know how compression works is vital. And now you know how to do that.

Demonstration

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. Start with a man command with a --where to search for the location of manual pages for the program gzip.

$ man --where gzip /usr/share/man/man1/gzip.1.gz

Notice how the file is given the extension .gz?

As it is with a program such as vim.

$ man --where vim /usr/share/man/man1/vim.1.gz

Or grep.

$ man --where grep /usr/share/man/man1/grep.1.gz

So it is standard for man pages to be compressed with gzip. And that's good to know.

Next, let's use that same command and create a file to compress.

$ man gzip > video68.txt

Okay, let's copy video68a.txt to video68b.txt.

$ cp video68a.txt video68b.txt

And there's a different way to do this of course, but I just wanted to go through this illustration. Then gzip -v video68b.txt.

$ gzip -v video68b.txt video68b.txt: 64.5% -- replaced with video68b.txt.gz

And then do an ls -og on video68*.

$ ls -og video68* -rw-r--r-- 1 17742 Nov 5 14:04 video68a.txt -rw-r--r-- 1 6322 Nov 5 14:04 video68b.txt.gz

And then, notice how the size changed here, so notice the difference and it replaced the old file with the new.

And last, let's decompress with -d and that ls -og video68* again.

$ gzip -d video68b.txt.gz $ ls -og video68* -rw-r--r-- 1 17742 Nov 5 14:04 video68a.txt -rw-r--r-- 1 17742 Nov 5 14:04 video68b.txt

So the takeaway here should be that, by default, gzip compresses files in place.

A Final Tip

Okay now you know how to use gzip. And you know the syntax for commands, options and arguments.

One last tip about the gzip command. So in the man page on gzip. Read through it, and it details additional functionality provided by gunzip and zcat.

Okay, thanks for visiting today. I hope this was a helpful introduction to the gzip command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

Here's a YouTube Channel subscription button. If you learned something today, please consider subscribing.

  • For the Outline of all 100 tutorials, click Outline.
  • To go back to the aptitude command, hit Back.
  • To see the next compression tool gunzip, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / gzip command



 
 
Keywords:
Linux gzip command
gzip Linux
tar gz
compress files
compress directories
decompress
compression algorithm
zcat command
compressed man pages
gz files
extract gz files
gzip a directory
unzip gz file
gzip example
file compression