Study guide

4.3 Archive and Compress with tar, gzip, and bzip2

Red Hat Certified System Administrator RHCSA

Track your progress as you read

Finished sections get a check mark.

1 Introduction & Exam Overview

1.1 Current Exam Facts 1.2 Lab Setup & Performance-Based Study Strategy

2 Essential Tools: Shell, Redirection & Text Analysis

2.1 Shell Prompt and Command Syntax 2.2 Input-Output Redirection and Pipes 2.3 grep and Regular Expressions for Text Analysis

3 Essential Tools: Remote Access, Users & Text Editing

3.1 Access Remote Systems Using SSH 3.2 Log In and Switch Users in Multiuser Targets 3.3 Create and Edit Text Files

4 Essential Tools: Files, Links & Archives

4.1 Create, Delete, Copy, and Move Files and Directories 4.2 Hard and Soft Links 4.3 Archive and Compress with tar, gzip, and bzip2

5 Essential Tools: Permissions & System Documentation

5.1 List, Set, and Change Standard ugo/rwx Permissions 5.2 System Documentation: man, info, and /usr/share/doc

6 Manage Software: RPM and Flatpak

6.1 Configure Access to RPM Repositories 6.2 Install and Remove RPM Software Packages 6.3 Configure Access to Flatpak Repositories 6.4 Install and Remove Flatpak Software Packages

7 Create Simple Shell Scripts

7.1 Conditional Execution: if, test, and [] 7.2 Looping Constructs for Files and Input 7.3 Process Script Inputs ($1, $2, and Beyond) 7.4 Process Shell Command Output in Scripts

8 Operate Running Systems: Boot and Recovery

8.1 Boot, Reboot, and Shut Down a System Normally 8.2 Boot Systems into Different Targets Manually 8.3 Interrupt the Boot Process to Gain Access

9 Operate Running Systems: Processes and Tuning

9.1 Identify and Kill CPU/Memory Intensive Processes 9.2 Adjust Process Scheduling 9.3 Manage Tuning Profiles

10 Operate Running Systems: Logs, Services & File Transfer

10.1 Locate and Interpret System Log Files and Journals 10.2 Preserve System Journals 10.3 Start, Stop, and Check Status of Network Services 10.4 Securely Transfer Files Between Systems

11 Configure Local Storage: Partitions and LVM

11.1 List, Create, and Delete Partitions on GPT Disks 11.2 Create and Remove Physical Volumes 11.3 Assign Physical Volumes to Volume Groups 11.4 Create and Delete Logical Volumes

12 Configure Local Storage: Mounting and Expansion

12.1 Mount File Systems at Boot by UUID or Label 12.2 Add Partitions, Logical Volumes, and Swap Non-Destructively

13 Create and Configure File Systems: Local FS and Permissions

13.1 Create, Mount, and Use VFAT, ext4, and XFS File Systems 13.2 Extend Existing Logical Volumes 13.3 Diagnose and Correct File Permission Problems

14 Create and Configure File Systems: NFS and autofs

14.1 Mount and Unmount Network File Systems Using NFS 14.2 Configure autofs

15 Deploy and Maintain: Scheduling, Services & Targets

15.1 Schedule Tasks with at, cron, and systemd Timers 15.2 Start, Stop, and Enable Services at Boot 15.3 Configure Systems to Boot into a Specific Target

16 Deploy and Maintain: Time, Software Updates & Bootloader

16.1 Configure Time Service Clients 16.2 Install and Update Software from CDN, Remote Repos, and Local Files 16.3 Modify the System Bootloader

17 Manage Basic Networking

17.1 Configure IPv4 and IPv6 Addresses 17.2 Configure Hostname Resolution 17.3 Configure Network Services to Start Automatically at Boot 17.4 Restrict Network Access Using firewalld and firewall-cmd

18 Manage Users and Groups

18.1 Create, Delete, and Modify Local User Accounts 18.2 Change Passwords and Adjust Password Aging 18.3 Create, Delete, and Modify Local Groups and Memberships 18.4 Configure Privileged Access

19 Manage Security: Firewall, umask & SSH Keys

19.1 Configure Firewall Settings with firewall-cmd and firewalld 19.2 Manage Default File Permissions 19.3 Configure Key-Based Authentication for SSH

20 Manage Security: SELinux Modes and Contexts

20.1 Set Enforcing and Permissive Modes for SELinux 20.2 List and Identify SELinux File and Process Contexts 20.3 Restore Default File Contexts

21 Manage Security: SELinux Ports and Booleans

21.1 Manage SELinux Port Labels 21.2 Use Boolean Settings to Modify SELinux Settings

4.3 Archive and Compress with tar, gzip, and bzip2

Key Takeaways Explain This Topic AI

tar bundles many files into one archive; common create/extract patterns use tar -cf / tar -xf, with compression added via z (gzip) or j (bzip2) flags or equivalent modern auto options.

gzip and bzip2 compress individual files by default (replacing the original unless you use options that keep it); tar with -z or -j compresses the whole archive stream.

