"

Lab #1: Getting Started with Linux

Linux & Vim Lab #1 – Goals and Overview

Getting Started

Get prepared to work in the CS linux environment:

    1. Prior to the lab, make sure to get a MCECS account (required); visit FAB 88
    2. During the lab we will demonstrate how to access linux from a personal computer
    3. Get to know the other students in lab and begin understanding the fundamentals of computer science. This begins with required group activities.
    4. Learn how to download putty or ssh for PCs and use terminal for Macs
    5. Experience logging in, entering a program, compiling and running
    6. Learn how to submit programming assignments to D2L
    7. More information can be obtained by visiting the cat website in their Remote Access information http://cat.pdx.edu/network/shell-and-ssh-access-2.html

Overview

  1. Everyone will need an MCECS (CS) account. This account is needed for both lab work and programming assignment work. When you login using this account you will be working on one of our linux systems. Visit FAB 88 to obtain this the first time!
    This needs to take place PRIOR to the first lab!
  2. There are two linux computer systems that we will be using this term; both use the linux operating system. These systems are available either on-campus or remotely, with internet access.
  3. LABS: The system used for labs should only be used for lab work or practicing; it should not contain files that you want to access after the term is over.
    1. CS162 labs will use cs162lab.cs.pdx.edu for all lab work
    2. CS163 labs will use cs163lab.cs.pdx.edu for all lab work.
    3. CS202 labs will use cs202lab.cs.pdx.edu for all lab work.
    4. CS299 labs will use cs299lab.cs.pdx.edu for all lab work.
    5. Your account may be accessed with your MCECS user name and password.
    6. The lab system is only available during the term in which this course is being taken. All files will be deleted immediately after the term is over.
  4. Programming Assignments: Programming assignment must be implemented on our CS linux systems using linux.cs.pdx.edu.
  5. Use your MCECS user name and password to login.
  6. We advise creating a separate directory for assignments with a separate directory for each assignment.

Logging into the MCECS Computer Systems

There are two computer systems that are used as part of our Computer Science curriculum on a regular basis. Both systems provide access to the linux operating system. They are available either on-campus or remotely, with internet access.

  1. One is used for the labs that you are signed up for:
    1. CS162 labs will use cs162lab.cs.pdx.edu for all lab work
    2. CS163 labs will use cs163lab.cs.pdx.edu for all lab work.
    3. CS202 labs will use cs202lab.cs.pdx.edu for all lab work.
    4. CS299 labs will use cs299lab.cs.pdx.edu for all lab work.
  2. All classes will use linux.cs.pdx.edu for programming assignments.

When using either account, there are some login instructions and software that may be required. You may be using ssh to login. ssh is a secure shell program that allows the computer to act as a ‘dumb terminal’ for logging in remotely. If this is the first time attempting to connect to this host, ssh may display a warning that it cannot guarantee that the computer being connected to is safe. Enter “yes” to save the key (required!).

  1. PC’s running Windows:
    1. Download a free version of ssh (secure shell) or putty. The lab computers already have this software available.
    2. Instructions can be found at:
      http://cat.pdx.edu/network/shell-and-ssh-access-2.html
    3. Double click on the application once it has finished installing
    4. Use the proper host for lab work (e.g., cs162lab.cs.pdx.edu)
    5. Use linux.cs.pdx.edu as the host for programming assignments.
  2. Linux type OS:
    1. Open up a terminal and use the ssh (Secure Shell) command
    2. Use the appropriate lab system based on your class (e.g., cs162lab.cs.pdx.edu, cs163lab.cs.pdx.edu, cs202lab.cs.pdx.edu, or cs299lab.cs.pdx.edu).
    3. To login, type:
      ssh login_name@cs162lab.cs.pdx.edu for labs and
      ssh login_name@linux.cs.pdx.edu for programming assignments.
  3. Apple Macintosh OS X:
    1. Terminal software is available as part of the Apple Utilities that allows us to open a window for remote login.
    2. Instructions can be found at:
      http://cat.pdx.edu/mac/accessing-using-ssh.html
    3. Follow these steps:
      1. Open the Finder and navigate to Applications.
      2. In Applications, navigate to Utilities.
      3. Find a program called Terminal and double click on it.
    4. Use the appropriate lab system based on your class (e.g., cs162lab.cs.pdx.edu, cs163lab.cs.pdx.edu, cs202lab.cs.pdx.edu, or cs299lab.cs.pdx.edu).
    5. To login, type:
      ssh login_name@cs162lab.cs.pdx.edu for labs and
      ssh login_name@linux.cs.pdx.edu for programming assignments.
    6. The above requires the use of the MCECS login name, because your login name on your own computer most likely differs from the one provided by our department.

Navigating to the Correct Lab Directory

Labs exercises use the following systems

  1. CS162 labs will use cs162lab.cs.pdx.edu for all lab work
  2. CS163 labs will use cs163lab.cs.pdx.edu for all lab work.
  3. CS202 labs will use cs202lab.cs.pdx.edu for all lab work.
  4. CS299 labs will use cs299lab.cs.pdx.edu for all lab work.
  5. When logging into the lab systems, directories already exist. You will want to navigate into the directory assigned to the lab while working in a particular lab session. These directories have already been pre-created.
  6. With each lab, first navigate into the correct directories:
    1. To change into the directory for your class (e.g. CS162, CS163, CS202, CS299 ) type:
      cd CS162
    2. Or, if you are in CS163 then type:
      cd CS163
    3. If you are enrolled in CS202, then type:
      cd CS202
    4. If you are enrolled in CS299, then type:
      cd CS299
    5. Next, navigate into the appropriate Lab directory:
      cd Lab1
    6. Or, the two steps can be combined:
      cd CS*/Lab1

