Ravindra BagaleCourses & study guides मराठी Track your progress

Linux tar, gzip, zip and xz: Archive and Compress Files with Examples

Backups, log shipping, code releases and file transfers all need two things: put many files into one file (archive) and make it smaller (compress). tar does the first. gzip, bzip2, xz and zstd do the second. zip does both and opens on Windows. We learn each command and each key option, one by one, with a safe habit for every step.

What you'll learn in this chapter

  • Create, list and extract tar archives
  • Compress with -z, -j, -J and zstd
  • Use -C, --exclude and --strip-components
  • Use gzip, gunzip, zcat and -k
  • Use xz, bzip2 and zstd and pick the right one
  • Use zip and unzip, and verify archives

1. An everyday example: packing for a move

Why do we need this?

When a family moves from Pune to Bengaluru, they put many small things into one carton and tape it. Then they squeeze clothes in vacuum bags so the carton holds more. A list is stuck on top so they know what is inside without opening it.

What is it?

Carton = tar archive. Vacuum bag = compression (gzip, xz). The list on top = tar -t. Unpacking at the new house in the right room = tar -x -C /target.

How to do it (step by step)

How tar.gz is made and openedtar walks the folder and writes each file with its name, owner, mode and timeThe stream goes through gzip (-z) which shrinks itResult: one .tar.gz fileTo open, gzip expands the streamtar reads each entry and recreates files under the target folderOwners are restored only when extracting as root
Always list (-t) before you extract an archive from someone else.

2. tar -c: create an archive

Why do we need this?

You need one file to copy, upload or keep as a backup instead of thousands.

What is it?

tar -c creates. -f NAME gives the archive file name (must come right before the name). -v lists files as it goes. Give the folders or files to add. Use relative paths so it extracts cleanly.

How to do it (step by step)

  1. Pack a folder.
tar -cvf site.tar www/

Output:

www/
www/index.html
www/css/app.css

What it means: One file, not compressed yet.

  1. From the parent folder.
cd /var && sudo tar -cf /tmp/www.tar www && ls -lh /tmp/www.tar

Output:

-rw-r--r--. 1 root root 51M Oct 25 13:30 /tmp/www.tar

What it means: Paths start at www/.

3. tar -t: list without extracting

Why do we need this?

You want to check what is inside, and make sure it will not write to strange paths, before you unpack.

What is it?

tar -tf FILE lists entries. Add -v for sizes, owners and dates. Works with compressed files too (tar detects the compression when reading).

How to do it (step by step)

  1. List.
tar -tf site.tar | head -3

Output:

www/
www/index.html
www/css/app.css

What it means: Safe, relative paths.

  1. Long list.
tar -tvf site.tar | head -2

Output:

drwxr-xr-x ravi/ravi    0 2026-10-25 13:20 www/
-rw-r--r-- ravi/ravi 2140 2026-10-25 13:20 www/index.html

What it means: Like ls -l.

4. tar -x and -C: extract, and choose where

Why do we need this?

Extracting in the wrong folder can mix files into your home or overwrite things.

What is it?

tar -xf FILE extracts into the current folder. -C DIR extracts into DIR (it must exist). Name a path after the archive to extract only that file or folder. -k (--keep-old-files) refuses to overwrite.

How to do it (step by step)

  1. Extract into a new folder.
mkdir -p /tmp/restore && tar -xf site.tar -C /tmp/restore && ls /tmp/restore

Output:

www

What it means: Contained and tidy.

  1. Only one file.
tar -xf site.tar -C /tmp/restore www/index.html

Output:

(no output)

What it means: Quick restore of one page.

  1. Do not overwrite.
tar -xkf site.tar -C /tmp/restore

Output:

tar: www/index.html: Cannot open: File exists

What it means: Keeps your newer copy.

5. tar -z: gzip compression (.tar.gz, .tgz)

Why do we need this?

Logs and text compress 5 to 10 times. gzip is fast and opens everywhere.

What is it?

Add -z to create or extract .tar.gz. The well-known short forms: tar -czf (create), tar -tzf (list), tar -xzf (extract). Modern tar detects compression when extracting, so -xf works too.

