$
Learn Linux handbook
en
XP:0
Quest 122Packer
+280 XP

Archives & Compression (tar)

Launch Interactive Terminal for This Quest→No installation required • Runs fully in browser

Concept & Overview

Imagine you have a folder containing 500 server logs, and you want to email it to a colleague or back it up to cloud storage. Sending 500 individual files is slow and inefficient. In Linux, we compress them into a single, compact zip-like file using tar (short for "tape archive").

- We create compressed archives using flags: -c (create), -z (compress with gzip), -v (verbose listing of files), and -f (specify filename). E.g., tar -czvf backup.tar.gz folder/ bundles and zips the directory.

Why this matters: If you run tar -cz logs.tar.gz logs without -f, you will get: tar: Refusing to write archive contents to terminal. The -f flag is critical because it tells tar to write the output to a file instead of sending raw binary archive data directly to your terminal. The -c and -z flags are also required to create and compress the archive respectively.

Let's package our logs. Bundle and compress the logs folder inside /home/learner into a file named logs.tar.gz by running tar -czvf logs.tar.gz logs.

Command Syntax Reference

Command / SyntaxDescription
tar -czvf archive.tar.gz folderCreate compressed tar archive

Verification Objectives

These conditions will be automatically verified when you run commands inside the interactive terminal simulator:

  • ○
    Use "tar" command with -c (create) and -z (gzip) flags
  • ○
    Create "logs.tar.gz" in home directory

Ready to complete Quest 122?

Test your skills live in the browser terminal with an emulated Linux filesystem, real-time command evaluation, and instant step-by-step hints.