Skip to content

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)

  1. Create a new repository on GitLab at code.vt.edu:

  2. in the top-left corner, click the "+" icon

  3. in the new menu that pops up, click "New project/repository"; a new page loads
  4. 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"
  5. Add the instructor and TA to your repository as a member with Developer access. In the web browser with your new repository open:

  6. in the left sidebar, hover the mouse cursor over "Manage"

  7. in the menu that pops up, click "Members"; a new page loads
  8. on the new page, click button "Invite members"
    • enter the jrudi
    • select maximum role: "Developer"
    • click the button "Invite"
  9. repeat to invite a new member:
    • enter the jraind
    • select maximum role: "Developer"
    • click the button "Invite"

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 q1 inside your repository for this exercise. The filenames of the screenshots are given below (the extensions of the files are not specified).

Laptop setup

  1. In class, you generated a pair of SSH keys on your laptop. Proof that the keys exist by showing the content of the ~/.ssh folder with the ls command. \ (terminal screenshot file 01)
  2. 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)
  3. 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 ls command. \ (terminal screenshot file 03)
  4. Inside your cloned repository folder, create an empty file named:
    hello.txt
    
    Proof the existence of the file with the ls command. \ (terminal screenshot file 04)
  5. Add the following line to the file:
    Hello, CMDA 3634!
    
    Proof that you wrote text into the file with the cat command (don't forget passing the filename to the cat command). \ (terminal screenshot file 05)
  6. Commit and push your changes. Proof this by showing all the git commands that you ran. \ (terminal screenshot file 06)

Matrix server setup

  1. SSH into Matrix. Proof you're on Matrix by showing the terminal prompt after SSH. \ (terminal screenshot file 07)
  2. 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 ~/.ssh folder with the ls command. \ (terminal screenshot file 08)
  3. 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)
  4. 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 ls command. \ (terminal screenshot file 10)
  5. Your repository must have the file hello.txt from before. Proof that the original text is in the file with the cat command. \ (terminal screenshot file 11)
  6. Open hello.txt and add the following new line:
    Hello from Matrix!
    
    Proof that both lines are in the file with the cat command. \ (terminal screenshot file 12)
  7. Commit and push the changes from Matrix. Proof this by showing all the git commands that you ran. \ (terminal screenshot file 13)
  8. 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.txt are showing up at GitLab after you clicked on the file. \ (browser screenshot file 14)

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 q2 inside your repository for this exercise. The filenames are given below (the extensions of the files are not specified).

  1. 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)
  2. 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)
  3. Open the file hello.txt. Proof the file is open by showing the editor panel (at the center) of VS Code. \ (screenshot file 03)

3. Basic command-line tools (40 points)

In this exercise, you will practice using terminal commands that make you productive:

  • wget for downloading files
  • grep for 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 q3 inside your repository for this exercise. The filenames are given below (the extensions of the files are not specified).

3.1. Create a script file

  1. Create a file named:
    commands.sh
    
  2. 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

  1. Use wget to download a public text file from the internet. Use the URL of any website or text file.
  2. Save (or rename) the downloaded file as:
    data.txt
    
  3. Add the wget command (with your chosen URL) to commands.sh. If you rename the file, add the renaming command after the wget command to commands.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:

  1. Find all lines containing the word "the".
  2. Find all lines containing the word "home".
  3. Save the results of each of the two searches above to a new file using output redirection (>).
  4. results for search "the" are in the new file the_results.txt
  5. 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:

  1. Count how many lines contain the word "the". Create one command with the | syntax that first searches with grep and then counts the lines with wc. Save the output from that pipe to a new file by using output redirection (>):
  2. results for "the" are in the new file the_count.txt
  3. results for "home" are in the new file home_count.txt
  4. Display only the first 10 lines that contain "the". Create one command with the | syntax that first searches with grep and then uses the head command. 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

  1. Commit and push the files:

  2. commands.sh

  3. the_results.txt
  4. home_results.txt
  5. the_count.txt
  6. home_count.txt
  7. the_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! 🍪