"

Level 2 Linux Exercises

Submitting Multiple Files (with zip or tar)

Building Archives is part of every Lab and every Programming Assignment!
Make sure to pay close attention to the process.

It is very common to destroy the contents of your files if these instructions are not carefully followed!

When submitting multiple files to D2L, they must be archived into a single file for submission. If this is not done, we may not be able to grade your work as D2L changes file names. Zip or tar may be used as described below.

Backup your Files!

Step 1) Backup your files – There are many ways to back up your files but here are two ways listed:

  1. Use Cyberduck to copy your files from your remote server to your PC.
  2. Rsync – Using the rsync command not only will copy your files from one directory to another, it will sync files on two directories on the same remote location.
    How to use Rsync on your Linux terminal:
    rsync –r  source_directory  destination_directory

So now if you accidentally delete your files while making a tar file, you will have backups. Doing both is recommended.

Creating Archives with Tar and Zip

  1. Read these instructions carefully.
  2. tar saves many files together into a single archive, and can restore individual files from the archive. It is standard practice to name your archive file with a .tar extension. Please do not name it the same as your program name. Compressed tar files are often called tarballs.
  3. Flags for tar:
    -c  – create a new archive
    -x      – extract files from archive
    -v      – verbose output
    -f     – specify archive file or device
  4. The format for using tar to archive; pay CLOSE attention to the arguments. After the flags, the next filename needs to be the DESTINATION file name (a new file is fine). This is then followed by a space separated list of source files.
    IF YOU FORGET to place the DESTINATION file name first, you will destroy your .cpp files!

    tar -cxvf    archivefile.tar   [files to add…]
    tar -cxvf    destination_file.tar  [space separated list of source files]

  5. Examples using tar to archive:
    1. Create a tar.gz file archive containing program1.cpp
      tar   -cvf   project1.tar.gz   program1.cpp  
    2. Create a tar.gz file archive containing all of the .h and .cpp files that exist in the current directory
      tar -cvf homework.tar.gz *.h *.cpp
  6. Note: Only the coded files need to be tar’d (external data files, .h files, and .cpp files). Write ups should not be included in the tar files.
  7. Always check that you actually created your archive correctly. This means that you should attempt to unpack the files in a separate directory before submitting your code to D2L. If you lose your files, it is important to contact the Computer Action Team (support@cs.pdx.edu) immediately for assistance.
  8. Unpacking (extracting) files from a tarball
    1. If you have a tarball and you want extract the files on linux, please first make sure you are in a directory that is empty (or has no files that will be destroyed by the extraction process):
      mkdir extracted_files
      cd extracted_files
    2. Transfer the tarball into the directory or copy it from another directory. Ask for assistance if needed.
    3. Extract files from project1.tar.gz into your current directory can be done all in one step using MCECS’ newest version of GNU:
      tar -xvf project1.tar.gz
    4. To unpack into a specific directory from tarball located in another directory:
      cd /directory_of_choice
      tar -xvf /full/path/to/project1.tar.gz

ZIP

    1. zip is a compression and file packaging utility for linux. It is analogous to a combination of the linux commands: tar and compress.
    2. Flags with zip:-1 -compresses faster (but larger)
      -9 -compresses better (slower but smaller!)
      -v -verbose mode
    3. Creating an archive using zip:
      zip  archive_filename  files to add…
    4. Examples using zip to archive:    
      1. Create an archive containing program #1:
        zip  project1.zip  program1.cpp 
      2. Create an archive containing all of the .h and .cpp files in the current directory:
        zip  -9  homework.zip  *.h  *.cpp               
    5. Extracting files from a zipped archive:  
      1. If you have a zipped file and you want extract the files on linux, please first make sure you are in a directory that is empty (or has no files that will be destroyed by the extraction process):
        mkdir Project1_Extracted
        cd Project1_Extracted
      2. Transfer the zip into the directory or copy it from another directory. Ask for assistance
      3. Extract files from project1.zip into your current directory:
        unzip project1.zip
      4. Extract files from project1.zip and places them into a directory called Project1_Extracted:
        unzip -d Project1_Extracted/ project1.zip

License

CS Linux & Vim Manual Copyright © by Karla Fant. All Rights Reserved.

Share This Book