Getting Started

This text is available online at:

In this article, you will find some general tips for doing programming assignments for courses in the CS department. A number of these courses expect your code to run on csa2 or csa3, which runs BU Linux. The undergraduate lab provides you with Linux machines where you can program and gsubmit your homework, but you may prefer to work from the comfort of your own home.

Here we present some suggestions for establishing a workflow for doing programming assignments from home. The suggestions mentioned here are merely, well, suggestions. They are believed to be working well for most people. Feel free to try something else if that suits you better.

Working from home and transferring files over

We assume that you have Internet at home. Depending on the link speed, some options may work better for you than others. Most programming assignments expect your code to run on Linux, so you want to have access to the same GCC compiler and tools from home and be able to test your code as you edit files.

If you use Windows...

Your programming assignment is assumed to use the POSIX API as opposed to Win32. Therefore, the key is to adapt Linux into your Windows workflow. You will still need to know how to use some basic Linux commands, which you can find explained in the "Using Linux primer" section below. You have the following options:

    • Turn your Windows machine to an X terminal. If you live on-campus and use ResNet, your network connection is fast enough to connect to csa2 and csa3 with graphical user interface (GUI). You have direct access to your files on the CS cluster and can compile and test your homework files in the same environment as the grader. Try Xming for the X server (free download for 7.4 which works fine; donation of £10 or more for 7.5). You connect to csa2/csa3 over SSH using the included PuTTY SSH client, which forwards the X11 session securely. Linux (and all Unix) GUI programs use the X11 protocol, which can run across the network as long as you have an X server running on your computer.
    • Run a Linux virtual machine. You have two options.
    • Install a POSIX environment on Windows. Download Cygwin (free download), which provides common shell and GCC tools that you'd find on a typical Linux system, as well as POSIX API to be used in your programming assignment. When you're done with your code, you need to transfer the files over to csa2/csa3. You should be able to compile your source code unchanged after copying files over to csa2/csa3, but make sure you test the code on csa2/csa3 before submitting it for homework.
      • Make sure at least the following packages are installed:
        • Under Devel: gcc4, make
        • Under Doc: man (preselected)
        • Under Net: curl, openssh, rsync.
    • Dual boot Linux and Windows. This is generally not recommended because, like reimaging the whole operating system on a computer, you are expecting to lose all the files. However, with Ubuntu, there is the Wubi installer than can install Linux while keeping the Windows file system intact. It is a fine way to try out Linux, but complication arises when you decide you want to get rid of Windows because the Linux system image resides on the Windows file system if you use Wubi.

For transferring files:

    • If you run X terminal and do your homework on csa2/csa3, there is no need to transfer files.
    • If you run VMware or Cygwin, use the tips in "If you use Linux..." subsection below. You have the option to have two working copies of the assignment, one on your local machine (or virtual machine), and one on csa2, and then keep them synchronized with the "rsync" command.
    • If you somehow have your own workflow, you can use WinSCP to transfer your files to csa2/csa3.

If you decide to edit source code in Windows, feel free to use Microsoft Visual Studio Express C++, NotePad++, or any other text editors you find handy. Please don't use the NotePad that came with Windows.

If you use Mac OS X...

Mac OS X already comes with most Unix tools and provides POSIX API, so you don't need anything special. The instructions for Linux below also works for you. You would probably be using a or for terminal emulator. Make sure you have X11 and Xcode installed. You should still test your code on csa2/csa3 prior to submission to make sure everything works.

You have the option to have two working copies of the assignment, one on your local machine and one on csa2. You can keep them synchronized with the "rsync" command below, described in the "If you use Linux..." section.

For editing source code on Mac OS X, I personally use Carbon Emacs. You can always use Xcode (only for editing; please do not submit Xcode project files). If you have other recommendation, let me know.

If you use Linux...

The ssh command allows you to run command line programs on another computer, with the remote input and output directed to the local terminal. You can use that to connect to csa2/csa3 and run many Linux commands (such as those mentioned in the "Using Linux primer" section below). These commands run on and use the filesystem on csa2/csa3, and they never touch files on your local machine. In this case, you don't need to worry about transferring files from your computer over to csa2/csa3.


If the login name on your local computer differs from your CS account, then you should use "" whenever you specify the host name, where cslogin is the login name of the CS account.

If you have a fast Internet connection, e.g. live on-campus and is connected to ResNet, you can enable SSH X11 forwarding, so you can run programs that involves a graphical user interface. You will need to enable X11 forwarding by passing the -X flag to ssh, like this.

ssh -X

If you have a slower connection, e.g. DSL, it may work for you if you use compression by additionally passing the -C flag to ssh. But the connection may still cause the programs to run sluggishly.

