Bookmark this page

Guided Exercise: Compressing and Extracting Data

Compress and extract individual files and directories.

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 environment for this exercise, and to ensure that all required resources are available.

[student@workstation ~]$ lab start software-compressed

Instructions

  1. On the command line, review the contents of the ~/Documents directory in a tree-like format.

    [student@workstation ~]$ tree Documents/
    Documents/
    └── Exercise
        ├── Debrief.doc
        ├── Questions
        ├── Solutions
        ├── Summary.txt
        └── presentation.ppt
  2. In the Documents directory, create a back up of the Exercise directory. Use the tar command with the --xz option for the compression. Save the archive file as exercise.tar.xz in the /tmp directory.

    [student@workstation ~]$ cd /home/student/Documents
    [student@workstation Documents]$ tar --create --xz \
    --file /tmp/exercise.tar.xz Exercise/
  3. Create the back up again, and this time, include the ~/Desktop/Notes.txt file. Use the relative path to the Desktop directory as an argument of the tar command. Replace the exercise.tar.xz file with the new back up.

    [student@workstation Documents]$ tar --create --xz \
    --file /tmp/exercise.tar.xz Exercise/ ../Desktop/Notes.txt
    ...output omitted...
  4. Create the /home/student/Backup directory and change to that directory.

    [student@workstation Documents]$ mkdir ~/Backup
    [student@workstation Documents]$ cd ../Backup/
    [student@workstation Backup]$
  5. Extract the /tmp/Exercise.tar.xz file to the Backup directory. Review the contents of the Backup directory.

    1. Extract the /tmp/Exercise.tar.xz file to the Backup directory.

      [student@workstation Backup]$ tar --extract --xz \
      --file /tmp/exercise.tar.xz
    2. Review the contents of the Backup directory.

      [student@workstation Backup]$ tree
      .
      ├── Desktop
      │   └── Notes.txt
      └── Exercise
          ├── Debrief.doc
          ├── Questions
          ├── Solutions
          ├── Summary.txt
          └── presentation.ppt
    3. Return to the student user home directory.

      [student@workstation Backup]$ cd
      [student@workstation ~]$
  6. Using the GNOME Files application, create the MyNotes.zip compressed file of the Backup directory. Use password protection and set RedHat123! as the password.

    1. Open the Files application.

    2. Right-click the Backup directory and click Compress.

      Figure 6.8: Compressing a directory in the Files application
    3. Set MyNotes as the name and select the .zip format with the Lock icon from the drop-down list. Set RedHat123! as the password. Click Create.

      Figure 6.9: Creating a password-protected compressed file in the Files application
  7. In the Files application, extract the MyNotes.zip compressed file. Use RedHat123! as the password.

    1. Double-click the MyNotes.zip file.

    2. The Files application prompts for the compressed file password. Use RedHat123! as the password. Click Extract.

      Figure 6.10: Extracting a password-protected compressed file in the Files application
    3. On the command line, verify that the MyNotes directory contains the expected content.

      [student@workstation ~]$ tree MyNotes
      MyNotes
      └── Backup
          ├── Desktop
          │   └── Notes.txt
          └── Exercise
              ├── Debrief.doc
              ├── Questions
              ├── Solutions
              ├── Summary.txt
              └── presentation.ppt
      
      5 directories, 4 files

Finish

On the workstation machine, 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 software-compressed

Revision: rh104-9.1-3d1f2bc