Caution

For the labs, it is important to work in the directory assigned for the lab.

In Lab, do not make new directories.
In Lab, do not delete existing files or directories.

Work within the given structure unless explicitly directed to do so!

Working on Programming Assignments

Programming assignments should be implemented using linux.cs.pdx.edu; in fact, never implement your programming assignments on the lab system or using a different operating system.

  1. The first time:
  2. The very first time that you login to do your Computer Science programming assignments, create a directory where you will be creating programs for this course.
  3. We recommend a separate directory for each class (CS162, 163, and 202) and for each programming assignment that you will be working on.
  4. You won’t need to do this for the Lab work…just for your individual programming assignments.
  5. To make a new directory use the mkdir linux command. For example:
    mkdir CS162_Programs
  6. Once you login, navigate into the directory that contains the files that you are intending to work on. For example, to change into that directory type:
    cd CS162_Programs
  7. To make a directory for working on program #1 files type:
    mkdir Prog1
  8. Each time you login:
    1. From then on, you will need to change into that directory to actually get your work done. This will need to happen each time you login.
    2. To change into that directory to start to work type:
      cd CS*/Prog1

Compiling and Running Programs

  1. All programs should be completely implemented using the MCECS linux systems. Do not use PC editors or compilers. Do not use a remote linux system. Instead, make sure to use the MCECS linux systems at all times for lab exercises and programming assignments.
  2. All C++ programs should have a .cpp extension.
  3. An approved linux editor must be used to type in C++ code and programs. Do not use an IDE unless instructed by your teacher to do so.
    1. CS162 students may use nano, pico, vi, vim, or emacs.
    2. CS163, CS202 and CS299 students must use vi, vim or emacs.
    3. With vi or vim, use the commands to navigate rather than the arrow keys!
    4. Learn the short-cuts so that you don’t repetitively use the same key to navigate (e.g., to go down 50 lines type 50<enter> or 50j rather than using the j key 50 times!
  4. Once a program has been created, save your work and exit the editor.
  5. The next step is to compile the C++ source code file. The command to do this is:
    g++ program_name.cpp
  6. Linux is “no news is good news”. No message will be displayed if the program successfully compiles.
  7. If there are syntax errors, examine the line number of the first 2 or 3 errors and fix those before continuing. To fix the syntax errors use the linux editor again:
    vim program_name.cpp
  8. After the program successfully compiles, by default a file named a.out will appear in the current working directory.
    1. We do not advise changing the name of your executable. These are large files and should not be kept around. Each time you need to run a particular program – just quickly recompile with g++ and then it can be run with ./a.out
    2. To run your program type:

./a.out

Submitting Work

Lab work and programming assignments are submitted using different techniques. Labs can be directly submitted on our lab system. But, programming assignments must be transferred from linux and ultimately uploaded to D2L. This process requires some practice to prepare and should be followed carefully!

Submitting Labs

  1. At the end of each hour and 50 minute lab session, make sure to always submit your work. This should be done whether you have completed all the exercises or not. Submitting lab work can be more than once and all submissions are saved.
  2. Lab work is submitted by typing ./submit in the corresponding lab directory:
    1. This will only work if lab programming is performed in the assigned directory
    2. Please submit your lab work at the end of a lab session even if the work has not been completed.
    3. Lab work can be submitted more than once (e.g., if a makeup lab is attended in order to finish a particular lab, you would type ./submit again at the end of the makeup lab).

Submitting Programming Assignments

  1. Programming assignments must be uploaded to D2L to submit, unless instructed otherwise by your professor. Files may not be directly uploaded to D2L from linux. This requires that we first securely transfer the files from linux to our PC, MAC or linux system before we can upload it. This process is different depending on your platform and will take special care:
    1. When submitting a file to D2L, you will first need to transfer your .cpp file to your computer (from linux).
    2. To do this, you will need to use a secure file transfer program.
    3. There are many choices! Our Computer Action Team (CAT) provides this information:
      http://cat.pdx.edu/network/ftp-access.html

Transferring Files

The following outlines the process for transferring files from our linux system to other platforms. Only upload source files to D2L (for example, .cpp files) and not executable files (a.out).

  1. Using Windows or Mac platforms:
    1. Cyberduck is a free program that allows files to be moved using drag and drop techniques
    2. Once this software has been downloaded and installed, make sure you have selected “Secure” file transfer (SFTP).
    3. Then, you can drag and drop the file from linux to your desktop (or desired location)
    4. This file can then be uploaded to D2L using the dropbox tool. Make sure when using D2L to hit the submit button. Files uploaded but not “submitted” will not be saved by D2L!!!
    5. Double check D2L that your file exists there. Never assume!!
    6. If you are using a school computer, it will also be important to remove the file that is transferred before you leave. Otherwise, your software will stay on the school’s hard drive for the next student to access!
      1. Make sure the file is deleted off of the school’s desktop or hard drive before leaving the lab.
      2. You don’t want to leave your code available for the next student to access!
      3. Best to use a flash drive and avoid risking this situation happening!
  2. Linux to Linux Transfers:

On linux, there are commands that will allow us to copy a file from one linux system to another. This can be done using the scp command. But a safer way is to use filezilla. Ask the lab assistants to demonstrate this for you in lab!

License

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

Share This Book