Computer Science 101 - Lab 1

Introduction to Unix Systems and Codelab

How to login

On the login screen is a place to enter your user name, and four controls:

"OK", "Start Over", "Options", and "Help"

Click on "Options", and select "Session".

Under "Session", select "Java Desktop System".

Type your CS username in the space provide and click "OK" or just type the enter key.

When prompted, enter your temporary password cpsc123 to complete the login procedure.

Setting Your Password

Select a good password:

NOTE: Only the first eight (8) characters of the password are meaningful. (e.g. password = password1234)

DO NOT:

DO NOT use your login name, first name or last name. DO NOT reverse it, capitalize it, double it, or use it in any form.

DO NOT use all digits or all the same letter.

DO NOT use a word contained in an English dictionary, foreign language dictionary, or word list. This includes proper nouns.

DO NOT use words from a dictionary as described above as any suffix or prefix to a password, e.g. word! and !word are bad.

DO:

DO use a password with upper and lower case letters mixed with numbers or symbols.

DO use a password that is easy for you to remember.

DO use a password that you can type quickly.

Open a terminal window:

Method 1: Menu Shortcut

Click on the "Launch" control

Click on the "Applications" control (see image):

Select "Utilities"

Select "Terminal"

Method 2: Command Execution

Click on the "Launch" control

Click on the "Run Application" menu :

Type "xterm" in the entry field.

In the new terminal window, enter the command passwd

When prompted, enter your current password (cpsc123)

Enter your new password

Re-enter your new password

REMEMBER YOUR NEW PASSWORD

Setting Up Mozilla Email

You have an email account for Computer Science that is separate from your university email account. This email account is your CS username + @cs.clemson.edu. You can use Mozilla to check your CS email account for class-related email notices.

Click on the "Launch", "Applications", "Internet", "Mozilla" (you may be prompted to create a new profile. If you do this, it's a good idea to use your username as the profile name.

Inside the browser window, click on the "Window" menu and select "Mail & Newsgroups"

Select "email account" for setup

Type your username"@cs.clemson.edu"

Type "mailhost.clemson.edu" as your incoming and outgoing email servers

Make the account name your username.

Forwarding CS Email

If you would prefer to have your CS email forwarded to your University account, do the following:

In your home directory (see "Managing Files and directories" for more information), create a file named .forward (Yes the . is important.)

Insert your full email address for your University account, e.g. someuser@clemson.edu. Do not put any extra lines, space, or punctuation marks in this file.

Until you delete the .forward file, all mail addressed to you at the CS department will automatically be forwarded to the account you specified in the file.

Class announcements will be sent to your Clemson University mail account. If you don't read this account or you forward it to some account in which your mailbox is full, you will miss important announcements related to class.

Managing Files and directories

Creating directories

Open a terminal window

Enter the pwd command. (It stands for print working directory). The working directory should be "/users/your_username". This is also known as your home directory. Terminal windows open to this location by default. All your files and directories will will be kept in a directory tree with this directory as root.

Enter mkdir 101 to create a directory for your CPSC 101 files.

Enter ls to list the contents of the current directory. You should see the new 101 directory.

Enter cd 101 to change to the 101 directory.

Enter mkdir lab1 to create a directory for today's lab.

Enter mkdir temp to create a temporary directory.

Creating Files

Select Launch and then "Run Application...".

Type gedit to start the gedit text editor.

You can use gedit to create and edit any type of text files including C programs. For now, create a file named test.txt and save it in 101/temp/.

In a terminal window, cd to your 101/temp/ directory.

Type ls to see if the test.txt is in the right spot. If it is not, go back to gedit and save it there now.

Now in the terminal window type pico test.txt. This should open your file in a text-based editor. You can edit your files this way without gedit. Feel free to make changes.

Use the commands at the bottom to save and exit.

Deleting Files and directories

In the terminal window in the 101/temp/ directory, delete test.txt by typing rm test.txt

Type ls and confirm the file is gone.

Leave the temp directory by typing cd .. to return to the parent 101 directory.

Now delete the temp directory by typing rmdir temp. Notice that files are removed with rm, but directories are removed with rmdir.

Desktop Shortcuts

If you wish to have a desktop shortcut for launching applications you use frequently, such as gedit, xterm, or mozilla, follow these steps:

Right click on the desktop and choose Create Launcher.

Fill in the required fields in the dialog box that appears

Choose an appropriate icon and click OK.

You may also add a launcher to the "panel" at the bottom of the screen by right clicking on the application name in the launch menu structure

Writing a C Program

Using gedit, you are going to create a simple C program that will print the words "Hello, world!" to the screen. In the gedit window type in the following program:

#include <stdio.h>

int main()

{

printf("Hello, world\n");

return(0);

}

After entering the above text save the file in 101/lab1/ as simple.c

Compiling a C Program

In terminal window, cd to 101/lab1/. Enter ls to confirm simple.c is there.

To compile simple.c enter the command: gcc simple.c

If there are errors, go back and confirm you entered the program correctly.

If there are no errors, use ls to confirm that the compiled machine language program was created with the name a.out.

To run the program enter the command: ./a.out The ./ is used to tell the system that a.out is in the current directory.

"Hello, world!" should print on its own line.

CodeLab

Registering

In a web browser go to http://www.turingscraft.com/

In the uppper right-hand corner, click register.

Select STUDENT and click continue.

Enter the correct code for your professor:

Professor Westall: Section 301:	CLEMSO-7053-2656

Professor Lowe: Section 302:	CLEMSO-1891-2657

Section 303:	CLEMSO-6909-2658

Select Clemson in the Un

iversity list and click continue.

Type your Clemson University email address (NOT .cs; NOT gmail; NOT hotmail) and click continue.

Create a password and click continue.

Accept the user agreement and click continue.

Using CodeLab

Go to http://www.turingscraft.com/ and click login.

Type your Clemson University email address and password to login.

On the Left menu, select C CODELAB, ORIGINAL, QUICKSTART, Beginning. You should see four (4) exercises.

Do all four (4) exercises: 10001, 10002, 10003, and 10004.

Turn In Work

Show your TA that you completed the four (4) CodeLab assignments.

Turn in your simple.c.
Use sendlab.101.section_number 1 simple.c

Optional: Accessing Unix From Windows

Your laptop should already have Secure Shell Client (SSH) installed on it. Run SSH.

Press Enter to open a connection dialog.

Type a host name:

If you are on campus, you can use gecko1.cs.clemson.edu, gecko2.cs.clemson.edu, . . . gecko24.cs.clemson.edu. There are other systems as well you can connnect to.

(If you are not on campus, you will have to use access.cs.clemson.edu. Once you are connected, you must immediately type ssh another_host@cs.clemson.edu because access need to be kept free for incoming connections.

Type your CS username and click connect.

You may be prompted to confirm first-time connection to the server. click Yes.

Type your password and click OK.

You should now be logged onto a UNIX machine. You cannot use GUI tools such as gedit, however any text-based tools (gcc, pico, ls, . . .) are available.

When you are finished, log out using exit

7

Mike Westall

2007-08-27T13:33:18