How to do it (step by step)

  1. Create .tar.gz.
tar -czf logs-2026-10-25.tar.gz /var/log/shop/ 2>/dev/null; ls -lh logs-2026-10-25.tar.gz

Output:

-rw-r--r--. 1 ravi ravi 6.2M Oct 25 13:35 logs-2026-10-25.tar.gz

What it means: From 48 MB to 6.2 MB.

  1. Extract it.
tar -xzf logs-2026-10-25.tar.gz -C /tmp/restore

Output:

(no output)

What it means: Leading / was removed when created.

6. tar -J and -j: xz and bzip2

Why do we need this?

For files kept a long time or downloaded many times, smaller matters more than speed.

What is it?

-J uses xz (.tar.xz): smallest, slowest. -j uses bzip2 (.tar.bz2): older, in between. Set the level with XZ_OPT=-9 or use -I 'xz -T0' for all CPU cores.

How to do it (step by step)

  1. xz archive.
tar -cJf release.tar.xz build/ && ls -lh release.tar.xz

Output:

-rw-r--r--. 1 ravi ravi 3.9M Oct 25 13:40 release.tar.xz

What it means: Smaller than gzip's 6.2M.

  1. Use every core.
tar -I 'xz -T0' -cf release.tar.xz build/

Output:

(no output)

What it means: Much faster on big servers.

  1. bzip2.
tar -cjf old.tar.bz2 build/

Output:

(no output)

What it means: Only if someone asks for .bz2.

7. zstd with tar: fast and small

Why do we need this?

For backups and CI caches you want speed close to gzip and size close to xz. zstd gives both.

What is it?

tar --zstd -cf FILE.tar.zst (GNU tar 1.31+). Or -I 'zstd -T0 -19' for level and threads. zstd -d FILE.zst to decompress a single file.

How to do it (step by step)

  1. Make a .tar.zst.
tar --zstd -cf cache.tar.zst node_modules/ && ls -lh cache.tar.zst

Output:

-rw-r--r--. 1 ravi ravi 41M Oct 25 13:45 cache.tar.zst

What it means: Quick to make and open.

  1. Extract.
tar --zstd -xf cache.tar.zst

Output:

(no output)

What it means: Same -x as always.

8. --exclude and --exclude-from

Why do we need this?

You do not want node_modules, .git, caches or secrets in a backup or release.

What is it?

--exclude=PATTERN skips matches (put it before the folder names). Repeat it, or list patterns in a file with -X FILE (--exclude-from). --exclude-vcs skips .git and similar.

How to do it (step by step)

  1. Release without junk.
tar --exclude=node_modules --exclude='*.log' --exclude-vcs -czf app.tgz app/

Output:

(no output)

What it means: Small and clean.

  1. From a file.
printf '.env\n*.pem\ntmp/\n' > .tarignore && tar -X .tarignore -czf app.tgz app/

Output:

(no output)

What it means: Secrets never leave.

  1. Check nothing leaked.
tar -tzf app.tgz | grep -E '\.env|\.pem' || echo none

Output:

none

What it means: Always check.

9. --strip-components, -p and --same-owner

Why do we need this?

Downloaded releases often have a top folder like app-1.2.3/ that you do not want. Backups need permissions kept.

What is it?

--strip-components=1 removes the first path part on extract. -p keeps permissions (default as root). --same-owner restores owners (default as root). --numeric-owner stores IDs, not names, for moving between systems.

How to do it (step by step)

  1. Drop the version folder.
tar -xzf node-v22.10.0-linux-x64.tar.gz -C /opt/node --strip-components=1 && ls /opt/node

Output:

bin  include  lib  share

What it means: bin is directly in /opt/node.

  1. Backup with owners.
sudo tar -cpzf etc-backup.tgz --numeric-owner /etc

Output:

