Due:

See Gradescope

Starter code:

Sign up to the course’s pawtograder https://pawtograder.khoury.northeastern.edu/course/647. Then, look in your github.com account.

Submission:

Submit the contents of your repository via Gradescope. See Deliverables below for what to submit.

This is an individual assignment.

The purpose of our first assignment is to make sure everyone is able to set up a working environment and to familiarize yourself with the terminal, shell, and the C compiler, as well as the process of submitting deliverables. It might be worthwhile to take a look at the Deliverables at the end of this assignment and then work through the tasks. We will also reserve some time in class to help walk you through the process and fix issues that might arise.

For this class, we need everyone to have a working Linux environment to work in. There are multiple ways to achieve this goal, but we want to make sure you are at least able to use Github Codespaces.

A Note on Windows

If you are working on a Windows machine and you want to work standalone on your computer, you mush set up Windows Subsystem for Linux 2 (WSL2). This will give you access to a Linux environment directly on your computer. Read more about WSL2. The rest of the description here assumes you have a working Unix-like terminal.

Part 1 - Sign up for GitHub Student Developer Pack

Everybody in this class should have an Intel x86-64 Linux environment to develop and test their code. You might already have a Linux installation on your machine or a VM. However, to make sure we all have access to a reasonably similar environment, we will use Github Codespaces. Codespaces is free for any Github user to use, but, alas, the free version has a limited number of CPU hours per month (60 for a 2-core VM) available. Applying for the Student Developer Pack allows you to extend the computation time available to you to 90 hours per month for a 2-core VM. It also comes with additional perks.

  1. If you do not already have one, create a Github.com account.

  2. Sign up for the Student Developer Pack. Note, unless your NUID card contains an expiration date, you might need to upload a document, e.g., a unofficial transcript, course schedule, or another document, that contains the end date for your studies.

Part 2 - Pawtograder sign up and start Codespaces

  1. If you have not already, sign up to the Pawtograder for this course at: https://pawtograder.khoury.northeastern.edu/course/647 using the Northeastern Login option. Pawtograder will create your repository, fa26-a1-setting_up-[your-github-username], when the assignment is released.

    We are only using pawtograder for repository creation. All submissions must be to Gradescope.

  2. Open Codespaces from within the repository. Codespaces is an option under the green Code button (see green arrow in the figure below).

  3. You will be provided with a web-based VS Code interface to edit your files. Stop!
    For this assignment, resist the urge to use the pretty VS Code editor.
    Instead, focus on the terminal below the editor window and find the “Maximize Panel Size” button to have the terminal take over the whole view. Complete the rest of this assignment inside this terminal. Alternatively, you should be able to use the Terminal on macOS or the Ubuntu terminal provided by WSL on Windows.

Part 3 - (At least) 17 Commands

Run the first 17 commands. Skim through each command’s manpage. For Assignment 1, we will ask you to copy and paste the console history of running some of these commands.

  1. ls - lists the files and folders in the current directory.
  2. pwd - Echos (i.e. prints) the current directory you are in to the terminal
  3. mkdir - Create a new directory
  4. rmdir - Removes an empty directory
  5. cd - Change directory
  6. mv - Allows you to move a file elsewhere (sometimes I use this to rename a file)
  7. cp - Copies a file
  8. touch - Typically I use to create a new empty file that does not exist.
  9. man - Manual pages
  10. ps - Shows which processes are running
  11. echo - Prints out a line of text.
  12. whoami - Prints which user you are logged in as.
  13. sort - Sorts information
  14. cat - Concatenates files and prints them to standard output
  15. nl - Outputs a file with number of lines
  16. cut - Remove sections from each file
  17. grep - Prints lines that match a pattern. This is a very powerful serach command.
  18. Other interesting commands/programs include: cut, sed, awk, locate, clear

Note from instructor: We included urls to the manpages above, but it will almost always be faster for you to use the man pages within your terminal.

Task

Meaningfully experiment with and run the first 17 of the above commands. See the first deliverable for what to submit. “Meaningfully” means that you do not just type the command names one after the other, but provide a sensible use case. For example, show a man page using man. Or use sort to sort the lines of an actual file. Use cp to copy an actual file. The idea is that you explore and get a basic familiarity with the commands from the above list.

