0
0
Linux CLIscripting~20 mins

tar with compression (-z, -j, -J) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tar Compression Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this tar command?
You run this command in a directory containing a file named file.txt with the text Hello inside:

tar -czf archive.tar.gz file.txt && tar -tzf archive.tar.gz

What will be the output?
Linux CLI
tar -czf archive.tar.gz file.txt && tar -tzf archive.tar.gz
Afile.txt
Bfile.txt\narchive.tar.gz
Carchive.tar.gz
DError: Cannot list compressed archive
Attempts:
2 left
💡 Hint
The -t option lists files inside the archive. The -z option means gzip compression.
💻 Command Output
intermediate
2:00remaining
What error does this command produce?
You run this command:

tar -cjf archive.tar.bz2 file.txt && tar -tzf archive.tar.bz2

What error message will you see?
Linux CLI
tar -cjf archive.tar.bz2 file.txt && tar -tzf archive.tar.bz2
Atar: This does not look like a tar archive
BNo such file or directory
Cfile.txt
Darchive.tar.bz2
Attempts:
2 left
💡 Hint
The -j option compresses with bzip2, but the -z option tries to decompress with gzip.
📝 Syntax
advanced
2:00remaining
Which command correctly creates an xz compressed tar archive?
You want to create a tar archive compressed with xz compression named archive.tar.xz containing the folder data. Which command is correct?
Atar -cZf archive.tar.xz data
Btar -cJf archive.tar.xz data
Ctar -cjf archive.tar.xz data
Dtar -czf archive.tar.xz data
Attempts:
2 left
💡 Hint
The -J option is for xz compression.
🚀 Application
advanced
2:00remaining
How to extract a bzip2 compressed archive to a specific folder?
You have a bzip2 compressed tar archive named backup.tar.bz2. You want to extract its contents into the folder /tmp/restore. Which command will do this correctly?
Atar -xvf backup.tar.bz2 /tmp/restore
Btar -xzf backup.tar.bz2 -C /tmp/restore
Ctar -xJf backup.tar.bz2 -C /tmp/restore
Dtar -xjf backup.tar.bz2 -C /tmp/restore
Attempts:
2 left
💡 Hint
Use -j for bzip2 and -C to specify extraction directory.
🔧 Debug
expert
2:00remaining
Why does this tar extraction fail with 'Cannot open: No such file or directory'?
You run this command:

tar -xzf archive.tar.bz2

and get the error:

tar: archive.tar.bz2: Cannot open: No such file or directory

What is the most likely cause?
Linux CLI
tar -xzf archive.tar.bz2
AThe archive is corrupted
BThe -z option cannot be used with .bz2 files
CThe file archive.tar.bz2 does not exist in the current directory
DYou need to run the command as root
Attempts:
2 left
💡 Hint
Check if the file is present in the folder you are running the command from.