tar: Removing leading `/' from member names

What it means: The warning is normal.

10. gzip and gunzip: one file

Why do we need this?

Old logs and SQL dumps are single files; you just want them smaller.

What is it?

gzip FILE replaces FILE with FILE.gz. -k keeps the original. -d or gunzip decompresses. -1 fastest, -9 smallest (default 6). -l shows the ratio. -r does every file in a folder. gzip works on files, not folders (use tar for folders).

How to do it (step by step)

  1. Compress and keep the original.
gzip -k -9 dump.sql && ls -lh dump.sql*

Output:

-rw-r--r--. 1 ravi ravi 210M Oct 25 13:50 dump.sql
-rw-r--r--. 1 ravi ravi  31M Oct 25 13:50 dump.sql.gz

What it means: Both kept.

  1. Ratio.
gzip -l dump.sql.gz

Output:

  compressed        uncompressed  ratio uncompressed_name
    32505111           220200960  85.2% dump.sql

What it means: 85% saved.

  1. Decompress.
gunzip -k dump.sql.gz

Output:

gzip: dump.sql already exists; do you wish to overwrite (y or n)?

What it means: -k and an existing file: it asks.

11. zcat, zless and zgrep: read without unpacking

Why do we need this?

Rotated logs are .gz. Unpacking them all wastes disk and time.

What is it?

zcat FILE.gz prints the text. zless pages it. zgrep PATTERN FILE.gz searches. xzcat, bzcat, zstdcat do the same for other formats.

How to do it (step by step)

  1. Search old logs.
sudo zgrep -c ' 500 ' /var/log/nginx/access.log.2.gz

Output:

37

What it means: 37 server errors that day.

  1. First lines.
zcat dump.sql.gz | head -n 2

Output:

-- PostgreSQL database dump
-- Dumped from database version 16.4

What it means: No file written.

12. xz, bzip2 and zstd on single files

Why do we need this?

Each tool has the same pattern, so once you know gzip you know them all.

What is it?

xz FILE / unxz FILE.xz / xz -k -T0 -9. bzip2 FILE / bunzip2. zstd FILE (keeps original by default) / zstd -d / unzstd. All support -k and -d. -c writes to stdout.

ToolSpeedSizeUse for
gzipFastMediumLogs, web, everywhere
bzip2SlowSmallerOld systems
xzSlowestSmallestReleases, archives
zstdVery fastSmallBackups, CI, streaming

How to do it (step by step)

  1. xz with all cores.
xz -k -T0 dump.sql && ls -lh dump.sql.xz

Output:

-rw-r--r--. 1 ravi ravi 22M Oct 25 13:55 dump.sql.xz

What it means: 22M vs gzip 31M.

  1. zstd.
zstd -T0 dump.sql

Output:

dump.sql : 13.10%   (210 MiB => 27.5 MiB, dump.sql.zst)

What it means: Fast, original kept.

  1. Stream a dump straight to a compressed file.
pg_dump shopdb | zstd -T0 > shopdb.sql.zst

Output:

(no output)

What it means: No big temp file.

13. zip and unzip

Why do we need this?

Windows and Mac users, emails and many web uploads expect .zip.

What is it?

zip -r OUT.zip FOLDER adds a folder. -q quiet. -x 'pattern' excludes. -e asks for a password (weak, do not rely on it). unzip FILE.zip extracts; -d DIR into a folder; -l lists; -o overwrites without asking; -q quiet.

How to do it (step by step)

  1. Zip a report folder.
zip -rq reports-oct.zip reports/ -x '*.tmp' && ls -lh reports-oct.zip

Output:

-rw-r--r--. 1 ravi ravi 2.4M Oct 25 14:00 reports-oct.zip

What it means: Ready for email.

  1. List.
unzip -l reports-oct.zip | tail -n 3

Output:

     8120  2026-10-25 13:58   reports/gst.csv
---------                     -------
  9921040                     14 files

What it means: 14 files inside.

  1. Extract into a folder.
unzip -q reports-oct.zip -d /tmp/rep && ls /tmp/rep

Output:

reports

What it means: Contained.

zip in depth: -r, -e, -u and -9

Why do we need this?

Windows and Mac users open .zip files with a double click. When you send files to a client, an accountant or a teacher, zip is the safest format to share.

What is it?

zip packs many files into one .zip file and compresses them at the same time. First write the zip name, then the files or folders to add.

Common options

OptionWhat it does
-rRecursive: add a folder and everything inside it.
-eEncrypt: ask for a password and lock the zip.
-uUpdate: add only new or changed files to an existing zip.
-9Best (slowest) compression. -1 is fastest. Default is 6.
-qQuiet: do not print each file name.
-xExclude files that match a pattern.

How to do it (step by step)

  1. Zip a whole folder with -r.
zip -r gst-2026.zip gst-2026

Output:

  adding: gst-2026/ (stored 0%)
  adding: gst-2026/april.csv (deflated 71%)

What it means: Without -r you would get only the empty folder entry.

  1. Lock it with a password using -e.
zip -er salary-slips.zip slips

Output:

Enter password:
Verify password:
  adding: slips/ (stored 0%)

What it means: The zip cannot be opened without the password. The password is not shown while you type.

  1. Add a changed file with -u.
zip -u gst-2026.zip gst-2026/may.csv

Output:

updating: gst-2026/may.csv (deflated 70%)

What it means: Only the new or newer file goes in. The rest stay as they were.

  1. Squeeze harder with -9.
zip -9 -r photos-best.zip photos && ls -lh photos-best.zip

Output:

-rw-r--r-- 1 asha asha 41M Oct 25 10:12 photos-best.zip

What it means: -9 is a little smaller but slower. Photos are already compressed, so the gain is small.

Practise this in the tasks below: Practice tasks

unzip in depth: -l, -d, -o, -t and one file

Why do we need this?

People send you zips by email and download links. You must look inside before opening, open in the right folder and check the file is not broken.

What is it?

unzip opens a .zip file. With no option it extracts everything into the current folder. You can also give file names after the zip to extract only those.

Common options

OptionWhat it does
-lList the files inside, do not extract.
-d DIRExtract into folder DIR (it is created if needed).
-oOverwrite existing files without asking.
-nNever overwrite existing files.
-tTest the zip for damage, do not extract.
-qQuiet output.
zip file1Extract only file1 from the zip.

How to do it (step by step)

  1. Look inside first with -l.
unzip -l vendor-kyc.zip

Output:

  Length      Date    Time    Name
---------  ---------- -----   ----
   182044  2026-10-20 09:14   pan.pdf
    90211  2026-10-20 09:15   aadhaar.pdf
---------                     -------
   272255                     2 files

What it means: Two PDFs are inside. Nothing was written to disk.

  1. Extract into a chosen folder with -d.
unzip vendor-kyc.zip -d /srv/kyc/v102

Output:

Archive:  vendor-kyc.zip
  inflating: /srv/kyc/v102/pan.pdf
  inflating: /srv/kyc/v102/aadhaar.pdf

What it means: Files go to /srv/kyc/v102, not the current folder.

  1. Replace old copies with -o.
unzip -o plugin-v2.zip -d wp-content/plugins

Output:

  inflating: wp-content/plugins/seo/seo.php

What it means: No "replace? [y]es, [n]o" question. Good for scripts.

  1. Test for damage with -t.
unzip -t backup-sept.zip

Output:

testing: db.sql   OK
No errors detected in compressed data of backup-sept.zip.

What it means: The zip is safe to use. A broken zip shows "bad CRC" or "End-of-central-directory signature not found".

  1. Take out one file only.
unzip vendor-kyc.zip pan.pdf

Output:

  inflating: pan.pdf

What it means: Only pan.pdf is extracted. Use quotes for patterns, like "*.pdf".

Practise this in the tasks below: Practice tasks

14. Verify archives: -t, -d, --test and checksums

Why do we need this?

A backup you cannot restore is not a backup. Corrupt archives are found only when you need them, unless you test.

What is it?

gzip -t FILE.gz tests. xz -t, zstd -t, unzip -t do the same. tar -tzf FILE > /dev/null reads it all. tar -d (--compare) compares with the disk. sha256sum FILE > FILE.sha256, then sha256sum -c to check after copy.

How to do it (step by step)

  1. Test gzip.
gzip -t logs-2026-10-25.tar.gz && echo OK

Output:

OK

What it means: No output from gzip = good.

  1. Zip test.
unzip -tq reports-oct.zip

Output:

No errors detected in compressed data of reports-oct.zip.

What it means: Safe to send.

  1. Checksum after upload.
sha256sum app.tgz > app.tgz.sha256 && sha256sum -c app.tgz.sha256

Output:

app.tgz: OK

What it means: Same bytes on both ends.

15. Real examples from many industries

Why do we need this?

The same Linux skill shows up in every kind of company. Seeing it in many places helps you remember it.

What is it?

Each row is a made-up team. It shows who uses this and how.

How to do it (step by step)

Team and cityHow they use itCommand
Amit, CA office, PuneZips monthly GST reports for clientszip -r gst-oct.zip gst/
Hannah, SaaS, BerlinShips releases as .tar.xztar -cJf app.tar.xz build/
Omar, bank, RiyadhNightly DB dump streamed to zstdpg_dump db | zstd > db.zst
Yuki, gaming, TokyoSearches old rotated logs with zgrepzgrep 'match_id=91' access.log.3.gz
Diego, media, LimaBacks up /etc with owners kepttar -cpzf etc.tgz /etc
Kavya, hospital, NashikVerifies every backup archivegzip -t backup.tgz

16. Common errors and how to fix them

Why do we need this?

Everyone hits these errors. Knowing the cause saves hours.

What is it?

Read the exact message first. Then match it to a row below.

How to do it (step by step)

Error you seeWhy it happensHow to fix
tar: Cowardly refusing to create an empty archiveNo files named after -f NAMEGive the folder to pack.
tar -czf out.tgz folder/
tar: Removing leading `/' from member namesYou gave an absolute path; tar makes it safeNormal; or use -C / with relative path.
tar -czf etc.tgz -C / etc
gzip: stdin: not in gzip formatFile is not gzip (maybe plain tar or xz)Check with file, use the right flag.
file archive.tgz
tar: Error is not recoverable: exiting nowArchive truncated or corruptRe-download; verify checksum.
sha256sum -c app.tgz.sha256
tar: f: Cannot open: No such file or directoryOption order: -fcz puts c as the file nameKeep f last before the name.
tar -czf out.tgz dir/
tar: /target: Cannot open: No such file or directory (with -C)Target folder does not existCreate it first.
mkdir -p /target
gzip: dump.sql.gz already exists; do you wish to overwrite (y or n)?Output existsRemove it or use -f.
gzip -f dump.sql
zip warning: name not matched: reportsPath wrong or not in this folderCheck the path.
ls -d reports
unzip: cannot find zipfile directoryNot a zip, or incomplete downloadCheck with file and size.
file reports.zip
No space left on device during tarWriting the archive on the same full diskWrite to another disk or stream it away.
tar -czf - dir | ssh backup 'cat > dir.tgz'

