User Tools

Site Tools


haas:spring2011:cprog:tasks:task0


Corning Community College

C/C++ Programming


Task 0: Initialization

~~TOC~~

Objective

To become familiar with the command-line through exposure to some simple commands.

The student will also be presented with traditional C/C++ Programming and UNIX/Linux conventions they are expected to become familiar with and use throughout the semester.

Reading

In “Version Control with Subversion”, please read:

Overview

What is UNIX?

UNIX is a multiuser, multitasking operating system.

Developed at Bell Labs in the early 1970s, UNIX has formed the foundation of much of computing as we know it. Just as the PDP/11 hardware that greatly influenced even today's computer architectures, UNIX is home to a philosophy of computing and information usage.

Computer Science curriculums over the past 30 years have reaped the benefits from having this relatively open, flexible, and in a way standardized environment to promote learning of essential concepts, as well as to drive innovation and to create new and exciting breakthroughs.

UNIX was created out of a need for a flexible operating system that would allow productive use of computer hardware. Truth be told, the original developers wanted a portable means of playing one of the first computer games- Space War.

But outside of those initial goals, UNIX found its use in the fields of text processing, filtering, programming, automation, and many other areas. With the dawn of packet switching computer networks (such as the Internet), UNIX also acquired the legendary reputation it has today- a robust, reliable, and efficient server platform for deploying network services and other mission critical tasks.

With the growing popularity of Linux and the Open Source movement, the ideals of UNIX (whose dominance was being threatened by the likes of Novell Netware and Microsoft's Windows NT) were given a second chance, and in recent times we've been observing the rise of UNIX once again through Linux (as well as the open source BSDs), supplanting Netware, and is now considered by Microsoft one of the top threats to Microsoft's monopoly.

No longer purely a server platform, Linux is also driving a newfound push for alternate desktop environments, games, and other common computing uses.

Linux can no longer truly be termed “exotic” or “esoteric”. Instead, it is becoming a significant force in the computing industry and thus acquiring proficiency in Linux is a growing skill that is increasingly being sought by employers.

Rarely a week goes by now where Linux doesn't make the headlines in some way. City of Munich's (in Germany) city government is in the process of switching to Linux to save on operating costs. Big name support by the likes of IBM, HP, Novell. NASA buys 10,000 processor Linux cluster from SGI.

This class offers you the chance to partake in an incredible journey- one that can open many new doors and opportunities; to help you unlock some of the hidden potential trapped inside your computer; and to be aware of another option available to you when designated with the task of using the computer to solve a problem.

Be you in pursuit of the computer sciences, networking, web development, traditional sciences and mathematics, education, liberal arts, or just new skills and experiences, welcome to the adventure!

Case Sensitivity

UNIX/Linux is case sensitive!

What this means is that commands typed on the system are distinguished from one another not only based on their spelling, but also whether or not they use upper or lowercase letters.

For example, in UNIX/Linux: “Word” is distinguished from “word” is distinguished from “WORD” is distinguished from “wORD”. Case matters.

Usernames on UNIX systems are traditionally in lowercase, so be sure your CAPSLOCK key is turned off and you do NOT capitalize the first letter when entering your username on login. Passwords are often composed of many letters, numbers, and symbols, so unless you specifically know something is uppercase, chances are you need to use the lowercase equivalent.

Logging In

If you haven't already, obtain your CCC username/password. (This information will be given out by your instructor or e-mailed to the e-mail address you have registered with MyCCC).

IMPORTANT: If you have not received information on your Lab46 account, please contact your instructor (haas@corning-cc.edu) immediately. Send along your CCC username (what you use to log into the MyCCC website or log into the computer labs).

1. Using a Secure Shell terminal program of your choice (such as PuTTY for Windows), do the following:
a.Log into the following host: lab46.corning-cc.edu
b.If using PuTTY, be sure to select the SSH protocol.
c.When prompted, enter the username and then password provided to you.

Passwords

If this is your first time logging in, you will be prompted to enter a new password.

Please create a 6-8 character password, using at least two numbers or symbols other than lowercase letters), that is known only to you.

