ECF Unix Guide
ECF Unix Guide
1 Summary
This document provides information about how to log in to ECF, manipulate files and folders,
change permissions, compile programs without using an IDE, submit assignments, and manage
archives (using zip).
To avoid a grade of zero for your labs, please read carefully the section on submitting work.
Also, please read and follow the instructions on setting file permissions to avoid academic
offenses related to copying of your work.
Once you log in, you will likely be presented with some introductory messages and
announcements from ECF, and then you will get an xterm window. If you do not get the xterm
window you can start one by clicking on “Applications” then “System Tools”, and then
“Terminal”. The xterm window has the UNIX prompt: “pxxx.ecf%” (e.g., p120.ecf% or
p150.ecf %) indicating that the system is ready to accept your commands. In the remainder of
this document, we will use just “%” as the prompt and it will appear in front of all commands
you type, but of course you will not type it.
The UNIX file system is organized into a tree-like structure of directories. At the top of the
tree is the root directory of the system, designated by a “/”. Various system directories, named
“bin”, “local”, “lib”, “u”, etc are contained in the root directory. In turn, files and other
directories exist in each of these directories, as shown in Figure 1.
Your files and directories exist in the system under your home directory, which has the same
name as your login name (assumed to be ast for the remainder of this document). This is also
shown in Figure 1: your files are in the directory called ast, which exists in the directory
called 1T1, which in turn is in the directory called u that exists in /.
When you are logged into the ECF system, you are always associated with one directory or
another. The directory you are currently associated with is called your working directory. When
you first login, your home directory is your working directory. You can then change your
working directory using the cd command (explained later). At any time, you can find out what
your working directory is using the print-working-directory command, pwd, as follows:
% pwd
The command will print the name of your current working directory to the screen.
The location of a file or a directory is specified using a path through the tree. This path can be
full (or absolute) starting from the root of the tree “/”, or relative to the current directory, or to
some other directory. Thus, in Figure 1, the file a1.c can be specified in a number of ways,
assuming that your home directory is your working directory:
Note how ~ast specifies the home directory of user “ast” and how “~” by itself specifies
your home directory.
UNIX also provides two short-hands: “.” refers to the working directory, and “..” refers to the
parent directory of the working directory. These short-hands are useful in specifying relative
paths. For example, in Figure 1, if the working directory is aps105, then the file a1.c can also
be specified as ./a1.c, and the file sort.cc can be specified as ../sort.cc.
To obtain a listing of the names of all of the files in a directory, you can use the ls command:
% ls
Thus, using ls when you first login will print a list of all the files in your home directory.
In order to keep your files better-organized, you should create directories to hold files relating
to various subjects, courses, etc. For example, to create a new directory, called newdir, in your
home directory, use the mkdir command at the prompt:
% mkdir newdir
To work within a directory, you must use the change-directory command, cd, to make it your
working directory. The cd command has the following syntax:
cd dirlocation
where dirlocation is the location of the directory you wish to make your working directory,
specified using a path in the directory tree as described above. For example, in Figure 1, if your
home directory is the working directory, and you can make assign1 your working directory,
by typing:
% cd ece244/assign1
If your working directory is assign1, and you can make ece244 your working directory by
typing:
% cd ..
which takes you to the parent directory of your current directory; i.e., ece244.
It is important to always know what your current working directory is (using the pwd
command, described earlier), and how to move to subdirectories of it, or to move to its parent
directory.
Using UNIX commands, you can type commands to list your files, move, copy, delete, etc. For
example, the cp command is used to create a copy (duplicate) of a file. It has the following
syntax:
cp file1 file2
This takes a file named file1 and creates a new file called file2 that is an exact duplicate of
file1.
The mv command is used to move (or rename) a file, and has the following syntax:
mv file1 file2
This takes a file named file1 and creates a new file called file2 that is an exact duplicate of
file1. The original file1 is removed.
Be careful when using the rm command; files that you remove cannot be retrieved. Thus, it
pays to use the rm command with the “-i” option as follows:
rm –i file
The command will prompt for confirmation before the file is deleted.
Every UNIX file has an owner (and group) associated with it. You are the owner of all files and
directories in your home directory. As the owner you may choose to allow or deny others to
This prevents others from reading or searching through newdir. You can use the command on
any existing directory as well to protect it and all the files contained in it.
Three sets of permissions are set: user, group, and other (abbreviated above as u/g/o). The
permission types that can be granted are read, write, and execute. With this understanding, the
line above can be interpreted as followed: from group and other, subtract read/write/execute
privileges. To check that we have set the privileges correctly, use the ls command in its long (-
l) form to get more details:
% ls -l
The important part is the sequence of letters in the left column. It starts with ‘d’ to indicate that
the entry is a directory. Next, the rwx indicates that the user (tsa) can read, write, and execute.
Next, r-x indicates that members of the group “eceprof” can read and execute. The final r-x
means that others (not user “tsa nor group eceprof”) can read and execute. Normally execute
(‘x’) means that you are allowed to run the program if it’s a binary file or a script – in the case
of directory, execute actually means you can enter the directory to view its contents.
Note that your directories should read drwx------, and your files should read -rw------- such that
only the owner (you) can read them.
You can get more information on any UNIX command by using the man command (for manual
page). For example, type
% man ls
Indeed, if you wish to find out more about the man command, type:
% man man
Sometimes, it is more convenient to save multiple files into a single file, eg. for transmission
over e-mail or downloading via the web. The common ZIP program and file format for
Windows often accomplishes this, and has been implemented for UNIX as well.
Zip, which uses the extension .zip, stores and compresses multiple files and their folder
hierarchy within a single file, which can later be expanded. The command is zip to compress
and unzip to decompress
Some of the instructional material for the course is distributed this way. To get the files, simply
download the relevant zip file (here called foo.zip), place it in your ece244 folder, and run:
% unzip foo.zip
You can get more information by using the man command, or using the --help option.
4. Useful Tools
Please note that the functions of many tools listed below (editor, compiler, terminal,
debugger) can all be accessed from within the NetBeans Integrated Development
Environment (IDE) for greater simplicity and convenience. Lab materials assume that you
will be using NetBeans, though you may want to learn to use the individual components as
well.
As noted previously, the terminal and command line remain very important for Unix users.
While graphical user interfaces (GUIs) can be very handy, some things can only be done or
remain easiest for a skilled user to do from the command line. It is also useful when logging in
to computers remotely since text is much more compact to transmit than the instructions to
draw the GUI.
Another important use for the terminal is creating and testing shell scripts, which issue a series
of commands to automate certain repetitive tasks. By reducing the effort to accomplish
common tasks, effective terminal use and scripting can make you a more efficient programmer.
As you advance in your programming career, shell scripting is a very important skill to learn.
The submitece244f and exercise commands are so implemented – thus saving you
from typing a long and error-prone series of commands to submit your assignment.
Note that you may have several terminal windows open at a time. For instance, you may have
one for manipulating files, one for debugging, one for compiling, several running other jobs in
the background, etc.
In addition to source code files, programmers often have to read and write a number of text
files – for test cases, Makefiles, data, documentation, etc. Text editors come in many different
styles and are a matter of personal preference. What is important is that you find one that works
well for you, and with which you are highly productive. Popular instances include:
gvim A graphical and customizable editor. It has mouse support, but you can also
accomplish an incredible number of things from the keyboard. Very fast and
productive once you learn, but has a steep learning curve.
emacs An extremely stable, long-standing open-source project, Emacs is very customizable
and has numerous plugins but can be very hard to learn initially. It would be
considered a “classic” but still sees wide use today.
gedit Has many of the same basic features as gvim and emacs but may be less daunting to
learn
netbeans The NetBeans IDE includes a powerful text editor.
You can try out the various editors by typing their name at the command prompt. Features
commonly considered “must-have” include:
• syntax highlighting: the ability to recognize and highlight language key words
• search & replace (preferably with regular expressions)
• auto-indent
• line numbering
• jump to line number
• bracket matching (ability to highlight or jump to a matching bracket or parenthesis)
• folding (the ability to ‘collapse’ a function definition into a single line, or ‘expand’ it
back)
• syntax-error highlighting (find syntax errors before compiling)
• source browsing (navigation by variable/function/class definition)
• auto-completion
• refactoring (the ability to rename variables or methods in a syntax- and scope-aware
way across files)
4.3 Compiler
For our C++ programs to run, the source code file(s) must be compiled and linked with the
standard libraries. Compilation is the process of converting human-readable source code into
binary instructions that the computer can execute directly (machine code). The standard
libraries are a set of functions that all C++ implementations agree to provide. They include, for
instance, the provisions for allocating and de-allocating memory, accessing files, printing to the
terminal, standard math functions, and many more. Linking means taking function calls that
cannot be found within the source files, finding them in a library, and inserting a pointer to the
library file at the appropriate point.
To compile C++ code, we use the C++ frontend to the GCC compiler suite by typing g++.
While we will rarely use the compiler directly (see section on IDE below), it is worth being
familiar with what is happening “behind the scenes”. These commands will most commonly be
This will (if successful) produce an executable called a.out from the source file
hello.cpp. Generally when compiling for this course, we will add several other options as
listed below:
% g++ -std=c++11 -g –Wall hello.cpp –o hello
We can of course specify more source files (just add after hello.cpp), if more than one is
required for the program.
4.4 Debugger
A debugger is a tool that helps you find errors (i.e., “bugs”) in your programs. It does so by
allowing you to control the execution of a program. You can make the program stop when it
reaches a particular point in the code: this is called a breakpoint. While at a breakpoint, you can
examine the values of variables and inspect the state of the program. You can resume execution
from the breakpoint, possibly to another breakpoint, or step through one statement at a time in
your program. You can also set watches to view the values of variables you are interested in.
The use of a debugger can save you hours of frustration. While a debugger can never tell you
what a bug is, it can help you quickly determine where the bug is located in your code.
Combined with your knowledge of what the program should be doing, you can quickly locate
and fix your bug.
Learning to use a debugger does take some time. However, this is time well-spent. It certainly
beats debugging your code by staring at it for hours at a time, by randomly changing lines in
the code, or by inserting print statements all over the code.
For this course, we use the very powerful and extremely common GNU Debugger (GDB). It is
free, open-source, and available for many different computer platforms. The debugger is an
important tool that is covered in greater detail in a separate document. It is also used by the
NetBeans IDE.
For ECE244, we recommend and support a free IDE called NetBeans 8.2. It provides syntax
highlighting, source browsing, extensive help features, integration with the GCC compiler, and
integration with the GDB debugger. The provided interface is very visual and intuitive, making
it easy and worthwhile to learn.
There is a separate tutorial on getting, installing, and starting with NetBeans. We strongly
recommend that you use NetBeans unless you have a strong preference for another
environment.
Use your login and password to log onto the ECF system.
In your home directory, create a new directory for ECE244 (this course!) by typing the
following at the prompt:
% mkdir ece244
It is your responsibility to ensure that others cannot copy your work. If another student is
able to copy your work, and we determine that two submitted solutions stem from the same
source, then we have no option but to take action against both parties, since it is impossible
to tell who copied from whom.
Now use the ls command to see the new “ece244” directory in your list of files.
If you type the ls commend now, you will get no output, since the directory is currently
empty; i.e., has no files in it.
It is a good idea to have a separate folder for each course, and for each course folder to have a
separate sub-folder for each lab or assignment.
Note: You may also choose to use NetBeans (or another IDE) to create and compile your
code. In that case, you may safely skip the compiling section here.
You will use a simple example program whose only purpose is to print the message “Hello,
world!” to the screen. An initial version of this program is provided; simply download it into
your working directory (ece244/examples/helloworld) from
https://www.eecg.utoronto.ca/~yuan/teaching/ece244/lab1_examples/hello/
This will create an executable called hello. You can run it with by typing:
% ./hello
If your output does not match the expected output exercise will tell you. The exercise
command has the following syntax:
Let’s assume that our example program should be named hello, but, we mistyped our
compilation line as:
This will create a output file called Hello (note the uppercase “H”) when you compile it. If
you ran exercise with this file name, exercise will complain:
#############################################################
#############################################################
Running Testcase 1
#############################################################
#############################################################
-------------------------------------------------------------
<<<<<<<<< Comparing output to solution version 1 >>>>>>>>>>>>
Output does not match solution version 1
-------------------------------------------------------------
Running diff on program output and solution version 1 output
( < actual output vs > expected output )
=============================================================
1,2c1
< Hello
< world!
---
> Hello, world!
-------------------------------------------------------------
#############################################################
################# Summary for 1 test(s) #####################
#############################################################
#############################################################
#############################################################
#############################################################
Now fix the problem in the example program. Edit Hello.cpp and add the missing comma
on line 5. The result should look like this:
#############################################################
#############################################################
Running Testcase 1
#############################################################
#############################################################
-------------------------------------------------------------
#############################################################
################# Summary for 1 test(s) #####################
#############################################################
#############################################################
#############################################################
#############################################################
This time exercise tells you that the output was correct. You should use exercise for
every assignment, but you should also remember that passing all of its test cases does not
guarantee a perfect mark – the automarker uses some test cases that are not available to
exercise. You should always perform additional testing.
When you have completed and tested your program, you should submit it for marking using the
submit command. The submit command takes only one argument: the lab number.
~ece244i/public/submit assignment#
For example, to submit the files needed for your lab 1 to be marked, you would first make sure
all the necessary files are in your current directory (which for lab 1 are the hello.cpp file and
another file called convert.cpp). Then type:
~ece244i/public/submit 1
This command will search for all the files needed for the assignment in the current directory,
copy them to the course automarker directory, compile them, and run the exercise program
on them. If anything goes wrong in this process, submit will print an error message. You
should carefully examine the error message, take whatever corrective action is appropriate and
submit again. For example, if you had the hello.cpp program in the current directory, but
did not have convert.cpp in the directory, submit will complain:
% ~ece244i/public/submit 1
It is very important to read the output from submit very carefully and ensure there are
no errors. If submit cannot find the appropriate files or they do not compile correctly,
the automarker will not be able to run your program and you will receive 0 on the lab.
If we copy the convert.cpp file into the current directory and run submit again, submit
will succeed and produce output like this:
% ~ece244i/public/submit 1
Submitting files
Verifying submission
submitece244f -l 1
total 16
-rw-r----- 1 submit ece244f 2748 Sep 7 10:38 convert.cpp
-rw-r----- 1 submit ece244f 173 Sep 7 10:38 hello.cpp
Reading through the output above you can see that submit found all the necessary files,
compiled them successfully, and the resulting programs passed the exercise test cases. The
last line states that submission was successful; you should always check to make sure submit
prints this success message.
You can submit a lab as often as you like; the automarker will always mark only the last
submission.