Linux Basics 08 — Archives, Compression, and a Restore Test

Linux course index · Linux Basics category · Lesson 8 of 8

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Create and inspect an archive, then prove that you can recover a file from it.

Concepts and setup

An archive groups files and their metadata. Compression reduces size, along with the ability to inspect or restore only as supported by the format. tar -z uses gzip and tar -t lists members without extracting them. 7-Zip is another archive tool discussed on the site. This exercise adapts the site’s timed tar and selective restore script to your own lab data rather than copying real system configuration.

Archive a lab folder and restore one file

lab=$(mktemp -d)
cd "$lab" || exit
mkdir -p project restore
printf 'service=demo\n' > project/settings.txt
printf 'release notes\n' > project/notes.txt
tar -czf project.tgz -C project settings.txt notes.txt
tar -tzf project.tgz
tar -xzf project.tgz -C restore settings.txt
cmp project/settings.txt restore/settings.txt &&
  printf 'restore matches the original\n'

Possible output

settings.txt
notes.txt
restore matches the original

-C changes directory for the tar operation, and the member names do not include project/. Do not extract an untrusted archive over existing files. Inspect its member names and use an isolated destination.

Record an integrity check

sha256sum project.tgz > project.tgz.sha256
sha256sum -c project.tgz.sha256
ls -1 restore

Possible output

project.tgz: OK
settings.txt

An integrity checksum tells you whether this artifact matches a known digest. It does not authenticate an archive if an attacker can also replace the checksum file.

Questions only

Quick-check questions

  1. Which command lists the gzip archive without extracting?
  2. Did this restore extract notes.txt?

Assessment questions

  1. Change the extraction command to restore both members into a fresh directory.
  2. Explain why keeping only an archive on the same laptop is not enough for disaster recovery.
  3. Name a stronger acceptance test than archive creation returned 0.

Questions and answers

Quick-check answers

  1. Which command lists the gzip archive without extracting?
    Answer — tar -tzf project.tgz.
  2. Did this restore extract notes.txt?
    Answer — No. settings.txt was the only requested member.

Assessment answer key

  1. Change the extraction command to restore both members into a fresh directory.
    Answer — Run mkdir restore-all followed by tar -xzf project.tgz -C restore-all.
  2. Explain why keeping only an archive on the same laptop is not enough for disaster recovery.
    Answer — One failure or loss can take out both the original and archive. Keep a separate protected copy.
  3. Name a stronger acceptance test than archive creation returned 0.
    Answer — Restore selected content into a clean location and compare it to the expected data.

Source articles on this site

Continue the course

Previous lesson 07 — Processes, Jobs, and Signals. This is the last lesson in this level. See the course index for the next level.

Linux course index · Linux Basics category · Lesson 8 of 8

Leave a Reply