0Pricing
DevOps Bootcamp · Lesson

Archiving and Compression (tar, gzip, unzip)

Learn how to create, extract, and compress archives using standard Linux tools like 'tar', 'gzip', and 'unzip'.

Archiving and Compression (tar, gzip, unzip) is a free DevOps Bootcamp lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Archive & Compress?

When working with many files or large files, archiving and compression become super useful!

  • Archiving groups multiple files into a single file, making them easier to manage, move, or backup.
  • Compression reduces the size of a file or archive, saving disk space and speeding up transfers over networks.

These tools are essential for efficient file management in Linux.

Introducing 'tar' for Archiving

The tar command (short for Tape ARchiver) is the standard Linux tool for grouping files and directories into a single archive file.

It doesn't compress files by default, but it's the first step before compression. Think of it as putting many items into one box.

Creating a 'tar' Archive

To create a .tar archive, we use the -c (create), -v (verbose, shows progress), and -f (filename) options.

Let's create an archive called my_files.tar containing file1.txt and file2.txt.

echo "Content for file1" > file1.txt
echo "Content for file2" > file2.txt

tar -cvf my_files.tar file1.txt file2.txt

ls -l

Extracting from a 'tar' Archive

Once you have a .tar archive, you'll often need to extract its contents. We use the -x (extract) option, along with -v and -f.

Let's remove the original files and then extract them from our my_files.tar archive.

rm file1.txt file2.txt

tar -xvf my_files.tar

ls -l

Listing 'tar' Archive Contents

Sometimes you just want to see what's inside an archive without extracting everything. The -t (list) option is perfect for this.

It shows you the names of the files and directories stored within the .tar file.

tar -tvf my_files.tar

Introducing 'gzip' for Compression

gzip is a popular Linux utility for compressing single files. It typically replaces the original file with a .gz compressed version.

A compressed file takes up less disk space and is faster to transfer.

Compressing with 'gzip'

To compress a file, simply run gzip followed by the filename. The original file will be replaced by its compressed .gz version.

Let's compress our my_files.tar archive.

gzip my_files.tar

ls -l

Decompressing with 'gunzip'

To decompress a .gz file and restore the original, use the gunzip command. It works just like gzip but in reverse.

Let's decompress my_files.tar.gz back to my_files.tar.

gunzip my_files.tar.gz

ls -l

Combining 'tar' and 'gzip'

It's very common to archive and compress in one step. tar has a built-in option, -z, to use gzip for compression.

This creates a .tar.gz (or .tgz) file, which is a tar archive compressed with gzip. This is often the most efficient way to package files.

echo "Another file" > another.txt

tar -czvf my_combined.tar.gz file1.txt file2.txt another.txt

ls -l

Quick Check: Extracting Combined Archives

You have a file named project_docs.tar.gz. Which command would correctly extract its contents?

Recap: Archiving & Compression

Great job! You've learned how to handle archives and compressed files in Linux:

  • tar: Used to create (-c), extract (-x), and list (-t) archive files (.tar).
  • gzip: Compresses single files into .gz format.
  • gunzip: Decompresses .gz files.
  • The -z option with tar allows you to create or extract .tar.gz (or .tgz) archives, combining archiving and gzip compression.

These commands are fundamental for managing files efficiently on any Linux system!

Frequently asked questions

Is the “Archiving and Compression (tar, gzip, unzip)” lesson free?

Yes — the full text of “Archiving and Compression (tar, gzip, unzip)” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Archiving and Compression (tar, gzip, unzip)”?

Learn how to create, extract, and compress archives using standard Linux tools like 'tar', 'gzip', and 'unzip'. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Archiving and Compression (tar, gzip, unzip)” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Advanced Text Manipulation (sed, awk)
  2. Archiving and Compression (tar, gzip, unzip)
  3. Disk Usage & System Info (df, du, uname)
  4. Sorting & Deduplicating Data (sort, uniq, cut)
← Back to DevOps Bootcamp