Table of Contents#
- Question 1: Basic Archiving with tar
- Question 2: Compression Formats
- Question 3: Compressing and Archiving in One Step
- Question 4: Extracting Archives
- Question 5: Best Practices for Archiving and Compression
- Answers and Explanations
- References
Question 1: Basic Archiving with tar#
What is the correct command to create a tar archive named myarchive.tar containing the files file1.txt, file2.txt, and the directory mydir?
A. tar -cvf myarchive.tar file1.txt file2.txt mydir
B. tar -xvf myarchive.tar file1.txt file2.txt mydir
C. tar -zcvf myarchive.tar file1.txt file2.txt mydir
D. tar -jcvf myarchive.tar file1.txt file2.txt mydir
Question 2: Compression Formats#
Which of the following compression formats is known for its high compression ratio but relatively slower compression speed? A. gzip (.gz) B. bzip2 (.bz2) C. xz (.xz) D. zip (.zip)
Question 3: Compressing and Archiving in One Step#
What command would you use to create a compressed tar archive named myarchive.tar.gz containing the files file1.txt and file2.txt?
A. tar -cvf myarchive.tar.gz file1.txt file2.txt
B. tar -zcvf myarchive.tar.gz file1.txt file2.txt
C. tar -jcvf myarchive.tar.gz file1.txt file2.txt
D. tar -xvf myarchive.tar.gz file1.txt file2.txt
Question 4: Extracting Archives#
How would you extract the contents of a myarchive.tar.bz2 archive to the current directory?
A. tar -cvf myarchive.tar.bz2
B. tar -zxvf myarchive.tar.bz2
C. tar -jxvf myarchive.tar.bz2
D. tar -xvf myarchive.tar.bz2
Question 5: Best Practices for Archiving and Compression#
Which of the following is a best practice when archiving and compressing files in Linux? A. Always use the highest compression ratio available, regardless of the time it takes. B. Keep a backup of the original files before archiving and compressing. C. Use a single large archive for all files, regardless of their type or usage. D. Avoid compressing already compressed files, as it may increase the file size.
Answers and Explanations#
Answer 1: A#
- Option A:
tar -cvf myarchive.tar file1.txt file2.txt mydiris the correct command. The-coption creates a new archive,-venables verbose mode (showing the files being added), and-fspecifies the archive file name. - Option B:
tar -xvfis used to extract an archive, not create one. - Option C:
tar -zcvfis used to create a gzip - compressed tar archive. The question asks for a non - compressed tar archive. - Option D:
tar -jcvfis used to create a bzip2 - compressed tar archive.
Answer 2: C#
- Option A: gzip (
*.gz) offers a good balance between compression ratio and speed. It is relatively fast and provides a decent compression ratio. - Option B: bzip2 (
*.bz2) has a higher compression ratio than gzip but is slower. - Option C: xz (
*.xz) is known for its extremely high compression ratio, but it has the slowest compression speed among the common Linux compression formats. - Option D: zip (
*.zip) is more commonly used on Windows systems. While it can be used in Linux, its compression performance is generally not as good as the native Linux compression formats.
Answer 3: B#
- Option A:
tar -cvfcreates a non - compressed tar archive. It will not compress the files with gzip. - Option B:
tar -zcvfis the correct command. The-zoption tellstarto use gzip for compression,-ccreates a new archive,-venables verbose mode, and-fspecifies the archive file name. - Option C:
tar -jcvfis used to create a bzip2 - compressed tar archive, not a gzip - compressed one. - Option D:
tar -xvfis used to extract an archive, not create one.
Answer 4: C#
- Option A:
tar -cvfis used to create a tar archive, not extract one. - Option B:
tar -zxvfis used to extract a gzip - compressed tar archive (*.tar.gz). - Option C:
tar -jxvfis the correct command. The-joption indicates that the archive is compressed with bzip2,-xextracts the archive,-venables verbose mode, and-fspecifies the archive file name. - Option D:
tar -xvfis used to extract a non - compressed tar archive.
Answer 5: B and D#
- Option A: Using the highest compression ratio available can be time - consuming. It is better to balance the compression ratio with the time required, especially for large files or when time is a constraint.
- Option B: Keeping a backup of the original files is a best practice. Archiving and compression involve modifying the original data, and having a backup ensures that you can recover the data in case of any issues.
- Option C: Creating a single large archive for all files can make it difficult to manage and extract specific files. It is better to group files logically into separate archives based on their type, usage, or time of creation.
- Option D: Compressing already compressed files (such as JPEG or MP3 files) can actually increase the file size due to the overhead of the compression algorithm. So, it is best to avoid compressing them.
References#
- "The Linux Documentation Project": https://tldp.org/
- "GNU Tar Manual": https://www.gnu.org/software/tar/manual/html_node/
- "Linux.com": https://www.linux.com/