Overview of Lab

After this lab you should be able to:

Back to Schedule

Exercise

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?

  • How do you get a "Terminal"?tooltip

  • How do you log out?

  • What happens when you put something on the "Desktop" and then click on the different boxes in the bottom right hand side


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

We will leave the explanation of compiling files until a later lab. 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++ -o hello hello.cpp
  3. You can now run the code:
    • ./hello

Compiling a Nontrivial File

Let's repeat the process with a file based on recent material in Dr. Hamilton's lecture.

  1. First, get the file to be compiled:
    • cp ~anima/public_html/115/Notes/02-Arrays/Answers-02-1.cpp main1.cpp
  2. Look at the program you are compiling (you should hit the ENTER key to advance through the file)
    • more main1.cpp
  3. Then, compile:
    • g++ -o main1 main1.cpp
  4. You can now run the code:
    • ./main1

Explore:

  • 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 infront of one of the "a0" machines listed from the above command

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

Right click on the desktop and select: "Open Terminal"
What comes after the -o?