17. Troubleshooting step by step

Why do we need this?

When an archive will not open, find its real type, test it, then extract into an empty folder.

What is it?

Go top to bottom. Stop at the first step that shows the problem.

How to do it (step by step)

  1. What is it really?
file backup.tgz
  1. Is the size sane?
ls -lh backup.tgz
  1. Test the compression layer.
gzip -t backup.tgz
  1. List the tar layer.
tar -tzf backup.tgz | head
  1. Compare checksum with the source.
sha256sum backup.tgz
  1. Extract into an empty folder.
mkdir -p /tmp/x && tar -xzf backup.tgz -C /tmp/x

18. Lab 1: Backup and restore a project

Why do we need this?

Create a project, back it up without junk, verify it, delete and restore it.

What is it?

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

How to do it (step by step)

  1. Make files.
mkdir -p proj/src proj/node_modules && echo app > proj/src/app.js && echo secret > proj/.env && echo dep > proj/node_modules/x.js

Output:

(no output)
  1. Backup with excludes.
tar --exclude=node_modules --exclude=.env -czf proj.tgz proj/

Output:

(no output)
  1. Check contents.
tar -tzf proj.tgz

Output:

proj/
proj/src/
proj/src/app.js
  1. Verify and checksum.
gzip -t proj.tgz && sha256sum proj.tgz > proj.tgz.sha256 && sha256sum -c proj.tgz.sha256

