You’ll be using the Math & CSci Division’s “FCCsci” Linux server for your work this semester. You’ll use it to store, edit, compile, and test your programs, and to submit them to me for grading.

Connecting to the Server

To connect to the server you’ll need a SSH client. If you’re using a Mac (or Linux) you’ve already got one; it’s part of the standard install. The computers in the CSci lab, although they run Windows, already have PuTTY installed, but you’ll want to install it on your personal computer. (Note that you can connect to the server from any computer with a client; you don’t need to be on campus.) There’s even a client for Android: JuiceSSH.

However you connect, you’ll need several pieces of information:

When you connect, you have to set the port to 5150. In PuTTY, this is done on the main connect screen, next to the hostname. After you click connect, you will be prompted for your username and password.

If you’re using a Mac (or Linux), then you’ll need to open a terminal and use the ssh command. On Mac OS X, you can find the terminal in the Applications folder, under Utilities (or you can press Command-Space and then type the name “terminal”).

The command to connect to the server looks like this (press Enter at the end):

ssh -p 5150 username@fccsci.fullcoll.edu 

Replace username with your username; the -p 5150 gives the port. You’ll be prompted for your password.

Either way, after you connect, everything you do will be on the server, rather than on your local machine, thus you don’t need to worry about always working on your own computer, or what happens if your computer dies at the last minute, etc.

The first time you connect you will get a message about the “server key” being unknown. This is normal; just say Yes or Accept or whatever. (This will cause your computer to save some information identifying the server, so that in the future it can be certain you are connecting to the same machine.)

The first thing you’ll want to do is change your password, in case anyone else knows (or can guess) your Banner ID. Do to this, type

passwd

and press Enter. The system will prompt you for your current password (the one you just used to log in) and then for a new password, and then for your new password a second time, for verification.

A special trick: often you’ll want to do more than one thing at the same time on the server. E.g., you might want to edit your program, but at the same time, be able to compile it to check for errors. Although there are tools on the server that you can use for this (see screen and tmux) an easy way to do this is just to open more than one connection. E.g., launch two copies of PuTTY, or two terminal windows, and connect from both. Now you have two separate “views” into your account on the server.

Submitting assignments

Generally speaking, you don’t have to do anything to “submit” an assignment. As long as you’ve created it with the name and in the location I specified, I will automatically grab a copy of it on the due date. If your work is unfinished by the due date, you might add a comment to point that out to me (so I don’t waste time correcting “mistakes” that you already know about).

All the files on the server (and on your computer…) are organized into a tree of directories and files. Everything you do will be in the branch of the tree that starts with your home directory, which looks like

/home/username

When you log in, you are automatically placed in your home directory. You can (and for many assignments, must) create subdirectories under your home directory to organize things. For example, I like to have a subdirectory called “work” as a scratch pad for experiments and the like. You can create directories using the command mkdir; e.g.:

> mkdir work

will create work as a subdirectory of the current directory. What’s the current directory? The pwd command will tell you:

> pwd
/home/aclifton

(In these examples I’m using > as a generic substitute for the prompt, the bit of text that the system prints before the cursor. The actual prompt looks something like this by default:

username@fccsci:path$ 

where username is your username and path is a representation of what pwd would print, with some shortcuts that I’ll mention below. But the prompt is customizable, if you want to get fancy.)

If you want to get a high-level view, use the tree command, which displays everything in the current directory, and all its subdirectories. For me, it looks something like this:

