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 ways to handle
.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 is inside.
project/.tar archives files and directories into a single container. Compression is optional..tar.gz is tar + gzip. .tar.xz is tar + xz.ls project/
Confirm what you are packaging. This avoids shipping incomplete bundles or archiving the wrong path due to a typo or assumption.
README.md src/ assets/ data/
tar -cvf project.tar project/
-c creates the archive, -v prints what is added, and -f names the output file.
This produces a single tarball without compression.
project/
project/README.md
project/src/
project/assets/
project/data/
tar -tvf project.tar
Before compressing or shipping, confirm what is inside. Listing is a fast sanity check and a good habit for handoffs.
# Example output (truncated):
drwxr-xr-x vonds vonds 0 2026-02-08 10:00 project/
-rw-r--r-- vonds vonds 0 2026-02-08 10:00 project/README.md
gzip project.tar
gzip compresses the tar file and replaces it with project.tar.gz by default.
ls -lh project.tar.gz
tar -xvzf project.tar.gz
-x extracts, -z enables gzip handling, -v prints extracted paths, and -f selects the archive.
project/
project/README.md
project/src/
project/assets/
project/data/
tar -cJvf project.tar.xz project/
This is the most direct workflow: tar creates the archive and handles xz compression in one step.
-J tells tar to use xz.
ls -lh project.tar.xz
.tar.xz directly.
tar -xvJf project.tar.xz
Direct extraction is ideal when you receive a .tar.xz bundle and just need to unpack it immediately.
project/
project/README.md
project/src/
project/assets/
project/data/
# If you already have project.tar:
xz project.tar
# Restore the tar later:
unxz project.tar.xz
# OR
xz -d project.tar.xz
This workflow shows up in real environments when a tar already exists and you need to compress it after the fact.
Always run ls first and consider using absolute paths if you are in a busy working directory.
Use -C <dir> when extracting to control where files land, for example:
tar -xvzf project.tar.gz -C /tmp.
On minimal systems, xz support may be missing. Install xz tooling or decompress first with unxz, then extract the tar.
Remove archives and any extracted test directories if you are working in a shared or constrained environment.
rm -f project.tar project.tar.gz project.tar.xz
# Remove extracted test directory if needed:
rm -rf project/
tar -cvf <archive.tar> <dir>: Creates an uncompressed tar archive.
-c: Create archive.-v: Verbose output.-f: Archive filename.tar -tvf <archive.tar>: Lists contents of a tar archive.
gzip <file>: Compresses a file with gzip and replaces it with .gz.
tar -xvzf <archive.tar.gz>: Extracts a gzip-compressed tar archive.
-x: Extract.-z: Use gzip.tar -cJvf <archive.tar.xz> <dir>: Creates an xz-compressed tar archive.
-J: Use xz.tar -xvJf <archive.tar.xz>: Extracts an xz-compressed tar archive directly.
xz <file>: Compresses a file with xz and replaces it with .xz.
unxz <file.xz> / xz -d <file.xz>: Decompresses an xz-compressed file.