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.
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
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.
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.
2. tar -c: create an archive
An archive keeps many files and their paths together. Compression makes the stored bytes smaller. A plain .tar can keep a folder tree while remaining uncompressed. In your lab, archive a folder with two short text files, then use tar -tf to predict the directory layout you’ll get back. The -f option names the archive file the command should work with. The -c, -t and -x options tell tar whether to create it, list it or extract it.
You need one file to copy, upload or keep as a backup instead of thousands.
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.
- Pack a folder.
tar -cvf site.tar www/
Output:
www/
www/index.html
www/css/app.css
One file, not compressed yet.
- 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
Paths start at www/.
3. tar -t: list without extracting
You want to check what is inside, and make sure it will not write to strange paths, before you unpack.
tar -tf FILE lists entries. Add -v for sizes, owners and dates. Works with compressed files too (tar detects the compression when reading).
- List.
tar -tf site.tar | head -3
Output:
www/
www/index.html
www/css/app.css
Safe, relative paths.
- 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
Like ls -l.
4. tar -x and -C: extract, and choose where
Choose a separate empty restore folder. If the listing shows project/report.txt, extracting with -C restore should create restore/project/report.txt. After extraction, compare the restored file with your test original using cmp. An empty cmp result with status zero means the bytes match. This gives better evidence than checking only that the archive opens. Keep the original until you know the restored folder contains the files you expected.
Extracting in the wrong folder can mix files into your home or overwrite things.
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.
- Extract into a new folder.
mkdir -p /tmp/restore && tar -xf site.tar -C /tmp/restore && ls /tmp/restore
Output:
www
Contained and tidy.
- Only one file.
tar -xf site.tar -C /tmp/restore www/index.html
Output:
(no output)
Quick restore of one page.
- Do not overwrite.
tar -xkf site.tar -C /tmp/restore
Output:
tar: www/index.html: Cannot open: File exists
Keeps your newer copy.
5. tar -z: gzip compression (.tar.gz, .tgz)
Logs and text compress 5 to 10 times. gzip is fast and opens everywhere.
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.
- 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
From 48 MB to 6.2 MB.
- Extract it.
tar -xzf logs-2026-10-25.tar.gz -C /tmp/restore
Output:
(no output)
Leading / was removed when created.
6. tar -J and -j: xz and bzip2
For files kept a long time or downloaded many times, smaller matters more than speed.
-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.
- 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
Smaller than gzip's 6.2M.
- Use every core.
tar -I 'xz -T0' -cf release.tar.xz build/
Output:
(no output)
Much faster on big servers.
- bzip2.
tar -cjf old.tar.bz2 build/
Output:
(no output)
Only if someone asks for .bz2.
7. zstd with tar: fast and small
For backups and CI caches you want speed close to gzip and size close to xz. zstd gives both.
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.
- 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
Quick to make and open.
- Extract.
tar --zstd -xf cache.tar.zst
Output:
(no output)
Same -x as always.
8. --exclude and --exclude-from
You do not want node_modules, .git, caches or secrets in a backup or release.
--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.
- Release without junk.
tar --exclude=node_modules --exclude='*.log' --exclude-vcs -czf app.tgz app/
Output:
(no output)
Small and clean.
- From a file.
printf '.env\n*.pem\ntmp/\n' > .tarignore && tar -X .tarignore -czf app.tgz app/
Output:
(no output)
Secrets never leave.
- Check nothing leaked.
tar -tzf app.tgz | grep -E '\.env|\.pem' || echo none
Output:
none
Always check.
9. --strip-components, -p and --same-owner
Use the file list to see which path components tar will remove. For project/docs/report.txt, stripping one component leaves docs/report.txt. Stripping two leaves report.txt. List the archive before choosing the count and try the extraction in the empty restore directory. Check that paths don’t unexpectedly collapse onto the same name. Decide whether you need to restore file owners and modes using your backup plan and identity, especially when you are practising with an archive from a different machine.
Downloaded releases often have a top folder like app-1.2.3/ that you do not want. Backups need permissions kept.
--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.
- 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
bin is directly in /opt/node.
- Backup with owners.
sudo tar -cpzf etc-backup.tgz --numeric-owner /etc
Output:
tar: Removing leading `/' from member names
The warning is normal.
10. gzip and gunzip: one file
Old logs and SQL dumps are single files; you just want them smaller.
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).
- 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
Both kept.
- Ratio.
gzip -l dump.sql.gz
Output:
compressed uncompressed ratio uncompressed_name
32505111 220200960 85.2% dump.sql
85% saved.
- Decompress.
gunzip -k dump.sql.gz
Output:
gzip: dump.sql already exists; do you wish to overwrite (y or n)?
-k and an existing file: it asks.
11. zcat, zless and zgrep: read without unpacking
Rotated logs are .gz. Unpacking them all wastes disk and time.
zcat FILE.gz prints the text. zless pages it. zgrep PATTERN FILE.gz searches. xzcat, bzcat, zstdcat do the same for other formats.
- Search old logs.
sudo zgrep -c ' 500 ' /var/log/nginx/access.log.2.gz
Output:
37
37 server errors that day.
- First lines.
zcat dump.sql.gz | head -n 2
Output:
-- PostgreSQL database dump
-- Dumped from database version 16.4
No file written.
12. xz, bzip2 and zstd on single files
Each tool has the same pattern, so once you know gzip you know them all.
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.
| Tool | Speed | Size | Use for |
|---|---|---|---|
| gzip | Fast | Medium | Logs, web, everywhere |
| bzip2 | Slow | Smaller | Old systems |
| xz | Slowest | Smallest | Releases, archives |
| zstd | Very fast | Small | Backups, CI, streaming |
- 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
22M vs gzip 31M.
- zstd.
zstd -T0 dump.sql
Output:
dump.sql : 13.10% (210 MiB => 27.5 MiB, dump.sql.zst)
Fast, original kept.
- Stream a dump straight to a compressed file.
pg_dump shopdb | zstd -T0 > shopdb.sql.zst
Output:
(no output)
No big temp file.
13. zip and unzip
Windows and Mac users, emails and many web uploads expect .zip.
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.
- 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
Ready for email.
- List.
unzip -l reports-oct.zip | tail -n 3
Output:
8120 2026-10-25 13:58 reports/gst.csv
--------- -------
9921040 14 files
14 files inside.
- Extract into a folder.
unzip -q reports-oct.zip -d /tmp/rep && ls /tmp/rep
Output:
reports
Contained.
zip in depth: -r, -e, -u and -9
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.
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
| Option | What it does |
|---|---|
-r | Recursive: add a folder and everything inside it. |
-e | Encrypt: ask for a password and lock the zip. |
-u | Update: add only new or changed files to an existing zip. |
-9 | Best (slowest) compression. -1 is fastest. Default is 6. |
-q | Quiet: do not print each file name. |
-x | Exclude files that match a pattern. |
- 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%)
Without -r you would get only the empty folder entry.
- Lock it with a password using -e.
zip -er salary-slips.zip slips
Output:
Enter password:
Verify password:
adding: slips/ (stored 0%)
The zip cannot be opened without the password. The password is not shown while you type.
- Add a changed file with -u.
zip -u gst-2026.zip gst-2026/may.csv
Output:
updating: gst-2026/may.csv (deflated 70%)
Only the new or newer file goes in. The rest stay as they were.
- 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
-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
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.
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
| Option | What it does |
|---|---|
-l | List the files inside, do not extract. |
-d DIR | Extract into folder DIR (it is created if needed). |
-o | Overwrite existing files without asking. |
-n | Never overwrite existing files. |
-t | Test the zip for damage, do not extract. |
-q | Quiet output. |
zip file1 | Extract only file1 from the zip. |
- 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
Two PDFs are inside. Nothing was written to disk.
- 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
Files go to /srv/kyc/v102, not the current folder.
- Replace old copies with -o.
unzip -o plugin-v2.zip -d wp-content/plugins
Output:
inflating: wp-content/plugins/seo/seo.php
No "replace? [y]es, [n]o" question. Good for scripts.
- 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.
The zip is safe to use. A broken zip shows "bad CRC" or "End-of-central-directory signature not found".
- Take out one file only.
unzip vendor-kyc.zip pan.pdf
Output:
inflating: pan.pdf
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
A backup you cannot restore is not a backup. Corrupt archives are found only when you need them, unless you test.
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.
- Test gzip.
gzip -t logs-2026-10-25.tar.gz && echo OK
Output:
OK
No output from gzip = good.
- Zip test.
unzip -tq reports-oct.zip
Output:
No errors detected in compressed data of reports-oct.zip.
Safe to send.
- Checksum after upload.
sha256sum app.tgz > app.tgz.sha256 && sha256sum -c app.tgz.sha256
Output:
app.tgz: OK
Same bytes on both ends.
15. Real examples from many industries
The same Linux skill shows up in every kind of company. Seeing it in many places helps you remember it.
Each row is a made-up team. It shows who uses this and how.
| Team and city | How they use it | Command |
|---|---|---|
| Amit, CA office, Pune | Zips monthly GST reports for clients | zip -r gst-oct.zip gst/ |
| Hannah, SaaS, Berlin | Ships releases as .tar.xz | tar -cJf app.tar.xz build/ |
| Omar, bank, Riyadh | Nightly DB dump streamed to zstd | pg_dump db | zstd > db.zst |
| Yuki, gaming, Tokyo | Searches old rotated logs with zgrep | zgrep 'match_id=91' access.log.3.gz |
| Diego, media, Lima | Backs up /etc with owners kept | tar -cpzf etc.tgz /etc |
| Kavya, hospital, Nashik | Verifies every backup archive | gzip -t backup.tgz |
16. Common errors and how to fix them
Everyone hits these errors. Knowing the cause saves hours.
Read the exact message first. Then match it to a row below.
| Error you see | Why it happens | How to fix |
|---|---|---|
tar: Cowardly refusing to create an empty archive | No files named after -f NAME | Give the folder to pack.tar -czf out.tgz folder/ |
tar: Removing leading `/' from member names | You gave an absolute path; tar makes it safe | Normal; or use -C / with relative path.tar -czf etc.tgz -C / etc |
gzip: stdin: not in gzip format | File is not gzip (maybe plain tar or xz) | Check with file, use the right flag.file archive.tgz |
tar: Error is not recoverable: exiting now | Archive truncated or corrupt | Re-download; verify checksum.sha256sum -c app.tgz.sha256 |
tar: f: Cannot open: No such file or directory | Option order: -fcz puts c as the file name | Keep 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 exist | Create it first.mkdir -p /target |
gzip: dump.sql.gz already exists; do you wish to overwrite (y or n)? | Output exists | Remove it or use -f.gzip -f dump.sql |
zip warning: name not matched: reports | Path wrong or not in this folder | Check the path.ls -d reports |
unzip: cannot find zipfile directory | Not a zip, or incomplete download | Check with file and size.file reports.zip |
No space left on device during tar | Writing the archive on the same full disk | Write to another disk or stream it away.tar -czf - dir | ssh backup 'cat > dir.tgz' |
17. Troubleshooting step by step
When an archive will not open, find its real type, test it, then extract into an empty folder.
Go top to bottom. Stop at the first step that shows the problem.
- What is it really?
file backup.tgz
- Is the size sane?
ls -lh backup.tgz
- Test the compression layer.
gzip -t backup.tgz
- List the tar layer.
tar -tzf backup.tgz | head
- Compare checksum with the source.
sha256sum backup.tgz
- Extract into an empty folder.
mkdir -p /tmp/x && tar -xzf backup.tgz -C /tmp/x
18. Lab 1: Backup and restore a project
Create a project, back it up without junk, verify it, delete and restore it.
A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).
- 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)
- Backup with excludes.
tar --exclude=node_modules --exclude=.env -czf proj.tgz proj/
Output:
(no output)
- Check contents.
tar -tzf proj.tgz
Output:
proj/
proj/src/
proj/src/app.js
- Verify and checksum.
gzip -t proj.tgz && sha256sum proj.tgz > proj.tgz.sha256 && sha256sum -c proj.tgz.sha256
Output:
proj.tgz: OK
- 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
Compress the same file with each tool, compare size and time, and read one without unpacking.
A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).
- 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
- gzip and xz.
time gzip -k nums.txt; time xz -k -T0 nums.txt
Output:
real 0m0.9s
real 0m2.8s
- zstd and zip.
zstd -q nums.txt; zip -q nums.zip nums.txt
Output:
(no output)
- 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
- 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.
Ravindra Bagale's Tip – मराठी
tar c-x-t म्हणून लक्षात ठेवा: Create, eXtract, lisT, आणि f शेवटी कारण नाव त्याच्या नंतर येतं. कोणत्याही backup वर विश्वास ठेवण्याआधी test करा (gzip -t) आणि एकदा रिकाम्या folder मधे restore करा.
Ravindra Bagale's Tip – हिंदी
tar को c-x-t याद रखें: Create, eXtract, lisT, और f आखिर में क्योंकि नाम उसके बाद आता है. किसी भी backup पर भरोसा करने से पहले test करें (gzip -t) और एक बार खाली folder में restore करें.
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
- Back up your home folder's Documents with tar and zstd, excluding *.iso. Test it and restore into /tmp/check.
- Take a log file, compress it with gzip, xz and zstd, and write a table of size and time.
Practise this chapter
Interview questions and answers
How do you prove that an archive is a usable backup?
List the archive members, extract them into a separate empty directory and compare important restored files with the originals. Verify meaningful content and the expected paths, plus metadata needed by the app. That demonstrates recovery rather than just archive creation.
Check your understanding
Choose an answer, then compare your reasoning with the explanation.
Practice Tasks
Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.
About this scenarioMilan 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
Backups and transfers need archives.
Create site.tar.gz from the folder site.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy List an archive
Backups and transfers need archives.
List contents of site.tar.gz.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Extract
Backups and transfers need archives.
Extract site.tar.gz here.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Best gzip compression
Backups and transfers need archives.
Compress error.log with gzip at maximum level 9.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Uncompress
Backups and transfers need archives.
Uncompress access.log.gz.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Make a zip
Backups and transfers need archives.
Zip the folder report into report.zip.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy List zip
Backups and transfers need archives.
List contents of report.zip without extracting.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Uncompress xz
Backups and transfers need archives.
Uncompress dump.sql.xz.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Max zip compression
Backups and transfers need archives.
Zip the folder logs into logs.zip with the best compression level.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Check a zip
Backups and transfers need archives.
Check invoices.zip for damage without extracting it.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Extract elsewhere
Backups and transfers need archives.
Extract site.tar.gz into /srv/www.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium xz archive
Backups and transfers need archives.
Create logs.tar.xz from folder logs.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Keep original
Backups and transfers need archives.
gzip access.log but keep the original.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Read without extracting
Backups and transfers need archives.
Search ERROR in app.log.gz without extracting.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Unzip elsewhere
Backups and transfers need archives.
Unzip report.zip into /tmp/r.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium xz a file
Backups and transfers need archives.
Compress dump.sql with xz using all CPU cores.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Password zip
Backups and transfers need archives.
Zip the folder payroll into payroll.zip with a password lock.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Update a zip
Backups and transfers need archives.
Put only the changed file index.html into the existing site.zip.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Unzip without asking
Backups and transfers need archives.
Extract theme.zip here and replace existing files without any question.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium One file from a zip
Backups and transfers need archives.
Extract only cover.jpg from photos.zip.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Hard Exclude files
Backups and transfers need archives.
Archive app as app.tar.gz but skip node_modules.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Hard Test integrity
Backups and transfers need archives.
Test backup.tar.gz for damage.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
22. Related chapters
- Linux Ops Refresh for DevOps
- Bash Scripting for Automation
- Linux grep and find Commands with Examples
- How to Set Up Passwordless SSH Between Linux Servers
In short
- tar -c create, -t list, -x extract, f before the name.
- -z gzip, -J xz, -j bzip2, --zstd zstd.
- -C, --exclude, --strip-components shape the result.
- gzip/gunzip -k, zcat and zgrep for single files.
- zip -r and unzip -d for Windows-friendly archives.
- 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.








More cards: Ravi Sir's Cards.