If you don't want to depend upon a fast Internet connection, you may choose to work on your local machine, then transfer files using the scp command. For example, copying hello.c to my home directory (~/) on csa2, I type:

[liulk@localhost ~]$ scp hello.c

You can recursively copy a directory by supplying the -r flag. See "man scp" for more information. Man pages are discussed in the "Using Linux primer" section below. It is a quick way to obtain reference material to a command, system call, or Standard C Library functions.

If you have two working copies, one on your local machine and one on the CS cluster, that you'd like to synchronize frequently, use the rsync command. For example:

[liulk@localhost ~]$ rsync --rsh ssh -av ~/path/to/source csa2:~/path/to/destination

This avoids the need to transfer unmodified files. The trailing slash "/" at the end of the path is significant; in most cases, you want to make sure the slash is either both absent (preferred) or both present in the source and destination paths. Again, "man rsync" gives you the complete reference to the "rsync" command.

Both scp and rsync commands are available on Cygwin and Mac OS X as well.

Alternatively, on Linux, you can use gFTP (command is "gftp"), which allows you to transfer files over SSH2 graphically. This is not available if you use Cygwin or Mac OS X.

Using Linux primer

Since Linux underlies the main infrastructure in the CS department, and most faculty members and teaching fellows use Linux, you're going to be most effective with your homework if you learn how to use Linux. You're also more likely to get support.

Mac OS X and Cygwin under Windows provide many of the same tools as Linux does, many things in this section also applies to these scenarios.

We assume you can get to a command line, either by starting a terminal window (e.g. GNOME Terminal, Konsole, XTerm) or by SSH into csa2/csa3. You will get a prompt that looks like this:

You may see a slightly different prompt, but it's no big deal. It should end with a dollar sign (bash) or percentage sign (tcsh) depending on your shell. Most commands discussed here should work, unless otherwise noted.

Navigating around the file system

