0
0
Linux CLIscripting~30 mins

tar with compression (-z, -j, -J) in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Compress and Extract Files Using tar with Compression Options
📖 Scenario: You have a folder with some files that you want to compress to save space or share easily. You will learn how to use the tar command with different compression options to create compressed archives and then extract them.
🎯 Goal: Learn to create compressed archives using tar with gzip, bzip2, and xz compression options, and then extract the files back from these archives.
📋 What You'll Learn
Use the tar command with -z option for gzip compression
Use the tar command with -j option for bzip2 compression
Use the tar command with -J option for xz compression
Extract files from compressed archives using the correct tar options
💡 Why This Matters
🌍 Real World
Compressing files saves disk space and makes it easier to send multiple files as one package. Extracting archives is needed to access the original files.
💼 Career
System administrators, developers, and IT professionals often use tar with compression to manage backups, deployments, and file transfers.
Progress0 / 4 steps
1
DATA SETUP: Create a folder with files to compress
Create a folder called project_files and inside it create three empty files named file1.txt, file2.txt, and file3.txt.
Linux CLI
Need a hint?

Use mkdir to create a folder and touch to create empty files inside it.

2
CONFIGURATION: Set archive file names for compression
Create three variables named gzip_archive, bzip2_archive, and xz_archive and assign them the values project_files.tar.gz, project_files.tar.bz2, and project_files.tar.xz respectively.
Linux CLI
Need a hint?

Assign the archive file names to variables using = without spaces.

3
CORE LOGIC: Create compressed archives using tar with -z, -j, and -J options
Use the tar command to create three compressed archives from the project_files folder: use -z for gzip compression and save to $gzip_archive, use -j for bzip2 compression and save to $bzip2_archive, and use -J for xz compression and save to $xz_archive.
Linux CLI
Need a hint?

Use tar -czf for gzip, tar -cjf for bzip2, and tar -cJf for xz compression.

4
OUTPUT: Extract files from the gzip compressed archive and list contents
Extract the files from the gzip compressed archive stored in $gzip_archive into a folder named extracted_files. Then list the contents of extracted_files/project_files to verify the files are extracted.
Linux CLI
Need a hint?

Use tar -xzf to extract gzip archives and ls to list files.