Output:

proj.tgz: OK
  1. Delete and restore.
rm -rf proj && tar -xzf proj.tgz && cat proj/src/app.js

Output:

app

19. Lab 2: Compare gzip, xz, zstd and zip

Why do we need this?

Compress the same file with each tool, compare size and time, and read one without unpacking.

What is it?

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

How to do it (step by step)

  1. A big text file.
seq 1 3000000 > nums.txt && ls -lh nums.txt

Output:

-rw-r--r--. 1 ravi ravi 21M Oct 25 14:10 nums.txt
  1. gzip and xz.
time gzip -k nums.txt; time xz -k -T0 nums.txt

Output:

real 0m0.9s
real 0m2.8s
  1. zstd and zip.
zstd -q nums.txt; zip -q nums.zip nums.txt

Output:

(no output)
  1. Compare.
ls -lh nums.txt.* nums.zip | awk '{print $5, $9}'

Output:

6.3M nums.txt.gz
1.5M nums.txt.xz
2.9M nums.txt.zst
6.3M nums.zip
  1. Read without unpacking.
zcat nums.txt.gz | tail -n1

Output:

3000000

Ravindra Bagale's Tip

Remember tar as c-x-t: Create, eXtract, lisT, and keep f last because the name follows it. Before trusting any backup, test it (gzip -t) and restore it once into an empty folder.

