CS110-130 Lab: Introduction to Linux Operating System

Highlights of this lab:

This lab will guide you through the fundamentals that you need to perform your lab and class assignments.

Lab Exercise:


Click the little computer above for a detailed description.

If you need help during the week, you are welcome to go to CL119 during Office Hours posted for lab instructors.



Computer Accounts

Hyperion Account

Every U of R student recieves an Hyperion account and can keep that account for as long as they are a student at the University. You need a Hyperion account to:

If you have logged on to a computer on campus before, you can skip the Web Services for Students described here and proceed to the description of Hercules Accounts.

To get your Hyperion Account setup or to change your Hyperion password, click on this Link to Web Services for Students. You will see a vertical menu bar on the left side of the screen from which you can select one of:

  1. Find Username and Password, or
  2. Change Password, or
  3. Lab Printing->ComputerLabs. (See note on Enable Printing below.)

Check your email regularly. Your class and lab instructor send email regarding class and lab related information. For example, the midterm date, lecture notes, and lab tests reminders. Click check email

In order to print in the labs, you must Enable Printing. You only need to do this once to use any University lab printer such as the 'cl1354' printer. Once you have enabled printing, you can use any lab printer, including the ones in the library and the Education Building labs. Remember, you need to select the Lab Printing->ComputerLabs menu option in the left side of the Link to Web Services for Students web page to enable printing.

Note to lab instructors: Use this link if you need to reset a student's password: Reset

Hercules Account

These accounts are given out only to students taking Computer Science classes. A Hercules account is NOT the same thing as a Hyperion account even though the usernames are generally the same. They are separate accounts on separate computers and therefore have separate passwords. You need a Hercules account in CS110 for two reasons:
  1. To access the computers in CL135.4.
  2. To store your C++ programs.
  3. You can also use your Hercules account to compile your C++ programs from your home PC or from other labs on campus.

Linux Operating Systems in CL135.4

What is Linux?

Linux is a free Unix-type operating system originally created by Linus Torvalds with the assistance of developers around the world. It is an alternative to other operating systems, like Windows and Mac OS. Linux is not a program like a word processor and or a set of programs like an office suite; it is an Operating System.

1. Login

To access the Linux system, you must have a username and a password. The Computer Science department provides you with a Hercules UNIX account. Hercules is just the name of the Computer Science computer. If you don't have a Hercules account, contact your lab instructor in the lab or in CL119 during Office Hours.

When you login to Linux, you will see your home folder on the desktop. This is where you store your files, such as your C++ programs.

Once you log in, you will see something similar to the following image.



2. Web Browsers in Linux

There are many Web browsers available for Linux. The one we are going to use is Mozilla. It can be found on the bottom of the Menu bar. To start, simply click on the icon. The default Webpage should be the Computer Science Department Homepage. To set the default webpage to CS110 or CS130 online material, go Edit —> Preferences, then type

http://www.cs.uregina.ca/Links/class-info/110-130/     in the Location field box.

Make sure there are no mistakes, then press OK. Now when you click on the Home button, you will be taken to the CS110-130 material.

3. Open Terminal

Terminal is where you
  1. Write, compile and run your C++ programs.
  2. Capture your program output.
  3. Print your C++ programs.
When you use the Terminal, the operations are performed by Linux, but your files are stored on Hercules. If you want to perform the operations directly on Hercules, use the ssh Hercules command described in the next section of these notes.

To setup a terminal icon on the menubar, you need to click on the RedHat icon, choose System Tools ---> Terminal , then drag the Terminal icon to the bottom menu bar. .

To use Terminal, just click on the Terminal icon.

4. Logout from Linux when you leave

When you are done, always remember to logout, click on the redhat icon on the lefthand corner --> Log out, then click OK.

Manipulating Files

Unix Commands

You need to learn a few basic Unix commands in order to manipulate your files and control your working environment. Linux is a Unix type operating system, so generally the same commands will work on both systems.
Be sure to look in the following list for the cp ls and script commands. List of Unix commands

For more information refer to: UNIX Tutorial for Beginners

Another very important command is:
 ssh hercules
This allows you to work directly on Hercules, rather that working on a Linux machine and using the Hercules disk space. This is important if you want to access Hercules at home or in other labs on campus. When you enter the ssh hercules you are logging on to that computer and will have to enter your password again. You will see a different prompt on your Terminal when you are connected.

Copying files

This semester you will need to obtain C++ sample programs for your labs and class. There are three methods you can use to copy these files to your Hercules account.
  1. The Unix cp command.
    You need to know the path i.e. the location of the file to be copied from the CS Department's server to use this command. We will always give you the complete path. For example the path to the file hello.cpp is: /net/data/ftp/pub/class/110-130/ftp/cpp so to copy the file, you would use this cp command:
      cp  /net/data/ftp/pub/class/110-130/ftp/cpp/hello.cpp  hello.cpp
     
  2. Use the mouse to copy and paste the contents of the file.
    This works if the file is displayed on a web page such as in this link to hello.cpp. hello.cpp When you have the program displayed you can "copy" and "paste" it into the edit program you are using. Your lab instructor will demonstrate this process when explaining how to use the editor to you.

  3. Use the FTP program to perform the copy. Follow the instructions in this How to use FTP link to download the sample program: hello.cpp.

Editing Files

To write your C++ programs, you need to use a text editor, because we are not in MicroSoft Windows, we can't use Word, or Notepad. One text editor in Linux is called pico.

The Pico Editor is a user-friendly text editor on many LINUX and UNIX computers. It can be used for creating or editing files. The most common commands are listed at the bottom of the pico screen.

To open a file in the pico text editor type:

pico filename

For example, if you have the hello.cpp program in your account, type the following command:

pico hello.cpp

Pico text editor screen with hello.cpp file displaying:


In pico, you can move up, down, left or right using the arrows on your keyboard. You cannot use your mouse!

To edit, you can backspace over text and then enter new text. You can also delete an entire row of text at once time using Ctrl k.

To exit from pico, Ctrl^X will do.

Creating a New File:
To create a new file using the pico editor, type at the command prompt:

pico newfilename.cpp
A blank pico editor session will display. Add C++ code to create a new program. When you save the file, it will be given the filename that you entered in the command above.

Compiling and Printing your C++ Programs

Compiling your C++ program.

The command to compile your C++ program on Linux is:

g++ program_name 
For example,
g++ hello.cpp -o hello
To run the program, type
hello
If you have entered ssh Hercules to work directly on Hercules, the compile and run commands are similar. Using the hello.cpp example again, here are the commands to compile and run directly on Hercules in CL135.4, or from home or from another computer on campus.
CC hello.cpp -o hello
hello

Print from Linux in CL135.4

The command to print files on Linux in ClassRoom 135.4 is

lpr -Pcl1354 filename
For example,
lpr -Pcl1354 hello.cpp
In the next lab, you will see how to print from other labs on campus and at home.

Back to Highlights


Lab Exercise -- Starting Up.




Copyright: Department of Computer Science, University of Regina.