Assignment #1 -- Getting Started with UNIX

 

This assignment is composed of four steps:

1. Logging in to your UNIX account

2. Creating a text document called “helloworld.cpp”

3. Compiling and running your first C++ program in UNIX

4. Creating your own website, and posting the source code for the homework assignment on your homepage.

 

The first program that many programmers write upon meeting a new system is called a “Hello World” program. This is a small program that prints out a message, usually “Hello World.” The purpose is to help you get started on the system. You must edit a small program, compile it and execute it. Your first assignment is to write a “Hello World” program on a UNIX machine. Assignments will be submitted both as a hard copy, and by posting them on your homepage, which you will create in this assignment as well.

 

STEP 1: Logging in to your UNIX account the first time

Go to the WEB Building (also called the Field Building), and ask for your UNIX account.  They will give you:

Your username (account id) which is probably your initials followed by a part of your last name.

Your temporary password, which you will change.

 

You will go to a SUN machine (not a PC). The screen may be dark. Press the RETURN key and it lights up. At the login prompt, type in your user name:

 

login: username 

 

At the password prompt, type in your temporary password (UNIX is case sensitive):

password: temporary_password

 

When you login for this first time, you will be asked to change your password.  Follow the rules for a valid password. You will then be logged off automatically and told to come back after it has updated the password. This may take up to an hour.

 

Return and get a machine to login the second time. Give your username and the password you selected (which you can change at any time by using the passwd command). You are now logged in to your account. Always remember to logout before leaving your machine!

STEP 2: Creating a helloworld.cpp program

 

You all know how to create a C++ program that prints “Hello World” to the screen. The challenge in this part is to create your first text document in UNIX. The text editor that you use is your choice; although I recommend learning Emacs. You can find a link to an Emacs tutorial on the UNIX resources page, and there are many other online tutorials. You can also choose to learn vi or pico.

 

Create the document and save it as helloworld.cpp

STEP 3: Compiling and running your first C++ program in UNIX

 

The command to compile and create an executable from C++ source code is the following:

 

CC helloworld.cpp

OR:

g++ helloworld.cpp

 

If there are errors, they will be displayed on the screen. Fix them in the text editor and compile again.

 

The executable for your program is (by default) placed into a file called a.out

To run your program, simply type

 

a.out

 

on the command line. The output should display on your screen.

4. Creating your own Website

Log into your Unix account.

Change the permissions for your home directory to allow others read permission (DO NOT type the comments, they are for you):

 

pwd // tells you the exact name of your home dir, e.g. /users1/sneuburg

chmod 711 /users1/sneuburg // allows others to read certain files in your home directory

 

Now, create a directory called public_html under your home directory, as follows.

 

mkdir public_html // creates a directory called public_html

chmod 755 public_html // changes permissions for public_html directory

cd public_html // changes the current directory to public_html

 

Using any text editor create a file called index.html which will be your homepage. If you do not know HTML, you can use the following text, augmented, of course with your own name. You should read a bit about HTML; you may use some useful links provided on my Unix and HTML resources page.

 

 

 
<HTML>
<HEAD>
<TITLE>Neuburger’s Homepage</TITLE>
</HEAD>
<BODY>
<H2>Welcome to Neuburger’s Homepage</H2>
 
Here you will find links to all of my CISC 3100 assignments.
 
<br><br>
 
<a href=”helloworld.cpp”>Homework 1</a>
 
</BODY>
</HTML>
 
 
You can also view this file by going to: http://acc6.its.brooklyn.cuny.edu/~sneuburg/ex.html
Choose View -> Source on the Web browser’s menu.
 
Now, change permissions of the index.html file to allow all read permission, by typing the following at the command prompt in the public_html directory:
 

chmod a+r index.html // allow read access to all

 
 
You should now be able to view your homepage in any web browser. In UNIX, type netscape, or firefox at the command prompt to open a browser. The URL for your homepage is the following:
 
http://acc6.its.brooklyn.cuny.edu/~sneuburg


 
 

protocol  host                  domain name                user name

 

To complete your assignment, you must make sure that you have copied helloworld.cpp into your public_html directory, and you have changed the permissions for the file.

 

In your home directory, type:

 

cp helloworld.cpp public_html //copies file from your home directory to public_html directory

cd public_html //change directory to public_html

chmod a+r helloworld.cpp // allow read access to all

ls –la // list files, showing permissions

 

You may decide to put all files for each homework assignment into its own directory. Then, your link would be as follows:

 

<a href=”hw1/helloworld.cpp”>Homework 1</a>

 

However, be sure to change the permission on the directory hw1 as you did for the public_html directory above.

 

Before submitting, be sure to test your files by typing in your url in the address bar of a web browser.