Here are some other nice things to know with the terminal.

  • Pressing the up-arrow and down-arrow keys iterates through your command history (There is also a commmand called history you can checkout).
  • Pressing <tab> autocompletes if it finds a program, command, or file path.
    • Start typing mkdi then hit tab
    • tab can also auto-complete filenames and filepaths, which can be especially helpful!
  • Pressing <Ctrl>+C sends a signal to the terminal to terminate a program if it gets stuck.
    • Type: grep . and press Enter to run it. Then press Ctrl+C to terminate.
  • Pressing <Ctrl>+Z sends a signal to the terminal to suspend a program and give you back control.
    • You can play with this command by typing in sleep 10 (which puts the terminal to sleep) for 10 seconds, and see how you can terminate this program.
    • Bring back the suspended program by using the command fg.
  • Practice getting help by typing man grep into the terminal. Press q to quit a manual page.

A bit of precision

Calling each of these ‘commands’ (i.e. ls, sort, cat, etc.) is not really correct. Each of these is itself a program (typically implemented in C or some other language).

As an example, here is the source code for ls: https://github.com/coreutils/coreutils/tree/master/src/ls.c. Each of these commands is part of the coreutils package in Unix. If you look through the source tree, you will additionally find many other programs (i.e., the terminal commands in your shell) here: https://github.com/coreutils/coreutils/tree/master/src.

Part 4 - Get to know with an editor and the C compiler

Compile the program hello.c using gcc to get an executable named hello (Hint: look for the option -o in the gcc manual). Make sure it runs and prints what you expect.

Hint 1: For many commands/programs, you can supply a file to work on simply by adding the filename after the command name, along with any options. For example, to compile hello.c into an executable called hello (instead of the default a.out), we can use:

gcc -o hello hello.c

Hint 2: To run a program in the current directory, prefix filename with ./, i.e., ./hello. ./ specifies that the file hello is in the current directory.

Task

Take a look at Deliverables 2 and 3 for what to submit.

  1. Now open your chosen terminal editor (nano, Vim, Emacs, joe, …) and modify hello.c such that it prints ONLY: your first name followed by a newline and your email address followed by a newline. Recompile the program. Confirm it runs and the output is correct. Commit and push the file to your Github repository.

  2. Make the program print your name and email address 20 times using a for loop. (Hint: Take a look at the first few sections of the Learn C tutorial.) Recompile, run, and confirm the output is correct. Commit and push the file to your Github repository. At this point, take a screenshot of the terminal with the editor as requested in deliverable 3.

More information on text editors

You are not required to use the same terminal editor I use (I’m an Emacs user), but you should become comfortable using at least one terminal editor in this course. We recommend either VIM or Emacs, both powerful highly customizable editors with huge user bases. In practice, you should have a basic knowledge of VIM, since some version of it is installed by default on virtually any Unix/Unix-like system.

Deliverables

  1. Copy and Paste the output from the command-line interface of you running the 17 terminal commands from Part 3 into a file called output.txt (no capitalization, exactly as named.)
    • Include the command line you used to run the command.
    • Do not include any “command not found” results.
    • In Codespaces, you should be able to use your mouse to select the desired text and press the keys Ctrl (on Windows) or Command (on macOS) and C (simultaneously) to copy the text to the clipboard. Then open the file output.txt in an editor (e.g., nano output.txt), paste the text ( Ctrl/Command + V) and save the file.
    • Make sure to ‘add/commit/push’ this file to the repo in your directory.
  2. Modify the file called hello.c in your repository as instructed in Part 4.
    • Make sure to ‘add/commit/push’ this file to the repo in your directory after each parts of the task. There should be at least 2 commits for this task in your repo.
    • DO NOT add or commit the executable hello. If you did, remove it in an additional commit.
  3. Take a screenshot of a terminal running a command line text editor (such as Nano, Vim, or Emacs) with hello.c after you have made it print your name and e-mail 20 times.
    • Save the screenshot as editor.png or editor.jpg.
    • Make sure to ‘add/commit/push’ this file to the repo in your directory.
  4. Create a screenshot of your Github repository’s history page (That is, “Commits”) after completing the above steps and save it as repo.png or repo.jpg.
    • Make sure to ‘add/commit/push’ this file to the repo in your directory.

Finally, go to Gradescope and submit a ZIP of your repository. The easiest way to do that is to go on Github and use the “Download ZIP” link under “Code” (see the figure below). You may also connect your Github account to Gradescope and submit directly by pulling from your Github repository. Let us know if you have trouble with any of the steps.

Code button and Downloading a ZIP from Github