Lab2: UNIX, C++ and Windows

You will work on

Windows on Campus and at home.

1. Some basic UNIX commands

Unix commands are cryptic, usually between two to five characters in length. However, they reprsent the function they perform. For example, ls is the command to get a directory listing.

The general format for Unix commands is:

        command -options arguments

where "command" is the name of some command followed by a number of options or arguments.
Options are generally single characters that represent specific options. The minus sign "-" should be entered before an option.

        Type in ls 
        and then type in ls -l

Notice that the "-l" option results in a 'long' listing showing file permissions etc..

List of Commands

List of UNIX commands UNIX Tutorial for Beginners

2. Editing files using PICO

pico Commands are displayed at the bottom of the screen. As characters are typed they are immediately inserted into the text. Editing commands are entered using control-key combinations.

Simply enter pico filename
to call up pico editor. If the file does not exist, it will be created. If the file does exist, it will be read into the edit buffer.

A pico call up screen is as follows:

From the commands displayed at the bottom of the screen, select ^G by pressing ctrl-g, to get help. You should see the following.

Press ctrl-v to view more pages. Read the commands which are very useful to you when you edit your C++ program.

Here are more commands. Read them all.

Here is the last page for the Help. Read the page.

Now press ctrl-x to exit the help page. Press ctrl-x again to exit the pico text editor. You should see unix command line by now. It's time to practice.

Example of creating a file with pico

Here is an example of how to create a file called "header.txt" using pico.

Start by entering: pico header.txt

Entering the following lines. Do not worry about the mistakes, you can correct them later.

        Student Number:
        Assignment Number:
        Program Creation Date:
        Purpose of the Program:

When you finish editing the file, be sure to save and exit pico by entering ctrl-o and then ctrl-x.

4. Compile your C++ program in Linux

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

g++ program_name 
For example,
g++ hello.cpp -o hello
For now, just type the commands, we will explain the detail later. To run the program, type

5. Script command

The script command is used to capture your program output, so when you hand in your assignments, you need to print out your C++ program and the output of your program. For example, my C++ program name is asg1.cpp and my output filename is asg1.log, I need to print out both files and hand them in to my class instructor.
A044872[25]% script hello.log
Script started, file is hello.log
A044872[1]% g++ hello.cpp -o hello
A044872[2]% hello
Welcome to the world of C++
What is your name? Ada

Hi Ada! Welcome to CS110-130.
A044872[3]% exit
Script done, file is hello.log

You should have seen when the script command is used, the exit command is used to close the process of script. Always remember this --- WHEN YOU USE script YOU MUST ENTER exit AT THE END!!! In the example, usually, we call hello.cpp C++ source file, hello the executable file, and hello.log the output file or script file. The print out for the C++ source code and the output will be often required for your class assignment.

Now look at the following two screen captures. One is demonstrating how to use script commamd. The other is demonstrating how to use more command.

Using Windows on campus and at home

1. SSH to Hercules from home

Why Hercules?? Since you do not have Linux at home, you have to actually login to Hercules remotely.

If you have Windows 95, 98, 2000, or XP at home, you need to remote logon to Hercules to do your homework. The university provoides a program for you to use called Teraterm terminal emulation program with SSH support

Download UR Configured Software Suite

2. Telnet to Hercules on campus

If you want to logon to Hercules on campus using a Windows machine (rather than the Linux in CL135.4), you need to use Telnet to connect to Hercules.

See the following link for instructions. Telnet to Hercules

3. How to print from Hercules in CL135.4

To print your Hercules programs in the lab (ClassRoom 135.4) printer, type
lpr -Pcl1354 filename 
For example,
lpr -Pcl1354 hello.cpp 
Remember, all printing is charged to your student account.

How to print from Hercules on campus and at home by using TeraTerm

The command TeraPrint works only with TeraTerm program, which is a Windows program. If you are connected to Hercules which is a Unix/Linux system from a Windows PC, and is using TeraTerm on the Windows PC to make the connection, you can print a file using TeraPrint. TeraPrint prints to the Windows printer for that Windows PC. It could be one of our lab printers. If you are in CL115, it will be the printer in that lab. If you are in the Ed bldg, it will be the printer in that Ed lab. If you are at home it will be your own printer. It can never be the printer in CL135.4 - that is only accessible from Linux. To print,
TeraPrint filename 
For example, to print a file called hello.cpp, you type
TeraPrint hello.cpp

Copyright: Department of Computer Science, University of Regina.