Memorize create vs extract: c = create, x = extract, t = list, f = archive file name; v = verbose helps verify on the exam.

Preserve ownership and SELinux contexts when required using tar options such as --selinux / appropriate preserve flags, and extract carefully with paths in mind.

Test archives with tar -tf before extracting over important trees; wrong working directory or absolute paths in archives are classic recovery mistakes.

Last updated: August 2026

4.3 Archive and Compress with tar, gzip, and bzip2

Quick Answer: Create a gzip-compressed tarball with tar czf archive.tar.gz tree/ , list with tar tzf archive.tar.gz , extract with tar xzf archive.tar.gz . Use j instead of z for bzip2 ( .tar.bz2 ). Standalone gzip / bzip2 compress single files; tar is for multi-file trees.

The EX200 skill to archive, compress, unpack, and uncompress files using tar, gzip, and bzip2 is the exact wording Red Hat publishes for the RHEL 10 exam. Older revisions of the objective list also named star ; the current list does not. This skill appears whenever you backup a tree, ship logs, or unpack vendor content. On RHEL, these tools are always available in a normal base environment—do not depend on exotic compressors unless the task installs them.

Why Archive and Compress Are Separate Ideas

  • Concept Meaning Typical tool
  • Archive Combine many files/directories into one file, preserving structure tar
  • Compress Shrink a byte stream to save space gzip , bzip2 , xz
  • Compressed archive Archive then compress (or compress while archiving) tar + z / j

A .tar file is an archive that may still be large. A .gz file is usually a single compressed stream. A .tar.gz (or .tgz ) is a tarball compressed with gzip. A .tar.bz2 uses bzip2.

tar Fundamentals

tar originally meant “tape archive.” Today it writes archive files just as often as tapes.

Mode letters you must know

  • Letter Mode
  • c Create archive
  • x Extract archive
  • t List contents (table of contents)
  • f Use archive file name that follows (almost always required for file archives)
  • v Verbose — list members as they are processed
  • z Filter through gzip
  • j Filter through bzip2
  • J Filter through xz (awareness; gzip/bzip2 remain exam staples)
  • p Preserve permissions (extract; often default for root)

Traditional style concatenates letters after a dash (or even without a dash on some examples): tar -cf backup.tar project/

  • tar -tf backup.tar
  • tar -xf backup.tar
  • With compression: tar -czf backup.tar.gz project/
  • tar -tzf backup.tar.gz
  • tar -xzf backup.tar.gz
  • tar -cjf backup.tar.bz2 project/
  • tar -tjf backup.tar.bz2
  • tar -xjf backup.tar.bz2

Memory hook: c reate / x tract / t est-list + f ile + z gzip or j bzip2. The f archive name must immediately associate with the file operand —put the archive filename right after the options that include f (common form: tar czf name.tar.gz ... ).

  • Create examples cd /home/student
  • tar czf /root/student-project.tgz project
  • tar czf app-backup-$(date +%F).tar.gz /srv/app
  • tar cjf /backup/var-log.tar.bz2 -C / var/log

-C / changes directory before adding members so the archive stores var/log/... rather than an absolute /var/log/... layout—often cleaner for portable restores.

  • Extract examples mkdir -p /tmp/restore && cd /tmp/restore
  • tar xzf /root/student-project.tgz
  • tar xjf /backup/var-log.tar.bz2
  • Extract specific members: tar xzf backup.tar.gz path/inside/archive/file.conf
  • List before you extract into a sensitive location: tar tzf backup.tar.gz | head
  • tar tzf backup.tar.gz | grep 'etc/hosts'

Exam trap: Extracting as the wrong user, in the wrong directory, or overwriting live configs without a listing pass. Always pwd and prefer extracting into an empty staging directory first when unsure.

Absolute paths and tar

Older habits sometimes archived absolute paths. GNU tar often strips leading / on extract by default (safer), but you should still inspect with tar tf so you know whether members look like etc/hosts or /etc/hosts . Do not extract untrusted archives as root over / without understanding contents.

  • gzip and bzip2 as Standalone Tools
  • gzip gzip large.log # creates large.log.gz and removes large.log by default
  • gzip -k large.log # keep original if supported (gzip --keep)
  • gunzip large.log.gz # restore
  • zcat large.log.gz # view without writing decompressed file
  • gzip -d large.log.gz # same idea as gunzip

Characteristics:

  • Very common on RHEL for logs and tarballs
  • Fast compression and decompression
  • Typically smaller gains than bzip2 on some text, but quicker
  • bzip2 bzip2 bigdump.sql # creates bigdump.sql.bz2, removes original by default
  • bzip2 -k bigdump.sql # keep input when supported
  • bunzip2 bigdump.sql.bz2
  • bzcat bigdump.sql.bz2 | less

Characteristics:

  • Often better compression ratio than gzip on highly redundant data
  • Slower compress/decompress—noticeable on large trees
  • Pairs with tar via j → .tar.bz2

Single-file vs tar-of-many # Wrong mental model for a directory:

gzip mydir # does not archive a directory tree the way tar does

# Right approach for a directory:

tar czf mydir.tar.gz mydir

gzip / bzip2 operate on files (streams). Directories need tar (or another archiver) first.

  • Combined Workflows You Will Use on the Exam
  • Backup a project tree with gzip tar czf /backup/website-$(date +%F).tar.gz -C /var/www html
  • ls -lh /backup/website-*.tar.gz
  • tar tzf /backup/website-*.tar.gz | head
  • Backup with bzip2 when size matters more than speed tar cjf /backup/website.tar.bz2 -C /var/www html
  • Unpack vendor content cd /usr/local/src
  • tar xzf /tmp/app-1.2.3.tar.gz
  • cd app-1.2.3
  • Compress a single large log without tar gzip -k /var/log/myapp/old.log
  • ls -lh /var/log/myapp/old.log*
  • Pipe tar across a stream (conceptual) tar czf - project | ssh host 'cat > /backup/project.tgz'
  • # or extract from stdin on the far side—patterns appear in multi-host labs
  • Preserving Attributes and Special Files

For ordinary user trees, default tar create/extract is often enough. For system backups you may care about:

  • Permissions and ownership (extract as root to restore original owners)
  • SELinux contexts (GNU tar options such as --selinux when creating/extracting in SELinux environments)
  • Sparse files, device nodes, and ACLs on advanced backups

RHCSA-level tasks usually focus on getting the correct tree back with expected modes . If you archive as root and extract as an unprivileged user into your home directory, ownership becomes yours—verify with ls -l after extract when ownership matters.

cp -a (previous section) is still better for live local clones. Use tar when you need a single portable file , compression, or transfer packaging.

star: legacy objective wording only

Older EX200 objective lists (RHEL 7/8 era) named star (Schily tar) alongside tar. The current RHEL 10 objective names only tar, gzip, and bzip2 , and star is not part of a standard RHEL 10 install. Treat any study material that still drills star as out of date for this exam. Master GNU tar + gzip + bzip2 ; do not spend scarce minutes learning a second archiver that the objective no longer lists.

  • Verification Checklist After Create/Extract
  • Archive exists and size is plausible: ls -lh backup.tar.gz
  • Contents list looks right: tar tzf backup.tar.gz | head / grep
  • Extract into staging: empty directory, then compare with diff -r or ls -lR
  • Spot-check a known file’s content and mode

Clean up temporary copies so you do not leave wrong trees in graded paths mkdir -p /tmp/tarcheck && cd /tmp/tarcheck

  • tar xzf /backup/website.tar.gz
  • find . -type f | head
  • Common Pitfalls

Swapping create and extract — tar xzf on a non-archive path errors; tar czf with wrong argument order can create an archive named after a file you meant to include.

Forgetting f — tar may try to use a default tape device.

Wrong compression letter — using z on a .bz2 archive (or the reverse) produces errors; list with the matching filter or use modern tar auto-detect forms where available ( tar xf file.tar.gz often works on GNU tar).

gzip on a directory — does not replace tar .

Extracting in / or /etc accidentally — always check pwd and archive member prefixes.

Assuming compression keeps originals — classic gzip file removes file unless keep is requested.

Broken workflows with symlinks — decide whether you need to store symlinks as links ( tar does) or follow them; know that extracting may recreate links that break if targets are outside the archive.

Quick Reference Card

  • Goal Command pattern
  • Create gzip tarball tar czf arch.tar.gz dir/
  • Create bzip2 tarball tar cjf arch.tar.bz2 dir/
  • List gzip tarball tar tzf arch.tar.gz
  • Extract gzip tarball tar xzf arch.tar.gz
  • Extract bzip2 tarball tar xjf arch.tar.bz2
  • Compress one file gzip gzip file → file.gz
  • Compress one file bzip2 bzip2 file → file.bz2
  • Decompress gunzip file.gz / bunzip2 file.bz2
  • Practice Drill mkdir -p /tmp/tarlab/src/sub
  • echo one > /tmp/tarlab/src/a.txt
  • echo two > /tmp/tarlab/src/sub/b.txt
  • ln -s a.txt /tmp/tarlab/src/link-to-a
  • cd /tmp/tarlab
  • tar czf src-gzip.tar.gz src
  • tar cjf src-bzip.tar.bz2 src
  • tar tzf src-gzip.tar.gz
  • mkdir out-gz out-bz
  • tar xzf src-gzip.tar.gz -C out-gz
  • tar xjf src-bzip.tar.bz2 -C out-bz
  • ls -lR out-gz out-bz
  • gzip -k out-gz/src/a.txt
  • ls -l out-gz/src/a.txt*

Confirm the symlink survived packaging, both compression flavors unpack to matching trees, and standalone gzip produced a.txt.gz as expected.

Section Checkpoint

You should be able to create and extract .tar.gz and .tar.bz2 archives, list members before unpacking, compress and decompress individual files with gzip and bzip2, choose tar when directories are involved, and avoid path and overwrite mistakes during restore. Combined with solid cp / mv / ln skills, you can stage, package, and reassemble any file tree the exam throws at you.