Lab: The Command Line

Learning Objectives


There are several different environments that you can work in to complete the assignments in this course. These environments are described as follows.

1) On a Lab Machine

The lab rooms (JB 358 nd 359) contain computers that are running the Linux operating system. You can simply log into one of these computers and work in the lab.

To use these computers, The lab instructor will give you a username and password or will explain how to get one. You can also log into computers in JB 358 with the same username and password.

2) On a Lab Machine but Remotely

You can also work on a lab computer from a remote computer. You have 2 choices for working on a lab machine remotely.

3) In a Cloud9 Workspace

You can work in a Cloud9 workspace, which you access through a website.

This is the first time for me to use this in this course, so this is experimental. However, I believe it to be an excellent choice and hope to standardize on this in future quarters. The following instructions explain what you need to do in case you want to try this.

4) In OS X

You can easily use a Mac to do the assingments in this course. However, you will need to install Xcode to have access to a C++ compiler. You can get XCode for free from the App Store.

On a Mac, I recommend that you use work from the command line in the way that I demonstrate in lecture rather than using the graphical user interface of XCode. However, it is good to learn the XCode graphical interface, so you have the time and interest, I encourage you to do this.

5) In Linux

If you have access to a computer that runs the Linux operating system, you will need to install the GNU C++ compiler if not already installed. Try the following command to find out.

c++ -v

If the above command is not found, then you need to install the GNU C++ compiler. How you do this depends on your system. If you have a GUI-based package manager, you can use that. If your system uses yum, then run the following.

yum install gcc-c++

If your system uses apt-get, then run the following.

apt-get install gcc-c++

There are also other possible ways to install the Gnu C++ compiler, which are not covered here.

6) In Windows

Doing the work in this course on a Windows computer is more complicated than the other options. If you do not want to learn Visual Studio or other integrated development environment (IDE), then I recommend you either 1) work on the lab computers, 2) access a lab computer from Windows using SSH, or 3) use Cloud9 as described above.

To do the assignments in this course directly on a Windows computer you need to install an IDE. There are several free alternatives. One alternative is to use the student edition of Visual Studio called Visual Studio Express (for desktop development). Another alternative is to use an open source development system such as CodeBlocks or other system.

Learn the Command Line Interface

Complete the interactive Codecademy command line tutorial. You will need to create a free account with Codecademy for this purpose.

One helpful feature of the terminal window is called command completion. If you press tab in the command line, the system will try to complete what you are typing by looking for a matching filename.

Another helpful feature is called command history. This feature allows you to access a record of commands that you previously entered. Use the up and down arrow keys to scroll through the command history. Press enter at any previously entered command to run it again.

Learn How to Use a Text Editor

Practice creating files with one of the text editors available on your system.

If you are working directly on a lab computer (not through SSH), then you can run programs that create windows, such as the text-editor called gedit. However, if you are working on a lab computer remotely (through SSH), then you can not run programs that create windows, because the ssh program only gives you a text-based interface to the remote system. In this case, you need to use a text editor that runs inside a console window, such as vi or nano.

A program that creates a window is said to have a graphical user interface (GUI). In the early days of computers, GUIs did not exist, so all interaction with the computer was through character-based interfaces.

Nano is easier to understand than vi, but vi is the traditional text editor that comes pre-installed on practically all UNIX-like operating systems. For this reason, vi is an important tool for system administrators.

Experience Working with C++

This section explains how to write, compile and run a simple C++ console program from the Linux command line. When the program runs, it prints hello.

Create a file named hello.cpp with the following contents.

#include <iostream>

using namespace std;

int main(int argc, char * args[]) {
    cout << "hello\n";

From a terminal window, run the following command to compile hello.cpp.

c++ hello.cpp

The above command generates an executable file named a.out. To run this file, issue the following from the command line.


Modify the source code in hello.cpp so that it displays Hello, Alice. Test that your changes produce an executable file that runs as expected.

Submit Your Work

To complete this lab, send an email to the teaching assistant that includes a link to your Codecademy profile and the URL of your Cloud9 cse201 workspace. If you are not using Cloud9, then send the hello.cpp file as an attachment to the email. Also, CC me on this email. In general, when you send emails to the teaching assistant, you should always CC me.

For full credit on this assignment, your profile should list Learn the Command Line as a completed skill.