aclifton@fccsci:~$ tree
.
|-- bin
|-- rosters_fall2016
|   |-- clifton_cs123_mw_0430.csv
|   |-- clifton_cs123_mw_1245.csv
|   |-- clifton_cs123_tt_0815.csv
|   `-- clifton_cs133_tt_1030.csv
`-- work
    |-- fossil-src-1.35.tar.gz
    |-- test
    `-- test.cc

3 directories, 7 files

Paths

Paths in the tree have the form of a sequence of names, separated by / symbols. Paths that start with / are called absolute; they always refer to the same location in the tree. Paths that do not start with / are called relative, and they are relative to pwd. So, e.g., the path work/ means one thing when I am in my home directory (it refers to /home/aclifton/work/) and another thing if I am somewhere else.

Since a lot of the paths you’ll deal with will start with /home/username there’s a shortcut for this: ~. You might notice when you login that the prompt looks like

username@fccsci:~$

The ~ indicates that you are in your home directory. If I go into the work subdirectory via cd work:

aclifton@fccsci:~$ cd work
aclifton@fccsci:~/work$ 

The cd command changes to a different directory. You can give it an absolute path, or (more commonly) a relative path. There are two “special” directory names that you can use with cd:

You can mix these in with normal paths: if I have a subdirectory ~/homework and I’m currently in ~/work I can change directly to homework by doing

cd ../homework

Similarly, if I wanted to move up two levels I could do cd ../.. and so forth.

Getting help

You can get help on almost any command by typing

man command 

For example, man nano brings up the documentation for the Nano text editor, described below.

Downloading Assignments from the Web

For the practice sets, there’s a specialized command that will download them and put them in the right place, with the right name:

get-practice 0

will download practice0.txt into the directory ~/practice (creating it for you if it does not exist) and then offer to open it for editing for you.

To download a file from a website to the current directory, you can use wget:

wget http://staffwww.fullcoll.edu/aclifton/files/benchmark.h

will download the file http://staffwww.fullcoll.edu/aclifton/files/benchmark.h and save it as benchmark.h in the current directory. (This file is used in one of the fundamentals projects.)

Creating, editing and viewing files

To create and edit source files, you’ll need to use an editor. There are three major ones available on the server:

All three editors support loading multiple files at the same time and switching between them (although in Nano this feature is disabled by default). Emacs supports the ability to split the screen into subwindows, as well as the ability to open another shell (command prompt) in one of them.

All three editors can be started with a filename, to open (or create, if it does not already exist) that file:

> micro myfile.cpp

You can also open more than one file at the same time:

> micro myfile.cpp practice0.txt

If you just want to look at a file and don’t need a whole editor, you can use less

> less myfile.cpp

will display the contents of myfile.cpp; you can scroll through it using the arrow keys. Press h to view a help screen with all the commands (searching, going to a specific line). Press q to quit.

If a file is particularly short, so that you don’t need scrolling or other fanciness, you can use cat:

> cat myfile.cpp

will print the contents of myfile.cpp to the screen and then immediately return you to the prompt.

Editing in Micro

Compiling, Linking, and Executing source files

Of course, the major task of this course is writing programs, and that requires translating source files (that you create with an editor) into executable files that you can run.

To compile some files file1.cc file2.cc into a program file1 you can use

> compile file1.cpp file2.cpp

That will serve for our purposes for most of the semester; the remainder of this section explains the details that are going on in the background.

To compile a single source file.cpp into an object file, use

> g++ -c file.cpp

This will (assuming your file compiles error-free) produce a single object file as output, named file.o.

To link one or more object files together into an executable, use

> g++ -o executable_name object1.o object2.o ...

where executable_name is the name of the executable file you want to create (in the current directory) and object1, object2, etc. are the object files to link together. E.g., if file.cpp was the only file in the above project, we would link it with

> g++ -o file file.o

to produce an executable named file.

To (finally!) run the compiled-and-linked executable, we would do

> ./file

(We are actually giving the full path to the file; for executables that the system doesn’t “know” about, like the one we just created, we have to give the full path when running it.)

GCC will actually allow us to compile-and-link in a single step, which is sometimes easier:

g++ -o file file.cpp

The object file will still be created.

Errors

If errors are produced during compilation, they will generally have a line number attached to them. You can look up this line in your editor to figure out what went wrong. The micro editor will also mark lines that have errors with a >> whenever you save your file, saving you a significant amount of time.

Link errors happen after the source text has already been processed, so they don’t have line numbers (and hence, can be more difficult to track down). The most common link errors have to do with incorrectly-named symbols, so that the compiler is looking for something which does not exist.

When you run your program, it may crash due to a runtime error. Virtually no information is printed in this case, unfortunately, but there’s a way we can see what the program was doing when it failed: run it through the command catchsegv:

> catchsegv ./file

will run your program as usual, but will print a stack trace when it dies, letting you know where, in your program, the problem occured.

Command reference

Here’s a reference to some commonly used commands, including the ones discussed above, as well as some others

Command Description
ls Lists the contents of the current directory (files and subdirectories)
tree Lists the contents of the current directory, and all subdirectories
pwd Prints the current directory
cd path Changes the current directory to path
mkdir name Create a subdirectory of the current directory
rmdir name Remove a subdirectory (which must be empty)
rm file Permanently deletes file
cp path1 path2 Copies the file path1 to path2
mv path1 path2 Moves (renames) the file path1 to path2
less file Displays the contents of file
cat file Print the contents of file to the screen
g++ Used to compile and link programs (see above)
./program Run program in the current directory