Package files and prove you can restore them
By the end: Distinguish compression from archiving and verify a small restore.
The idea
Compression reduces a stream's size; an archive collects files and paths. Keep originals during practice and list an unfamiliar archive before extracting it into a new directory. A backup is useful only when you can restore it and compare the result.
Your command toolkit
gzip
What it solves: Compress a file while preserving its original.
gzip -c notes.txt > notes.txt.gz
-c writes compressed bytes to standard output. Without -c or -k, gzip normally replaces the original with its compressed form.
gunzip
What it solves: Read a gzip stream as plain text.
gunzip -c notes.txt.gz
-c decompresses to the terminal and retains the archive. Redirect to a new path if you want a separate restored file.
zcat
What it solves: Inspect gzip content without an extraction step.
zcat notes.txt.gz
Streams decompressed content. It is convenient for piping a compressed log into grep or head.
bzip2
What it solves: Try another lossless compression format.
bzip2 -c notes.txt > notes.txt.bz2
The .bz2 format differs from gzip. -c retains the source; use bunzip2 or bzip2 -d to decode it.
tar
What it solves: Bundle paths into an archive.
tar -czf notes.tar.gz notes.txt
tar -tzf notes.tar.gz
-c creates, -t lists, -z uses gzip, and -f names the archive. List and review member paths before extraction.
zip
What it solves: Create a widely supported archive.
zip notes.zip notes.txt
zip can package and compress together. A .zip suffix alone does not prove the contents are safe or authentic.
unzip
What it solves: Inspect a ZIP archive before extraction.
unzip -l notes.zip
-l lists entries. Extract into a dedicated empty folder only after checking the archive source and paths.
split
What it solves: Break a stream into manageable chunks.
split -l 2 notes.txt part-
Creates sequential files containing up to two lines each. Keep their order when reassembling; chunking is not encryption.
cpio
What it solves: Understand an archive driven by a file list.
printf '%s\n' notes.txt | cpio -o > notes.cpio
cpio's copy-out mode reads pathnames from input. This example deliberately archives one known practice file.
Before you move on
Try the guided lab below. Compare the result with the explanation, then record your reasoning in the workbook. A missing optional program or a restricted environment is something to explain, not a reason to change system settings blindly.
Practice with evidence
- Predict the result
- Run the guided lab
- Compare the output
- Explain your choice
A worked example
Guided lab
si_lab=$(mktemp -d)
cd "$si_lab" || exit
printf 'Plan\nBuild\nVerify\n' > notes.txt
tar -czf notes.tar.gz notes.txt
tar -tzf notes.tar.gz
mkdir restored
tar -xzf notes.tar.gz -C restored
cmp notes.txt restored/notes.txt
printf 'Comparison status: %s\n' "$?"
What to expect: The archive contains notes.txt. The restored file matches byte for byte and the comparison status is 0.
Make it yours: Describe your archive, extraction destination, and comparison result. Explain why listing an archive is different from verifying a restore.
Read further
- GNU Coreutils manual ↗www.gnu.org
Apply what you learned
Your private practice
Answers are private. Completion requires the correct knowledge-check answer and a written response when an activity is included.
Restore a downloaded workbook
Choose a recovery file for this course and version. Review the recovered copy before saving it to your account.
Ask a question or report a problem
Describe what needs attention. Your private answer is shared only if you select the option below.