Main navigation | Main content
February 3, 2024
In today’s lab, we’ll practice some basic skills for managing files and giving commands in a terminal on your VM, following a tutorial that the Ubuntu project publishes. But we’ll add on to the end of the tutorial by having you package your work into a file to submit, which will be a relevant skill for future labs too. You can work on this lab activity alone, or in a group of up to three students. Our recommended environment for doing the lab is one of the lab workstations, though VOLE, or anywhere else where you can have both a web browser and a connection to your VM could also work. After you have logged into a lab workstation, open a web browser in which you follow this link to the Ubuntu Command Line Tutorial, and open an SSH connection to your VM, like we did last week. If you set everything up the way we recommended last week, you should be able to SSH to the student
account on your VM without having to type an additional password. In the terminal with an SSH connection to your VM, you should be able to follow all of the steps of the tutorial that have you work with a directory named /tmp/tutorial
, but don’t delete the files when the instructions at the end of the tutorial tell you to: instead you are going to submit them. The final section of the tutorial that has you install the tree
program is the one part that you wouldn’t be able to complete on a lab workstation, because students (and faculty) aren’t allowed to run sudo
there.
Once you’ve finished with the creating all the files and directories in the tutorial, you’ll package them up into a single compressed file to submit. A generic name for this kind of combined file is an archive. If you’ve used Zip files in Windows, they are another kind of archive file, but we’ll use a format more common on Unix named tar
.
The standard way to turn a directory of files into a tar archive is by creating the archive from the parent directory of the one you want to save, so that all the files are created in a new subdirectory when they are unpacked. So start by changing directories to /tmp
, and then run the command shown below:
student@csel-xsme-s25-csci4271-NNN:~$ cd /tmp
student@csel-xsme-s25-csci4271-NNN:/tmp$ tar czf tutorial.tar.gz tutorial
student@csel-xsme-s25-csci4271-NNN:/tmp$ ls
You should now see a file named tutorial.tar.gz
in the directory /tmp
. The command tar
is a Unix command that was originally used for backing up files and directories on magnetic tapes; the acronym comes from tape archive. The options czf
(which are unusual in not requiring -
) are for creating an archive, compressing the archive with gzip and storing the archive in a file named by the following argument, since your VM don’t have a tape drive anymore. You will pretty much always use the f
argument and a file name with tar
. In the c
creation mode, the second argument, tutorial.tar.gz
is the file to create, and the arguments after that are the directories and or files copy into the archive. You can list the contents of the archive using the t
mode instead of c
:
Compression isn’t built into the tar
archive format, but it is common for archive files to also be compressed. The two-level file extension .tar.gz
indicates that files and/or directories were archived with tar
, and then the resulting tar-format archive was compressed with the program gzip
, which compresses a single file into a more compact version. When .tar.gz
files need to be stored on systems that only allow a single three-character file extension, you will see it shortened to .tgz
. The other most common operation is to extract the contents of an archive using the x
option. You don’t need to that today, though you could try it (e.g., in a different directory) if you’re curious.
Next, we’ll use scp
to copy the tutorial.tar.gz
archive from your VM to your CSELabs account. Get yourself a terminal on to type commands for your workstation, such as by logging out of your VM by typing exit
at the prompt, or by opening a second terminal window. In your CSELabs account, cd
to your ~/Desktop
directory. Then use scp
like in the last lab:
(Remember to replace NNN
with your VM number, and don’t miss that period argument at the end of the line.)
Now you are ready to upload the file tutorial.tar.gz
to Gradescope. Go to the Lab 2 assignment in Gradescope (it’s also linked from Canvas), and click in the “Drag & Drop” box to select the tutorial.tar.gz
file from your desktop and upload it. Make sure you include all of your group members in the submission if you worked in a group!
Once you’ve submitted the file, the autograder will test the archive to make sure the proper files and directories are present, and update your score accordingly within a few minutes. When you (and the autograder) are satisfied you have completed the lab, you can remove the tutorial
directory and its contents per the tutorial instructions:
Congratulations on finishing Lab 2!