Overview of Lab

After this lab you should be able to:

Back to Schedule


Quick Links:


  • Linux
  • "Unix" Commands
  • Editing
  • Compiling
  • "Unix" @ Home
  • Transferring files @ Home

Explore Linux Menus and Desktops

Log on using your computer science username and password. Take a few minutes to familiarize yourself with the Linux GUI (Graphical User Interface). A few suggestions to guide your exploration are:

  • What options are available when you right click on the desktop?
  • What options are available under each of the menus?

  • Can you drag applications from the menu to the desktop?

  • What happens when you move the mouse to the upper, left-hand corner? tooltip

  • How do you get a "Terminal"?tooltip

  • How do you log out?tooltip

Explore Commands

Now that you are familiar with the menus and the things that make Linux "pretty". We can explore the roots of Unix/Linux--the commands that you type.

Once you have a terminal, you can explore the following commands. You can use ls or pwd after the command to help you discover what the comands do:

  • ls
  • mkdir cs115
  • pwd
  • cd cs115
  • passwd
  • touch newfile

Commands to Work with a File Called newfile

  • cp newfile newfile2
  • mv newfile newfile3
  • rm newfile2

Commands for Viewing a File

  • cat /etc/passwd
  • more /etc/passwd
  • less /etc/passwd

With more and less explore the following:

  • What happens when you press the space bar?
  • What happens when you press enter?
  • What happens when you type the following: /nova/?
  • What happens when you press the letter q?
  • Why would you want to use more or less instead of cat?

Less is actually more!

Information about Commands

Unix folks have a good sense of humour. There are also "man" pages (an abrieviation for "manual" pages). Honestly, they take some getting used to to read, but they are very thorough. Try:

  • man rmdir
  • try some of the "what happens when..." explorations from above

Printing at Home and in the Lab

From a Windows machine use: TeraPrint file
From a machine in CL115 use: lpr -Pcl115 file

Unix References

Why learn these commands rather than using the GUI?
  1. You can put these commands into a script and run them. It is like learning a language in itself. If you are interested, look up "shell script" on the internet.

  2. In various situations, you may only have a command line to work with. Try the key sequence Alt Ctrl F2. To get out use "exit"

  3. If you are working from home on Unix/Linux you will be typing commands rather than accessing Linux menus

Remember, you always feel most comfortable with the things that you are used to. How can you feel more comfortable with these commands? Practice! Practice! Practice!

Text Editors

There are a variety of text editors that you can use on Unix systems. We recommend using one of these three if you are working at home:

Your lab instrutor will specify your Professor's choice for the current semester.

If you are using emacs, please use the following command to copy a configuration file:

cp /net/data/ftp/pub/class/115/ftp/config/.emacs .emacs  

Can you see this file using an ls? Try ls -a

In CS115, Dr. Hamilton will be asking you to use a newer version the C++ language. To do that, you will use newg++ for compiling. Behind the scenes, newg++ is an alias for a more specific call: g++ -std=c++11 (indicating the c++11 language standard).

If you have your own Linux machine, you can set up the alias using:

alias newg++ g++ -std=c++11

We will provide more details of compiling files in a later lab. For now, let's learn by example:

Single Files

Compiling a Single File

You might want to perform these in your CS115 directory. You can use the ls command after step 1 and 2 to see what files are being added to your directory.

  1. First, get the file to be compiled:
    • cp /net/data/ftp/pub/class/115/ftp/cpp/hello.cpp hello.cpp
  2. Then, compile:
    • g++ hello.cpp -o hello
    • newg++ hello.cpp -o hello
  3. You can now run the code:
    • ./hello

Compiling Code with Errors

Let's work with partially completed code for this week's exercise.

  1. First, get the file to be compiled:
    • cp /net/data/ftp/pub/class/115/lab1Grocery.cpp .
  2. Then, compile:
    • g++ lab1Grocery.cpp -o output
  3. You will see several error messages. Focus on fixing the top problem first.
  4. Look for the number between the colon (":") character that is the line number where the error appears
  5. Fix the code, save, and compile until no messages appear
  6. You can now run the code
    • ./output


  • Try playing around with the order of the arguments after the g++ in Step 2
    • If something happens to your hello.cpp code, don't worry--you can always get it again (from Step 1)

  • Try leaving out the -o hello in Step 2. What is produced? Can you use that to run the code?

  • Try replacing hello with test. Try to run test with or without the ./ in front. Does hello work that way too? If you are curious about why, try man test
Multiple Files

Compiling Multiple Files

You might want to perform these in your CS115 directory. You can use the ls command after step 1, 2, and 3 to see what files are being added to your directory.

  1. First, get the three files to be compiled:
    • cp /net/data/ftp/pub/class/170/ftp/cpp/SeparateCompile/main.cpp .
    • cp /net/data/ftp/pub/class/170/ftp/cpp/SeparateCompile/myFunction.cpp .
    • cp /net/data/ftp/pub/class/170/ftp/cpp/SeparateCompile/myFunction.h .

  2. Then, compile the two .cpp files:
    • g++ -c main.cpp
    • g++ -c myFunction.cpp

    • What two files are created? These are refered to as object files and contain the machine code

  3. Now, the two object files need to be "linked" or combined together into the "executable" (in other words, the file that will be run)
    • g++ main.o myFunction.o -o main

  4. You can now run the code. What will you type?tooltip

Work on Hercules/Linux Using PuTTY

If you want to work at home on the labs, you can install PuTTY onto your home computer:

You will now be able to work with Unix/Linux Commands at home. The catch is that Hercules is Unix and some labs have been designed especially for Linux.

To access the Linux machines (from Hercules):

  • try the command: cs_clients CL115

  • try ssh in front of one of the "a0" machines listed from the above command. For example, try the command: ssh a049856

Transferring Files Between Your Home PC and Hercules/Linux

If you want to work at home and send files to Hercules, you can use WinSCP:

  • Click on this link to download WinSCP from the: UR Configured Software Suite

  • Access WinSCP using the "Start" menu. Look in the URCOMM folder

  • Connect to Hercules

  • Pay attention to the blue path descriptions to guide you on where you are transferring to and from

For additional help with WinSCP, you can see the CS100 notes on the WinSCP Transfer Program

From the main menu, choose "Applications" > "Favorites"
What comes after the -o?
There is a "hot corner" that changes the desktop and shows:
  • A taskbar (on the left)
  • Your active applications (in the middle)
  • A search bar (upper middle)
  • Other desktops that you can use (on the right)
  1. Click on the shutdown icon in the upper right corner.
  2. From the menu, click on the twirl down arrow beside your user id.
  3. Select "Log Out"