Package a project directory into portable archives and compare
gzip vs xz compression workflows using tar. Validate results by
listing and extracting archives, then confirm multiple correct
methods for handling .tar.gz and .tar.xz.
You need to archive a project directory and ship it to another
system for review. You will create an uncompressed tar archive,
compress it with gzip, extract it, then repeat the process with xz
and verify that you can extract .tar.xz directly.
Archiving and compression show up everywhere: backups, incident bundles, offline transfers, and collecting evidence for escalation. The goal is doing it correctly and being able to prove what’s inside.
project/.
.xz-compressed tar directly using tar’s xz flag.
ls before archiving.
tar -c and -f.
gzip and extraction with tar -z.
xz and decompression using unxz / xz -d.
.tar.xz using tar -J.
ls project/
Confirm what you’re packaging. This avoids shipping incomplete bundles or archiving the wrong directory due to a typo or assumption.
README.md src/ assets/ data/
tar -cvf project.tar project/
tar creates a single archive container without compression.
-c creates the archive,
-v shows what is added,
and -f names the output file.
project/
project/README.md
project/src/
project/assets/
project/data/
gzip project.tar
gzip compresses the tar file and replaces it with
project.tar.gz
by default. This is one of the most common archival formats for transfers.
ls -l project.tar.gz
# Confirm the file exists and has a non-zero size.
tar -xvzf project.tar.gz
-x extracts,
-z tells tar to use gzip,
-v prints extracted paths,
and -f specifies the archive file.
project/
project/README.md
project/src/
project/assets/
project/data/
tar -cvf project.tar project/
Rebuilding the tar file gives you a clean baseline for testing xz compression next. In real workflows, you might produce both formats depending on your transfer constraints.
project/
project/README.md
project/src/
project/assets/
project/data/
xz project.tar
# Optional (multithread):
xz -T0 project.tar
xz typically compresses smaller than gzip, but may take longer.
By default, it replaces project.tar with
project.tar.xz.
ls -l project.tar.xz
# Confirm the file exists and has a non-zero size.
unxz project.tar.xz
# OR
xz -d project.tar.xz
This restores project.tar from the xz-compressed file.
Knowing both variants helps when one tool is missing or when you are
working on constrained environments.
ls -l project.tar
# Confirm project.tar exists again.
tar -xvJf project.tar.xz
-J
tells tar to use xz. This is the cleanest workflow when you receive
a .tar.xz bundle and just need to extract it immediately.
project/
project/README.md
project/src/
project/assets/
project/data/
tar -cvf <archive.tar> <dir>
: Creates an uncompressed tar archive.
-c
: Create archive.
-v
: Verbose output (lists files as they are added/extracted).
-f
: Output archive filename.
gzip <file>
: Compresses a file using gzip and typically replaces it with
.gz
.
tar -xvzf <archive.tar.gz>
: Extracts a gzip-compressed tar archive.
-x
: Extract archive.
-z
: Use gzip compression/decompression.
xz <file>
: Compresses a file using xz and typically replaces it with
.xz
.
unxz <file.xz>
: Decompresses an xz-compressed file (same as
xz -d
).
tar -xvJf <archive.tar.xz>
: Extracts an xz-compressed tar archive directly.
-J
: Use xz compression/decompression.