NOTE: As is commonplace on UNIX/Linux systems, when you enter your password, nothing will be echoed. On Windows-based systems you may be used to seeing “*” appear as you type in a password. On UNIX you will see nothing.

Once Logged In

MOTD

UNIX systems, like web sites, or bulletin boards, or any other resource that is utilized by several people, is ultimately a form of community. And, like any community, events take place which affect the members of that community.

In a city, when construction takes place, appropriate notices often appear in the local newspapers, radio broadcasts, or televised news. When there's an office picnic or staff meeting, one often sees an official memo or flier on the bulletin board.

On a UNIX system, there is also important information that must be relayed to users. Sometimes we must take the system down for maintenance or reboots, or to let users know about certain new features. For this reason, UNIX systems have what is known as the “Message of the Day” (or MOTD). Upon successful login to a UNIX system, the system will display the MOTD to you before your initial prompt appears.

The text you see displayed to you consists of the contents of the /etc/motd file.

*PLEASE take the time to read any information presented in the MOTD display.*

The Command Prompt

After all the login information has been displayed you will be presented with the command prompt. It should look something like:

lab46:~$ 

This prompt is broken into three parts. The first part- “lab46” is the hostname of the system. Following that is a colon to separate the hostname from your current directory.

The “~” (tilde) is a representation of your home directory. Your home directory is, of course, the default place you start out everytime you log into the system. All of your files are located here. Each user has their own unique home directory.

Finally is the “$” symbol which represents the end of your prompt. (In some cases it may be the only visible entity of your prompt). Historically, regular users will have either a “$” or a “%”, depending on your shell. The superuser (also known as root) would have a “#”.

Whenever this prompt is displayed it means that the system is available to accept input from you.

Location

As stated above, your default prompt will show you are in directory “~”. This symbol actually expands out into a real directory on the system, as seen with the pwd command.

2. Do the following at the prompt:
a.Run the pwd utility.
b.What happens?

In many cases, you can freely substitute “~” and its actual representation.

Important Basics

Having methods of labeling (location) and organizing data is very important in a file system (just as it is with a filing cabinet). However, what good is it if you don't have effective ways of retrieving that data?

Navigation plays an important role, allowing you to move around the file system, just as you would drawers of a filing cabinet, taking you to the desired destination where you can view data, or store new data.

Because UNIX/Linux systems (like many other systems) use a directory-based system (sometimes directories are referred to as “folders”), we describe navigation in terms of changing one's current directory. The “cd” command, which stands for change directory, is our key to getting around the system.

3. Do the following, and if you get any errors, read the note below:
a.Every account on Lab46 has a src subdirectory for writing programs. Change to that directory now by entering “cd src” at the prompt (without the quotes, of course).
b.Record the current appearance of your prompt. Type pwd again. How has it changed?
c.Now return to the previous directory by typing “cd ..”. This drops you down one level in the directory tree. You should now be back at the base (or root) of your home directory.
d.What do you think will happen if you issue a “cd ..” again? Take a guess and then try it. Were you correct?

NOTE: When you issue a “cd ..”, be sure that you put a space between the “cd” and the “..”

If you see a “command not found” error message when using “cd ..”, make sure you've inserted that space, otherwise the system will try to interpret the entire string as a command (and “cd..” doesn't exist as a command on the system).

A Shortcut

No matter where your travels take you, there is often no place like home.

All Dorothy needed to get home was to click her heels together 3 times, and repeat “there's no place like home”.

Luckily, UNIX makes use of similiar magical feats, and it is much easier to find your way home at the end of a journey across the filesystem.

When lost, homesick for your home directory, or in general need to get back to your own data, simply type “cd” and hit enter (without the quotes) at the prompt, and you will automatically be whisked back to your home directory, safe and sound.

Listing

One of the most important functions you'll want to employ when dealing with files and directories is the ability to view what is there. What better way to figure out what to do with the data if you can't figure out its current state.

In UNIX/Linux, to list your current directory we use “ls”. Whenever you have a question regarding what files may be present, or named, or anything, it is quick and easy to type “ls” and hit enter.

