0
0
Linux CLIscripting~20 mins

bzip2 and xz compression in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Compression Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Output of bzip2 compression command
What is the output of the following command sequence on a file named example.txt containing the text "hello world"?

cat example.txt | bzip2 > example.txt.bz2 && bzip2 -d -c example.txt.bz2
Linux CLI
echo 'hello world' > example.txt
cat example.txt | bzip2 > example.txt.bz2 && bzip2 -d -c example.txt.bz2
A
bzip2: (stdin) is not a valid bzip2 file
B
hello world.bz2
C
hello world
D
example.txt.bz2
Attempts:
2 left
💡 Hint
Think about what the bzip2 -d -c command does with the compressed file.
💻 Command Output
intermediate
1:30remaining
Comparing xz and bzip2 compression sizes
Given a file data.txt with repetitive content, which command will most likely produce the smallest compressed file size?
Axz -z data.txt
Bbzip2 -z data.txt
Ccat data.txt > data.txt.xz
Dgzip -z data.txt
Attempts:
2 left
💡 Hint
Consider which compression tool generally achieves better compression ratios on repetitive data.
🔧 Debug
advanced
2:00remaining
Why does this bzip2 command fail?
You run the command bzip2 -d example.txt.bz2 but get the error: bzip2: Can't decompress file: No such file or directory. The file example.txt.bz2 exists in your current directory. What is the most likely cause?
Linux CLI
bzip2 -d example.txt.bz2
AYou do not have read permission on the file
BThe file is actually compressed with xz, not bzip2
CThe file is corrupted and cannot be decompressed
DYou are running the command in a different directory than where the file is located
Attempts:
2 left
💡 Hint
Check your current directory and the file location carefully.
🧠 Conceptual
advanced
1:30remaining
Difference in compression options between bzip2 and xz
Which statement correctly describes a difference between bzip2 and xz compression tools?
A<code>xz</code> supports higher compression levels and multi-threading, <code>bzip2</code> does not
B<code>bzip2</code> compresses faster and produces smaller files than <code>xz</code>
C<code>bzip2</code> supports multi-threaded compression by default, <code>xz</code> does not
D<code>xz</code> cannot decompress files compressed by <code>bzip2</code>
Attempts:
2 left
💡 Hint
Think about modern compression features and performance.
🚀 Application
expert
2:30remaining
Automate compression and decompression with error handling
You want to write a shell script that compresses a file using xz and then decompresses it back, printing the decompressed content. The script should check if the compression succeeded before decompressing. Which script snippet correctly implements this?
Axz file.txt && xz -d -c file.txt.xz
Bxz file.txt; if [ $? -eq 0 ]; then xz -d -c file.txt.xz; fi
Cxz file.txt || echo 'Compression failed'; xz -d -c file.txt.xz
Dxz file.txt && echo 'Compression done'; xz -d -c file.txt.xz
Attempts:
2 left
💡 Hint
Use shell conditional statements to check command success.