Bookmark this page

Guided Exercise: Manage Compressed tar Archives

Create archive files and extract their contents with the tar command.

Outcomes

  • Archive a directory tree and extract the archive content to another location.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command ensures that all required resources are available.

[student@workstation ~]$ lab start archive-manage

Instructions

  1. From workstation, log in to servera as the student user and switch to the root user.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$ sudo -i
    [sudo] password for student: student
    [root@servera ~]#
  2. Create an archive of the /etc directory with gzip compression. Save the archive file as /tmp/etc.tar.gz.

    [root@servera ~]# tar -czf /tmp/etc.tar.gz /etc
    tar: Removing leading `/' from member names
  3. Verify that the etc.tar.gz archive contains the files from the /etc directory.

    [root@servera ~]# tar -tzf /tmp/etc.tar.gz
    etc/
    etc/mtab
    etc/fstab
    etc/crypttab
    etc/resolv.conf
    ...output omitted...
  4. Create the /backuptest directory. Verify that the etc.tar.gz backup file is a valid archive by decompressing the file to the /backuptest directory.

    1. Create the /backuptest directory and change to that directory.

      [root@servera ~]# mkdir /backuptest
      [root@servera ~]# cd /backuptest
      [root@servera backuptest]#
    2. Extract the /tmp/etc.tar.gz archive to the /backuptest directory.

      [root@servera backuptest]# tar -xzf /tmp/etc.tar.gz
    3. List the contents of the /backuptest directory. Verify that the directory contains the /etc directory backup files.

      [root@servera backuptest]# ls -l
      total 12
      drwxr-xr-x. 95 root root 8192 Feb  8 10:16 etc
      [root@servera backuptest]# ls -l etc
      total 1228
      -rw-r--r--.  1 root root       12 Feb 24 05:25 adjtime
      -rw-r--r--.  1 root root     1529 Jun 23  2020 aliases
      drwxr-xr-x.  2 root root     4096 Mar  3 04:48 alternatives
      ...output omitted...
  5. Return to the workstation system as the student user.

    [root@servera backuptest]# exit
    logout
    [student@servera ~]$ exit
    logout
    Connection to servera closed.
    [student@workstation]$

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish archive-manage

Revision: rh134-9.3-5fd2368