Think of “ls” as a set of eyes into the filesystem. Use it whenever you need or want to.

So remember- to list, just use “ls”.

Creating Directories

To better organize your files, you may wish to create additional directories. This is accomplished via the mkdir command. The common invocation will be of the form: mkdir newdirectory

To list files in your current directory, we use the “ls” command. Type it now, and view the current available files and directories.

For example, create a new directory named temp:

lab46:~$ mkdir temp

Type “ls”, and take notice to the line pertaining to temp.

To remove an empty directory, the rmdir utility can be used.

4. In the base of your home directory, do the following:
a.Check the files in your home directory. Do you have a bin directory?
b.If not, create your own bin directory. How did you do this?
c.Remove the temp directory you created in the above example. How did you do this?

NOTE: /bin and bin are *not* the same thing. You want to create your own bin directory.

Getting Started With Your Opus

As part of the required activities for the course, you are to maintain an Opus. To get started, you need to perform the following steps:

  • Open a web browser, go to http://lab46.corning-cc.edu/user/start
  • Make sure you are logged into the wiki
  • Locate the entry for your user
  • Click the link for your Opus
  • Click one of the small “Edit” links off to the right (for example, for the Opus title or Introduction)
  • Customize the Opus and get used to the operation of the wiki
  • Be sure to “Save” your changes frequently! (Wikis work better with many small changes)

Checking Your Mail

You may have noticed a message when you logged in that said “You have new mail.” This of course means that you have received one or more new messages in your inbox that are available to be read.

There are several mail user agents (MUAs) available, as you are probably already familiar. On Lab46, a popular program to use for mail is alpine.

5. Do the following:
a.Start alpine from the command prompt.
b.Check your e-mail.
c.Send an e-mail to yourself.

If this is your first time running it, you will get a few banner screens. One will ask you to participate in an alpine census, asking if you want to send the alpine project an e-mail to “count me”.

Along the bottom of the screen will be listed (often in two rows), the commands available for you to use. All available commands will be displayed in reverse video, then followed by a brief description of their action. Some commands will consist of a single letter. Others will be prefixed with a caret symbol (^). Traditionally, the ^ represents a control character (which is obtained by holding down the CTRL key and then pressing the desired key on your keyboard).

A common example of this is the CTRL-C sequence, (which is created by holding down the CTRL key on your keyboard and also pressing the c key) that attempts to kill (or interrupt) your current action.

Once you get past all the banner screens, you will be presented with the mail menu. In many cases, if you have a capable terminal program (such as PuTTY, MacSSH, or any SSH client), you can also use the cursor keys.

In most cases, you will only really use two of the options on a regular basis.

The most popular will undoubtedly be the “I” option, representing the “MESSAGE INDEX”. By hitting “I” or moving the cursor to that option and hitting enter, you will be taken to your INBOX, and it will list all the messages currently in your inbox.

I will leave the rest of it up to you, as there are commands available on the bottom of the screen, as well as the fact you are probably somewhat experienced with the basic operation of e-mail.

HINT: Make sure you check out and cycle through the “OTHER CMDS” available to you to figure out how to do things like “Reply”, “Compose”, go to the “Main Menu”, and of course “Quit Alpine”.

The other popular option on the main menu is COMPOSE. This of course lets you write an e-mail to someone. To do this you will need to know things like the recipient's e-mail address, and of course to provide an appropriate subject as well as a body of the message.

The available commands are once again available to you at the bottom of the screen. I will expect you to figure out how to use these on your own.

HINT: ^X and ^C will probably be good things to know.

To practice, try sending an e-mail to yourself.

6. Subscribe yourself to the class mailing list:
a.Go to the mailing list URL: http://lab46.corning-cc.edu/mailman/listinfo/cprog
b.Locate the “Subscribing to CPROG” section of this page, and enter your Lab46 e-mail address in the appropriate field.
c.Choose an appropriate password to use with the list.
d.Once you've entered your Lab46 e-mail address, chosen and verified your password, click the Subscribe button.

NOTE: Your Lab46 e-mail address consists of your Lab46 username, as follows: lab46username@lab46.corning-cc.edu

