0
0
Linux CLIscripting~30 mins

bzip2 and xz compression in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Compress and Decompress Files Using bzip2 and xz
📖 Scenario: You have a folder with text files that you want to compress to save space. You will learn how to use bzip2 and xz commands to compress and decompress files in Linux.
🎯 Goal: Learn to compress a file using bzip2 and xz, then decompress it back to the original file.
📋 What You'll Learn
Use the bzip2 command to compress a file
Use the xz command to compress a file
Use the bunzip2 command to decompress a bzip2 file
Use the unxz command to decompress an xz file
Display the contents of the decompressed files
💡 Why This Matters
🌍 Real World
Compressing files saves disk space and makes it easier to transfer files over the internet or between systems.
💼 Career
System administrators and developers often compress logs, backups, and data files to optimize storage and network usage.
Progress0 / 4 steps
1
Create a sample text file
Create a file called example.txt with the exact content: Hello, this is a test file for compression.
Linux CLI
Need a hint?

Use the echo command with redirection > to create the file.

2
Compress the file using bzip2
Use the bzip2 command to compress the file example.txt. This will create example.txt.bz2 and remove the original file.
Linux CLI
Need a hint?

Simply run bzip2 example.txt to compress the file.

3
Decompress the bzip2 file and display content
Use the bunzip2 command to decompress example.txt.bz2 back to example.txt. Then use cat to display the content of example.txt.
Linux CLI
Need a hint?

Use bunzip2 example.txt.bz2 to decompress and cat example.txt to show the file content.

4
Compress and decompress using xz
First, recreate example.txt with the same content. Then compress it using xz to create example.txt.xz. Next, decompress it using unxz back to example.txt. Finally, display the content of example.txt using cat.
Linux CLI
Need a hint?

Use echo to recreate the file, xz to compress, unxz to decompress, and cat to display.