Exercise
Creating and Extracting Archives Exercise
Overview
An archive is one file that holds many files, along with the directory structure, ownership, permissions, and timestamps that a plain copy can lose.
In this hands-on exercise you will bundle the entire
/etc directory into a single uncompressed
archive, read its contents without unpacking it, extract
the whole archive into a directory of its own, and then
extract just one file from it.
- Host
servera- Run as
root
-
Bundle all of /etc as root into one uncompressed archive under /tmp
Reading every file under
/etcrequires administrative privileges, so connect toserveraand becomerootfirst.ssh student@servera sudo -i-ccreates,-vlists each member as it is added, and-fnames the archive file.tar -cvf /tmp/etc-backup.tar /etc -
Check the size of the archive you produced
-hprints the size in human-readable units.ls -lh /tmp/etc-backup.tar -
Read the archive's contents without unpacking it
-tlists the members. Notice that every path is stored without its leading slash.tar -tf /tmp/etc-backup.tar | head -n 20 -
Unpack the archive into an empty directory of its own
tarunpacks into the current working directory, so change into a directory of its own first.mkdir -p /tmp/etc-extract cd /tmp/etc-extract tar -xf /tmp/etc-backup.tar ls -
Confirm the extracted tree looks like the original
Compare one extracted file against the original.
diffprinting nothing means the two files are identical.ls -l /tmp/etc-extract/etc | head -n 10 diff /tmp/etc-extract/etc/hosts /etc/hosts -
Extract a single file into a fresh directory
Name the member you want exactly as
-tprinted it:etc/hosts, not/etc/hosts.mkdir -p /tmp/etc-one cd /tmp/etc-one tar -xf /tmp/etc-backup.tar etc/hosts ls -R /tmp/etc-one