Once you've done this, go and check your e-mail on Lab46. You should receive a notice from the mailing list software with directions on how to confirm your subscription.

You need to receive and react to the confirmation message from the mailing list in order to be successfully subscribed to the class mailing list. If you try to post any messages to the list prior to confirmation, they will be rejected.

7. Send a test e-mail to the class mailing list cprog@lab46.corning-cc.edu:
a.Choose a relevant Subject: line for your e-mail, such as “Testing”.
b.In the body of the message indicate your intentions: “testing, please ignore.”
c.Check to make sure you received your post to the class list. As others subscribe you will see similar posts to the list.

Setting up your Subversion Repository

At the beginning of this task was a reading list consisting of two chapters out of a free “Version Control with Subversion” O'Reilly book that are well worth familiarizing yourself with.

Subversion, and other version control systems, allow you to version (or snapshot) instances of files, much as one would manually file dated versions of documents, that can be referenced, retrieved, and compared with other versions. Version control is particularly important in program development as many thousands of changes take place in any code base.

It is prudent to have a capability to “step back in time” should some modifications prove unsuccessful, to avoid needless data re-entry and effectively move forward.

What we are going to do now is initialize your personal Lab46 Subversion repository- a resource that each user on Lab46 receives, and can be used for an array of purposes, far beyond the requirements of any class activities you may encounter. We will be making use of subversion this semester to afford you the experience to familiarize yourself with this important development tool, so that you can effectively use it into the future.

Step 0: Create some files for our repository

For the purposes of this class, you'll want to create a special directory in which you store your source files. We'll be calling this directory cprog, and we'll want to create it underneath our ~/src/ subdirectory.

At the Lab46 prompt, do the following:

lab46:~$ mkdir -p src/cprog
lab46:~$ 

Step 1: Setting up your repository for class use

To accomplish this, please do the following at the Lab46 prompt (please substitute your username in place of the literal string “username” in the example below):

lab46:~$ svn import src http://lab46.corning-cc.edu/svn/username/src -m "Initial import"
Adding      src/cprog
Adding      src/submit
Adding      src/Makefile

Committed revision 1.
lab46:~$ 

To avoid some problems, we'll move our existing src directory out of the way:

lab46:~$ mv src src.bak
lab46:~$ 

Next, we'll need to check out our repository:

lab46:~$ svn co http://lab46.corning-cc.edu/svn/username/src src
A    src/cprog
A    src/submit
A    src/Makefile
Checked out revision 1.
lab46:~$ 

Step 2: Contact and misc. info collection

As is the practice in many classrooms the first week of class, essential contact information is collected to ensure priority communications should such a need arise. In your svn tracked src/submit directory, make a file called contact.info (see example):

lab46:~/src$ cd submit
lab46:~/src/submit$ nano contact.info

When you hit enter, you will be taken into the nano text editor and can type content into what will become the contact.info file.

Please provide the following information in that file:

Name: Your First and Last Name
Nickname: any preferred nicknames
E-mail: a preferred non-Lab46 e-mail address at which you can be contacted and check regularly

Rationale: a forward-looking statement describing why you have earned an 'A' in this class
(write as much as you want to justify your position).

When done, save and exit from the editor (if you look at the bottom of the screen you'll see various commands you can enter— ^ indicating the pressing down of your keyboard's CTRL key while pressing whatever key comes after).

For example, to save and then exit from nano, do a CTRL-X (press and hold down CTRL, press 'x').

You'll be prompted (at the bottom of the screen) whether or not you want to save your modified buffer. Answer 'y'.

The prompt will then change to display the filename to save as. If you followed the directions correctly above it should say “contact.info”. If not, you can take the opportunity now to make it say such. When set, press ENTER. You should be back at the Lab46 prompt.

Step 3: Add contact.info for subversion tracking

Before we can commit, we need to let subversion know we wish for it to track this file.

To do that, do the following at the lab46 prompt:

lab46:~/src/submit$ svn add contact.info
Adding       contact.info
lab46:~/src/submit$ 

Step 4: Commit contact.info to your repository

We'll now commit this file to your repository.

