Archive & Compress files with tar - The Survival Guide
Introduction
Welcome to the tar survival guide.
In this challenge everything lives in /home/laborant/tar_challenge/, and you write outputs in /home/laborant/ (q1, q2, ...).
The tasks in this challenge cover many aspects of the tar command: create, gzip, bzip2, list without extract, targeted extraction, exclude patterns, append, update, and xz compression...
Before pinging your favorite AI to found a solution (and its not a shame), explore man tar and test for real, this may be the best way to reinforce your memory and refine your skills.
Man page tips:
man tar, then/keyword: replace keyword withcreate,append,exclude,gzip,xz,updateto search for specific topics.tar --help | lessfor a quick view.- Always double-check with
tar -tfortar -xOfbefore overwriting anything.
Task 1: Create an uncompressed archive
Goal: Create the archive (without compression) /home/laborant/q1_system_backup.tar containing just the directory system/ from /home/laborant/tar_challenge/.
Task 2: Create a gzip-compressed archive
Goal: Create the gzip-compressed archive /home/laborant/q2_system_backup.tar.gz containing just the directory system/ from /home/laborant/tar_challenge/.
Task 3: Create a bzip2-compressed archive
Goal: Create the bzip2-compressed archive /home/laborant/q3_system_backup.tar.bz2 containing the system/ directory from /home/laborant/tar_challenge/.
Task 4: List archive contents
Goal: List the contents of the archive /home/laborant/q3_system_backup.tar.bz2 and save the output to /home/laborant/q4_list.txt (without extracting the archive).
Task 5: Extract archive to a specific directory
Goal: Extract the gzip archive /home/laborant/q2_system_backup.tar.gz into the directory /home/laborant/restored_system/ (create the directory mkdir /home/laborant/restored_system first if it doesn't exist).
Task 6: Create an archive with exclusions
Goal: Create the archive /home/laborant/q5_no_logs.tar from the /home/laborant/tar_challenge/system/ directory, excluding all *.log files and the file system/notes/todo.txt (you will append it in the next task).
Task 7: Append a file to an existing archive
Goal: Append the file system/notes/todo.txt to the existing archive /home/laborant/q5_no_logs.tar.
Task 8: Update a file in an existing archive
Goal: Update the file system/etc/hosts inside the archive /home/laborant/q1_system_backup.tar with the newer version from /home/laborant/tar_challenge/updates/system/etc/hosts.
Steps:
- Modify the file
/home/laborant/tar_challenge/updates/system/etc/hostsby appending a line (e.g.,echo "# update01" >> /home/laborant/tar_challenge/updates/system/etc/hosts) to make it newer than the version in the archive. - Use the command to update only the modified file
system/etc/hostsin the existing archive (without recreating the entire archive). - (Optional) Verify that the archive now contains your modification using
tar -xOf.
Task 9: Create an xz-compressed archive with exclusions
Goal: Create the xz-compressed archive /home/laborant/q8_full.tar.xz from /home/laborant/tar_challenge/, excluding all *.log files. Then verify the archive contents without extracting it.