The command prompt keeps track of where you are in the file system (called the "current working directory"). When you run a command and give it a relative path (a path that doesn't begin with a slash), the path is relative to the current working directory. You can see what's in a directory by issueing the "ls path" command. If path is missing, it lists the current directory. For example:

[liulk@localhost ~]$ ls

Desktop Library Music Public Sites tmp

Documents Movies Pictures Settings local

You can navigate the working directory by issuing the "cd" command, like this.

[liulk@localhost ~]$ cd tmp

[liulk@localhost tmp]$ ls


[liulk@localhost tmp]$ ls test-c

ccrun neg.c null.c trynull.c

[liulk@localhost tmp]$ cd ..

[liulk@localhost ~]$ ls

Desktop Library Music Public Sites tmp

Documents Movies Pictures Settings local

[liulk@localhost ~]$

The tilde "~" is a shorthand for the home directory, and ".." is the parent directory for any directory. You can also type in a partial command or file name and hit the tab key for auto-completion, as illustrated below.

[liulk@localhost liulk]$ cd Music/

[liulk@localhost Music]$ ls M # hit tab after typing 'M'

Mandalay - Solace (disc 2)

Matchbox Twenty - Yourself or Someone Like You

Michael Jones - Echoes of Childhood

Mike Link Harvey Taylor - Beat Elementals

[liulk@localhost Music]$ ls M

Continue typing 'ik' and then hit tab again. Note: tcsh doesn't print out completion candidates. It only beeps.

[liulk@localhost Music]$ ls Mike\ Link\ Harvey\ Taylor\ -\ Beat\ Elementals/

01 - Angels Of Mercy.mp3

02 - Silvery Swirl.mp3

03 - Brotherly Love.mp3

04 - Pura Veda.mp3

05 - Room For All.mp3

06 - A Secret Passageway.mp3

07 - Guided By Dreams.mp3

08 - Prototype.mp3

09 - The Mysterious Realm.mp3

10 - See What The Wind Blows Away.mp3

11 - Blue-Green Patina.mp3

12 - A Garden In Blooming Groove.mp3

13 - Proximity.mp3

14 - Sun Tour.mp3


Readme - .txt

[cover] Mike Link Harvey Taylor - Beat Elementals.jpg

[liulk@localhost Music]$ cd ~

[liulk@localhost ~]$

This should save you a lot of typing. At any point, you can do "cd ~" to return to your home directory.

You can pass the "--color" argument to "ls" to make the listing color coded. This way, you can tell easily what type of file it is.[liulk@localhost ~]$ ls --color

Desktop Library Music Public Sites tmp

Documents Movies Pictures Settings local

[liulk@localhost ~]$ ls --color tmp


[liulk@localhost ~]$ ls --color tmp/test-c/

ccrun neg.c null.c trynull.c

Green signifies an executable. Blue is a directory. Normal files are not colored.

You can also pass the "-l" argument to "ls" to do a long listing, showing permission, owner, file size, date, and time. I'll leave it for you to try.

You might find "--color" and "-l" very tedious to type. You can alias ls to 'ls --color' by editing your bashrc file (if you use bash) or your cshrc file (if you use tcsh).

Getting help

The most essential command you will find is "man" which displays a manual page for any command or system call you will need. You will find this command indispensible. The syntax is "man command", for example:

[liulk@csa2 ~]$ man cat

Will bring up the manual page for the "cat" command. This works for standard library functions and system calls too, like:

[liulk@csa2 ~]$ man malloc

Once in "man", you can use arrow keys to navigate line by line, as well as using "page-up" and "page-down" keys. The "home" and "end" keys may not work. But you can type in "g" (lowercase g) to go to the beginning, or "G" (uppercase g) to go to the end. Type "q" to quit. If "page-up" and "page-down" keys don't work for you, try "b" (going backward) for page-up and "f" (going forward) for page-down.

Sometimes a library function has the same name as a command. Man pages are organized into sections. Section 1 is for command line user programs, section 2 is for system calls, section 3 is for Standard C Library functions. For example, there is an "exit" shell command (to quit a shell or a shell script), an "_exit()" system call (probably you will never use this), and an "exit()" standard C library function (wraps around _exit() by calling some clean-up routines before terminating the current process). Type in "man sectionnum command" to specify the correct manual page.

When in a man page, the top left (and top right) corner shows which section the current manual page is from.

Getting colors on Mac OS X

The "ls" program on Mac OS X uses the BSD Unix implementation, which doesn't support coloring provided by GNU coreutils implementation found on Linux. You can of course download and compile coreutils on your own, but I prefer to use Fink.

Fink is a package manager based on the Debian package manager. After installing and setting up Fink according to the directions, you can issue the following command to install coreutils:

$ fink install coreutils coreutils-default

Fink will download and compile GNU coreutils from source code and install it to your system. You should be able to see colors.

In this case, I was looking at the printf command in section 1, not the printf() Standard C Library function. Use "man 3 printf" to get to the printf() man page for the Standard C Library function.

The "man" command is also available on Cygwin and Mac OS X.

Most man pages can also be found on the web, for example:

Text editors that you may try

Linux has many wonderful text editors that has syntax highlighting. Note: this section does not apply to Cygwin nor Mac OS X.

GNOME Text Editor can be launched by typing the "gedit" command. KDE Writer can be launched by typing the "kwrite" command. Both of them are compared side by side as follows:

As you can see, KDE Writer also supports block folding. Both of them can open multiple files in tabs.

I personally use Emacs, but it takes a while to customize it to your own liking and be used to it. I use it to enforce consistent code indentation and to highlight trailing spaces in a line.

Dealing with TAR (or TAR.GZ) files

From time to time, teaching staff may want to distribute a number of files together. It is easier to collect all the files into a (tape) archive file and distribute just that file. The whole archive file may be compressed to reduce its size, and the compression method can be seen from the file name. File names ending in .tar.gz or .tgz are gzip compressed; .tar.bz2 or .tbz2 are bzip2 compressed; or simply .tar are uncompressed.To extract,

Tape? What Tape?

The name of the program "tar" means tape archive. It was used to back up files by writing them sequentially to a tape device (which only allows sequential access). An ordinary file can also be used like a tape device, and it is common to create a tape archive (tar) file, which eases the distribution of a large number of files. One can then compress the whole archive using either gzip or bzip2 to reduce the amount of space required to store or transfer the archive.

The whole-archive compression scheme is often much more efficient than zip, which does per-file compression. However, unlike zip files, .tar files have to be accessed sequentially. Extracting only a selected number of files from the archive requires going through the whole archive once.

The "?xvf" tells the tar program what to do: 'z' means it's gzip compressed, 'j' means it's bzip compressed. 'x' means to extract, 'v' means to be verbose, and 'f' provides a file name (otherwise tar program reads from standard input). If the archive file contains a large number of files and you do not want to see any of them, remove 'v' from the command.

If you want to only look at the content of the archive file to see which files are in it,

The 't' character means to 'test' the archive.

If you want to create your own archive file, collect all the files into a directory. You may call the directory any name you want, but let's call it "the-dir" below.

Note that the convention is to derive the archive file name based on the directory name you created. The character 'c' means to create an archive.

You can find out more about the tar program in its man page, man tar.

The "tar" command is also available on Cygwin and Mac OS X.


Hope you find this useful.