Thuta Learning
ProjectsDevOps & Toolsbeginner

Archiving & Compression: tar, gzip, zip

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand Archiving & Compression: tar, gzip, zip without any of the intimidation
  • Get comfortable trying these commands yourself in the terminal
  • See how these commands are actually useful on a real server/project

Let's think about it this way for a second

tar (tape archive) bundles multiple folders/files together into a single archive file — on its own it just 'bundles' without compressing, which is why it's usually paired with gzip, and that's why you see the .tar.gz extension (a tarball) so often. tar -czvf archive.tar.gz folder/ combines the flags c (create), z (gzip compression), v (verbose, lists the files), and f (specify a filename) — you can remember it with the mnemonic 'create zipped verbose file.' To extract (unpack), run tar -xzvf archive.tar.gz (x = extract). zip/unzip is the go-to when you need compatibility with Windows users (the .zip format).

Let's connect it to a real scenario

When taking a server backup, it's common to package an entire folder with tar -czvf backup-2026-08-23.tar.gz /var/www/mysite and then pull it down to your local machine with scp — instead of transferring a thousand files one by one, you just transfer a single archive, which is much faster. If you want to send website files to a client, zip -r website.zip website/ is handy since Windows users can just double-click to open it.

Let's try it together in the terminal

bash
tar -czvf backup.tar.gz project/
tar -xzvf backup.tar.gz
zip -r website.zip website/
unzip website.zip
You should see
After tar -czvf, a file called backup.tar.gz shows up in the folder, and you can check its size with ls -lh.

5-minute try-it

Try archiving a practice folder with tar -czvf practice.tar.gz practice/. Use ls -lh to compare the archive's size against the original folder.

One thing to watch out for

Running tar -xzvf inside a directory that has important files in it can overwrite existing files with the ones in the archive — it's much safer to move into a fresh, empty folder before extracting.

Easy traps

  • Mixing up the tar flag order and getting an error (most modern tar implementations are flexible, but you should still keep -f right next to the filename)
  • Extracting an archive without checking with pwd where it'll actually land — this can make a mess of your folders

Now try it yourself

Try archiving a practice folder with tar -czvf practice.tar.gz practice/. Use ls -lh to compare the archive's size against the original folder.

You'll know it worked when: After tar -czvf, a file called backup.tar.gz shows up in the folder, and you can check its size with ls -lh.

Archiving & Compression: tar, gzip, zip | Thuta Learning