20. Frequently asked questions

Q. Archive vs compress?

Archive = many files into one (tar). Compress = make smaller (gzip). .tar.gz does both.

Q. .tgz vs .tar.gz?

Same thing.

Q. Which format should I use?

gzip for compatibility, zstd for speed, xz for smallest, zip for Windows users.

Q. Does tar keep permissions?

Yes, it stores them; restoring owners needs root.

Q. Can gzip compress a folder?

No, tar it first, or gzip -r compresses each file separately.

Q. Why is my .gz not smaller?

Already compressed data (jpg, mp4, zip) does not shrink.

Q. Is zip -e safe?

Old zip encryption is weak. Use gpg or 7z AES for secrets.

Q. How to copy a folder to another server as an archive without temp files?

tar -czf - dir | ssh host 'tar -xzf - -C /dest'.

21. Interview questions and answers

Beginner level

Q. Create a .tar.gz of folder app?

tar -czf app.tgz app/.

Q. List a tar.gz without extracting?

tar -tzf app.tgz.

Q. Extract into /opt?

tar -xzf app.tgz -C /opt.

Q. Keep the original with gzip?

gzip -k FILE.

Mid level level

Q. Exclude node_modules from a tar?

--exclude=node_modules before the folder.

Q. Remove the top folder on extract?

--strip-components=1.

Q. Search inside a .gz log?

zgrep PATTERN FILE.gz.

Q. gzip vs xz vs zstd?

Speed vs size trade-off: gzip balanced, xz smallest, zstd fastest at good size.

Senior level

Q. Design a backup that you trust.

Consistent snapshot or dump, compress with zstd, checksum, copy offsite, test restore regularly, monitor.

Q. What is a tar bomb and how do you avoid it?

An archive without a top folder or with ../ paths; list first and extract into an empty folder.

Q. Move 2 TB between servers fast?

tar | zstd -T0 | ssh or mbuffer, or rsync for resumable copies.

Q. Why --numeric-owner for system backups?

User names may map to different IDs on the restore host.

Try at home

  1. Back up your home folder's Documents with tar and zstd, excluding *.iso. Test it and restore into /tmp/check.
  2. Take a log file, compress it with gzip, xz and zstd, and write a table of size and time.

Practice Tasks

About this scenario

Milan Furniture is a furniture business in Milan. Giulia Rossi looks after its IT and cloud work. They count money in EUR and run their AWS resources in the eu-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 22