To do that, do the following at the lab46 prompt:

lab46:~/src/submit$ svn commit -m "created contact.info file for class"
Sending        contact.info
Transmitting file data .
Committed revision 3.
lab46:~/src/submit$ 

Data Directory Initialization

Please read and perform the activity in the Data Directory Initialization document.

Be sure to ask any questions if you are not sure your data directory has been correctly established.

Terminology

root user / superuser: a supervisor account often used by the System Administrator. This account is not limited by protections or restrictions as are set in place on regular user accounts.

base (or root) of home directory: the start of a subtree in the filesystem. In this case, the start of the tree of files you own.

blocks: units of data that are represented on the filesystem. Typically, it is common to see 512- or 1024- byte blocks on most storage mediums. (CD-ROMs are commonly an exception, using 2048-byte blocks, as are some exotic hardware configurations).

kilobytes: units of 1024 bytes, often represented by KB (or kB). Note in recent times it seems a new standard is emerging that promotes metric measurements, and you'll see 1000 bytes often be referred to as a kilobyte. The traditional 1024 bytes is referred to by some as KiB. I recognize the existance of KiB vs. KB, although I will often refer to kilobytes (kB) as units of 1024 byte units of information.

multi-user: the UNIX system is multi-user. This means that it can handle commands from more than one user at the same time. (A UNIX/Linux system can have multiple users logged in at once, each performing their own actions.)

multi-tasking: the UNIX system is multi-tasking. This means it can handle multiple commands/processes at the same time. This makes sense that if it can have multiple users on at the same time that it can handle multiple commands at the same time. Note that this also means that each user can have more than one program running at a given instance.

MUA: an acronym for “Mail User Agent”. In other words- an e-mail client, such as pine, Mozilla Messenger, Mozilla Thunderbird, etc. Basically any program that allows you to send/receive electronic mail.

mailing list: a collection of e-mail addresses pooled together for the purpose of creating a forum to discuss a topic or range of topics, as well as have a centralized communication medium for relaying important announcements.

post/posting: a message sent to the mailing list is often referred to as a “post”. When you send a message to a mailing list, you are “posting” a message to the list, as it is viewable by all subscribers.

command-line: the string of commands, arguments, options, and shell manipulation features that are typed in immediately following the prompt.

Logging Out

When you are done using the system for the time being, and wish to end your session, don't click the X in the top-right! This may have unintended effects, leaving your account logged in while you're technically no longer present. (Think mind without a body).

This would not only be undesirable for you, it is generally considered impolite as it may result in the system administrator (or you) having to do extra work later.

For those running Windows machines, you properly shutdown your computer when you're done, right? (Or at least log out your user). Same case here.

So, when you are done with your session, be sure to log out properly! This can be done in a couple ways:

  • The “logout” command, OR…
  • the “exit” command can be used.
  • Alternatively (and my personal favorite): if you prefer slightly less typing (with a few extra features; the usual fare: with laziness, comes more power) you can also use the CTRL-D key sequence to end your session.

Submission

All questions in this assignment require an action or response. Please organize your responses into an easily readable format and submit the final results to your instructor per the appropriate methods.

Your assignment is expected to be performed and submitted in a clear and organized fashion- messy or unorganized assignments may have points deducted. Be sure to adhere to the submission policy.

When complete, questions requiring a response can be electronically submit using the following form:

<html><center><a href=“http://lab46.corning-cc.edu/haas/content/cprog/submit.php?task0”>http://lab46.corning-cc.edu/haas/content/cprog/submit.php?task0</a></center></html>

Additionally, the successful results of the following actions will be considered for evaluation:

  • subscription to class mailing list with your lab46 e-mail address
  • creation of ~/src/cprog directory
  • import/checkout of lab46 subversion repository into ~/src
  • addition/commit of ~/src/cprog directory into repository
  • addition/commit of ~/src/submit/contact.info file into repository
  • creation of data directory symbolic link

As always, the class mailing list and class IRC channel are available for assistance, but not answers.

haas/spring2011/cprog/tasks/task0.txt · Last modified: 2012/01/18 23:38 by 127.0.0.1