You have files to back up or a tarball to extract
You downloaded a source package from GitHub and it ended in .tar.xz. You double-clicked it and nothing happened. Or you tried to back up your configuration directory and ended up with a file that contains only an empty folder. Archiving on Fedora feels like memorizing a spell book of single-letter flags until you understand the pattern. Once you see the pattern, tar stops being a mystery and becomes the most reliable tool in your belt.
How tar and compression work together
tar stands for tape archive. Its only job is to bundle multiple files into a single stream. It does not compress data by default. Think of tar as a cardboard box. You can put a stack of papers in a box, but the box doesn't make the papers smaller. Compression tools like gzip and xz are the vacuum sealers. You pipe the tar stream through a compressor to reduce the size.
The extension tells you what happened. .tar.gz means a tar archive compressed with gzip. .tar.xz means a tar archive compressed with xz. zip is a different format entirely that bundles and compresses in one step. This makes zip easier to share with Windows users but harder to manipulate from the command line.
Run tar -tf before you extract. Knowing what's inside prevents accidental overwrites.
Creating and extracting archives
Here's how to create a compressed tarball and extract it. The flags are mnemonic if you know the mapping: c for create, x for extract, z for gzip, J for xz, v for verbose, and f for filename.
# Create a tarball with gzip compression
# c: create archive
# z: filter through gzip
# v: verbose output (optional, helps you see progress)
# f: filename follows (must be last flag)
tar -czvf backup.tar.gz /home/user/docs
Extraction uses the same flags but swaps create for extract. The order of c, z, v does not matter, but f must be last because everything after f is treated as the filename.
# Extract a gzip-compressed tarball
# x: extract files
# z: decompress with gzip
# v: verbose output
# f: filename follows
tar -xzvf backup.tar.gz
Always put the filename last. The f flag eats everything that follows it.
Here's how to use xz compression. xz offers better compression ratios than gzip but takes longer to run. Use this for large archives where storage space matters more than speed.
# Create a tarball with xz compression
# J: filter through xz (capital J)
tar -cJvf large-data.tar.xz /var/log
Zip requires installing packages. It is useful for cross-platform sharing because Windows and macOS handle zip files natively.
# Install zip and unzip if missing
sudo dnf install zip unzip
# Create a zip archive recursively
# r: recurse into directories
zip -r project.zip /path/to/project
# Extract the zip archive
unzip project.zip
Use zip for cross-platform sharing. Linux tools prefer tar, but Windows users expect zip.
Advanced operations: excludes, permissions, and targets
You often need to peek inside an archive or extract files to a specific location without changing your current directory. The t flag lists contents. The C flag changes the target directory for extraction.
# List contents without extracting
# t: list files
tar -tf archive.tar.gz
# Extract to a specific directory
# C: change directory before extraction
tar -xzvf archive.tar.gz -C /tmp/extract-here
Excluding files is common when backing up home directories. You can skip cache folders, trash bins, or build artifacts to save time and space.
# Create archive while excluding specific patterns
# --exclude: skip files matching the pattern
tar -czvf home-backup.tar.gz /home/user \
--exclude='*.cache' \
--exclude='.local/share/Trash' \
--exclude='node_modules'
tar preserves file permissions, ownership, and symlinks by default. This makes it safe for backing up configuration directories like /etc. If you archive /etc which contains symlinks, the extracted archive will recreate those links pointing to the same relative paths.
Test your backups by extracting to a temporary directory. An archive you can't read is just a digital paperweight.
Common errors and how to fix them
The tar command will refuse to proceed and print tar: Cowardly refusing to create an empty archive. This happens when the path you provided does not exist, or you passed the filename in the wrong position. Check that the source directory exists and that the filename immediately follows the f flag.
If you see tar: Option requires an argument -- f, you typed tar -czvf but didn't provide the filename, or the filename was interpreted as a flag. This often happens if you put the filename before the f flag. The parser sees the filename as a flag and complains that f is missing its argument.
The error tar: This does not look like a tar archive appears when you try to extract a compressed file without the compression flag. If you run tar -xvf archive.tar.gz without the z flag, tar tries to read the gzip header as a tar header and fails. Add the z flag for gzip or J for xz.
If unzip complains about a corrupted zip file, the archive might be incomplete. Check the file size and verify the download. Network interruptions often produce truncated zip files.
Run journalctl -xe if a system service fails to start after an extraction. A botched extraction can overwrite critical binaries or configuration files.
Choosing the right format
Use tar.gz when you need a standard archive that works everywhere on Linux and compresses quickly.
Use tar.xz when you are archiving large datasets and storage space is the priority over compression speed.
Use zip when you are sharing files with users on Windows or macOS who expect a double-clickable archive.
Use tar without compression when you are backing up to a fast local disk and want to minimize CPU usage during the backup window.
Use rsync when you need incremental backups rather than full archives.