Easy Create a tar.gz

Why: Backups and transfers need archives.

What to do: Create site.tar.gz from the folder site.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy List an archive

Why: Backups and transfers need archives.

What to do: List contents of site.tar.gz.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Extract

Why: Backups and transfers need archives.

What to do: Extract site.tar.gz here.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Best gzip compression

Why: Backups and transfers need archives.

What to do: Compress error.log with gzip at maximum level 9.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Uncompress

Why: Backups and transfers need archives.

What to do: Uncompress access.log.gz.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Make a zip

Why: Backups and transfers need archives.

What to do: Zip the folder report into report.zip.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy List zip

Why: Backups and transfers need archives.

What to do: List contents of report.zip without extracting.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Uncompress xz

Why: Backups and transfers need archives.

What to do: Uncompress dump.sql.xz.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Max zip compression

Why: Backups and transfers need archives.

What to do: Zip the folder logs into logs.zip with the best compression level.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Check a zip

Why: Backups and transfers need archives.

What to do: Check invoices.zip for damage without extracting it.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Extract elsewhere

Why: Backups and transfers need archives.

What to do: Extract site.tar.gz into /srv/www.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium xz archive

Why: Backups and transfers need archives.

What to do: Create logs.tar.xz from folder logs.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Keep original

Why: Backups and transfers need archives.

What to do: gzip access.log but keep the original.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Read without extracting

Why: Backups and transfers need archives.

What to do: Search ERROR in app.log.gz without extracting.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Unzip elsewhere

Why: Backups and transfers need archives.

What to do: Unzip report.zip into /tmp/r.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium xz a file

Why: Backups and transfers need archives.

What to do: Compress dump.sql with xz using all CPU cores.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Password zip

Why: Backups and transfers need archives.

What to do: Zip the folder payroll into payroll.zip with a password lock.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Update a zip

Why: Backups and transfers need archives.

What to do: Put only the changed file index.html into the existing site.zip.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Unzip without asking

Why: Backups and transfers need archives.

What to do: Extract theme.zip here and replace existing files without any question.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium One file from a zip

Why: Backups and transfers need archives.

What to do: Extract only cover.jpg from photos.zip.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Exclude files

Why: Backups and transfers need archives.

What to do: Archive app as app.tar.gz but skip node_modules.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Test integrity

Why: Backups and transfers need archives.

What to do: Test backup.tar.gz for damage.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

In short

  1. tar -c create, -t list, -x extract, f before the name.
  2. -z gzip, -J xz, -j bzip2, --zstd zstd.
  3. -C, --exclude, --strip-components shape the result.
  4. gzip/gunzip -k, zcat and zgrep for single files.
  5. zip -r and unzip -d for Windows-friendly archives.
  6. Test with -t and checksums; restore once to be sure.

Revision, comparison and interview cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

tar c t x. Pack a folder into one file. c create, t list, x extract. z gzip, J xz, f file. Make a backup.
Revision card: tar c t x · Download PNG · Open card page
gzip zip xz. Smaller files, faster copies. gzip fast, xz smallest. zip for Windows friends. Read without extracting.
Revision card: gzip zip xz · Download PNG · Open card page
gzip vs xz. Fast. / Slower.
Comparison: gzip vs xz · Download PNG · Open card page
tar.gz vs zip. Linux backups. / Sharing with Windows.
Comparison: tar.gz vs zip · Download PNG · Open card page
gzip vs xz?. gzip: fast, common. xz: smaller, slower. xz with all cores.
Interview card: gzip vs xz? · Download PNG · Open card page
tar.gz vs zip?. tar keeps Linux permissions. zip opens anywhere. Zip a folder.
Interview card: tar.gz vs zip? · Download PNG · Open card page
Skip folders in tar?. node_modules is huge. Use --exclude. Skip it.
Interview card: Skip folders in tar? · Download PNG · Open card page
Check a backup?. Corrupt archives fail restores. List or test it. Test gzip.
Interview card: Check a backup? · Download PNG · Open card page

More cards: Ravi Sir's Cards.