Exercise 1¶
What is this exercise about¶
You will practice:
- using the terminal
- using SSH keys
- connecting to remote systems
- working with Git and GitLab
- editing files from the command line
- using basic command-line tools
Please use the course materials, including sessions and the wiki, to help you complete this exercise.
General Instructions¶
All submitted work must be stored in your GitLab repository. Below it will be explained how to do that. For the repository it is important that:
- one exercise = one GitLab repository → each exercise gets its own GitLab repository
- your repository must be private
- your repository must be named exactly as specified (in the setup below); do not change the name or the upper-case/lower-case letters
- create commits frequently, at least one commit per question
- push your work frequently (this also is your backup if your laptop breaks)
- your repository must be up-to-date before the deadline
- you must double-check your repository in the web browser to make sure all your work is uploaded to the code.vt.edu server
- you must provide screenshots as proof when they are requested; screenshots are also committed to the repository
⚠️ The screenshots must be taken by you on your laptop! Not following this is an Honor Code violation.
0. Setup: Git and GitLab (15 points)¶
-
Create a new repository on GitLab at code.vt.edu:
-
in the top-left corner, click the "+" icon
- in the new menu that pops up, click "New project/repository"; a new page loads
-
in the new page, click the "Create black project" button; a new page loads:
- enter the "Project name":
cmda3634-ex1 - in the drop-down field "Pick a group or namespace", select your username
- the "Project slug" field should populate automatically after entering a project name; do not change the slug
- for the "Visibility level", select "private" (very important!)
- for the "Project configuration", select only "Initialize repository with README"
- enter the "Project name":
-
Add the instructor and TA to your repository as a member with Developer access. In the web browser with your new repository open:
-
in the left sidebar, hover the mouse cursor over "Manage"
- in the menu that pops up, click "Members"; a new page loads
- on the new page, click button "Invite members"
- enter the
jrudi - select maximum role: "Developer"
- click the button "Invite"
- enter the
- repeat to invite a new member:
- enter the
jraind - select maximum role: "Developer"
- click the button "Invite"
- enter the
1. SSH Keys and Git Usage (30 points)¶
Each item in the list below requires a screenshot as proof of completion. The screenshot must be of your entire terminal window; and sometimes of your entire web browser window.
You will submit the screenshot files in a folder named
q1inside your repository for this exercise. The filenames of the screenshots are given below (the extensions of the files are not specified).
Laptop setup¶
- In class, you generated a pair of SSH keys on your laptop. Proof that the keys exist
by showing the content of the
~/.sshfolder with thelscommand. \ (terminal screenshot file01) - In class, we have added the public SSH key to your GitLab account. Proof that key is
added by showing the "SSH Keys" page of your GitLab "Preferences" at
code.vt.edu. \
(browser screenshot file
02) - Clone the repository that you created for this exercise in the
setup. You must clone using the URL provided by
"Clone with SSH". Proof that you cloned by showing the clone command and the new
folder the cloning created with the
lscommand. \ (terminal screenshot file03) - Inside your cloned repository folder, create an empty file named:
Proof the existence of the file with the
hello.txtlscommand. \ (terminal screenshot file04) - Add the following line to the file:
Proof that you wrote text into the file with the
Hello, CMDA 3634!catcommand (don't forget passing the filename to thecatcommand). \ (terminal screenshot file05) - Commit and push your changes. Proof this by showing all the git commands that you
ran. \
(terminal screenshot file
06)
Matrix server setup¶
- SSH into Matrix. Proof you're on Matrix by showing the terminal prompt after SSH. \
(terminal screenshot file
07) - Just like on your laptop, you also need SSH keys on the Matrix server. Generate an
SSH key pair on Matrix. Proof that the keys exist by showing the content of the
~/.sshfolder with thelscommand. \ (terminal screenshot file08) - Just like for your laptop, you also need to add the public SSH key to your GitLab
account. Add the Matrix public key to GitLab. Proof that key is added by showing the
"SSH Keys" page of your Preferences at code.vt.edu. \
(browser screenshot file
09) - Clone your repository – now in your home directory on Matrix. Proof that you
cloned by showing the clone command and the new folder the cloning created with the
lscommand. \ (terminal screenshot file10) - Your repository must have the file
hello.txtfrom before. Proof that the original text is in the file with thecatcommand. \ (terminal screenshot file11) - Open
hello.txtand add the following new line:Proof that both lines are in the file with theHello from Matrix!catcommand. \ (terminal screenshot file12) - Commit and push the changes from Matrix. Proof this by showing all the git commands
that you ran. \
(terminal screenshot file
13) - Double-check that the file is up-to-date in your repository in the web browser at
code.vt.edu. Proof that both lines in
hello.txtare showing up at GitLab after you clicked on the file. \ (browser screenshot file14)
2. VS Code remote access (15 points)¶
Each item in the list below requires a screenshot as proof of completion. The screenshot must be of your entire VS Code window.
You will submit the screenshot files in a folder named
q2inside your repository for this exercise. The filenames are given below (the extensions of the files are not specified).
- Connect to Matrix using SSH from VS Code. Proof that you are connected by showing the
terminal panel (at the bottom) of VS Code. \
(screenshot file
01) - Open the folder of the clone of your repository for this exercise. It must exist if
you did all the steps in the previous problem. Proof that you opened the repository
folder by showing the file explorer panel (on the right side) of VS Code. \
(screenshot file
02) - Open the file
hello.txt. Proof the file is open by showing the editor panel (at the center) of VS Code. \ (screenshot file03)
3. Basic command-line tools (40 points)¶
In this exercise, you will practice using terminal commands that make you productive:
wgetfor downloading filesgrepfor searching text- output redirection (
>and>>) for saving output of commands into files - pipes (
|) for chaining multiple commands together
You will learn how to retrieve, process, and analyze data using the terminal.
All of these steps are done on Matrix and inside the cloned folder of the repository for this exercise.
You will submit the screenshot files of your entire terminal in a folder named
q3inside your repository for this exercise. The filenames are given below (the extensions of the files are not specified).
3.1. Create a script file¶
- Create a file named:
commands.sh - Enable execution for this file by running this command:
chmod +x commands.sh
Proof that you created the script (with execution setting) by listing the files with the
ls -l command (don't forget the -l, a space is between ls and -l). \
(screenshot 01)
All commands for this exercise must be written inside this file.
3.2. Downloading data¶
- Use
wgetto download a public text file from the internet. Use the URL of any website or text file. - Save (or rename) the downloaded file as:
data.txt - Add the
wgetcommand (with your chosen URL) tocommands.sh. If you rename the file, add the renaming command after thewgetcommand tocommands.sh.
Tip: Look up how to use the wget command. Make sure the URL works (in your web
browser) and the file downloads correctly.
Proof that you added the command to the script by showing its contents with the cat
command. \
(screenshot 02)
3.3. Searching in text files¶
Using the grep command, write additional lines in commands.sh:
- Find all lines containing the word "the".
- Find all lines containing the word "home".
- Save the results of each of the two searches above to a new file using output
redirection (
>). - results for search "the" are in the new file
the_results.txt - results for search "home" are in the new file
home_results.txt
Tip: Look up how to use the grep command to search for words inside a file.
Proof that you have the two result files by using the ls command. \
(screenshot 03)
3.4. Using pipes¶
Use pipes (|) for chaining multiple commands together, write additional lines in
commands.sh:
- Count how many lines contain the word "the". Create one command with the
|syntax that first searches withgrepand then counts the lines withwc. Save the output from that pipe to a new file by using output redirection (>): - results for "the" are in the new file
the_count.txt - results for "home" are in the new file
home_count.txt - Display only the first 10 lines that contain "the". Create one command with the
|syntax that first searches withgrepand then uses theheadcommand. Save the output to:the_first10.txt
Proof that you have three new result files by using the ls command. \
(screenshot 04)
Hints: Using pipes and redirection¶
cat data.txt | grep "the" > test_results.txt # writes results into new file
cat data.txt | grep "the" | wc -l # prints count, no new file
cat data.txt | grep "the" | head # prints first 10 lines, no new file
3.5. Commit and push¶
-
Commit and push the files:
-
commands.sh the_results.txthome_results.txtthe_count.txthome_count.txtthe_first10.txt
Proof this by showing all the git commands that you ran. \
(terminal screenshot file 05)
2. Do not commit the data.txt file!
3. Double-check that all files are up-to-date in your repository in the web browser at
code.vt.edu. Proof that by showing commands.sh in your web
browser at GitLab after you clicked on the file. \
(browser screenshot file 06)
Submission¶
On Canvas¶
In your web browser, go to the page of your GitLab repository for this exercise. Then copy the URL from the address bar of your web browser. Submit this URL to Canvas.
Commit and push all the screenshot files to your repository of this exercise.
Congrats! You're done! 🍪