ENGLISH
UC Davis CSIF and General
Computer Science Reference
Welcome, UC Davis Computer Science Student!
We’re glad you have this manual in your possession. You will find the answers to most of your beginning CS
and CSIF related questions here. This manual was created by students for you for the purpose of having a
comprehensive guide that all computer science students, new or old, can return to when necessary.
This manual was created by three UC Davis students: Jackson Gaydon, Harrison Espino, and Nicole Shuman in
the Fall of 2019. As students, we hope that any confusion that you may have when trying to become
accustomed to the computer science tools available at UC Davis may be cleared up by this manual, as some of
us were once in your shoes, too!
Best of luck from your Cool STEM Ingenuitive Friends (Jackson, Harrison, and Nicole) at UC Davis!
L - R: Jackson, Harrison, and Nicole
Introduction
The main purpose of this manual is to introduce basic computer skills required in UC Davis computer science
courses for incoming computer science students as well as a reference for continuing computer science
students.
This manual covers three main topics: locating and using the CSIF lab/computers, navigating Ubuntu (the
operating system used by the CSIF computers), and programming with the CSIF computers (in an Ubuntu
setting).
Chapter 1, which covers locating and using the CSIF lab/computers, helps CS students locate the CSIF
computer labs in the basement of Kemper Hall. With that, CS students can learn how to log on and log off the
various computers on UC Davis’ campus and how to log on and access the Terminal in Ubuntu. Lastly, CS
students can learn how to remotely connect to UC Davis’ virtual computers when they are unable to make it
to the CSIF labs.
Chapter 2, which covers navigating Ubuntu, gives CS students the essential tools needed to use Ubuntu
machines for CS classes. Navigation is done through entering commands into the terminal in Ubuntu, and the
manual covers the basic commands for adding, removing, and moving between directories. Additionally this
chapter covers the basics of two command-line text editors: Emacs and Vim.
Chapter 3, which covers programming with the CSIF computers, explains the process of compiling with C/C++
and interpreting with Python. It also provides examples of different compiling options, such as compiling and
linking as different commands and customizing the name of the compiled executable. The goal of this chapter
is to give you, the student, an understanding of how to transform your code to a program on an Ubuntu
system.
This manual also uses a few different formats for organization of the information presented:
● Pre-chapter vocabulary sections sorts the terms by importance/logical order of necessity, rather than alphabetically since some concepts build on each other. However, the glossary at the end of the
manual provides every vocabulary term in alphabetical order.
● Vocabulary terms are underlined in each chapter so that users are aware that they can find a definition within the manual.
● Chapter 1 is presented first as it is required to understand how to access the CSIF computers to use them, Chapter 2 follows so that users can learn how to navigate the Ubuntu operating system, and
Chapter 3 is last as you will likely need all of these skills to proceed with any programming and
compiling.
● References to outside sources are labeled with the chapter number, a period, and then the number of the reference in that chapter as well as being inclosed in brackets (Example: [3.2] refers to the second reference in Chapter 3).
(Continued)
● Chapter sections are labeled with the chapter number, a period, and then the number of the section in that chapter (Example: 2.1 refers to the first section within Chapter 2).
● Figures (images) are labeled with the word “Figure,” the chapter number, a period, and then the number of the figure in that chapter (Example: the first figure of Chapter 1 would be labeled Figure 1.1).
● Text that should be written in the command-line, outputted in the command-line, or written in a text editor as code are all highlighted in gray (Example: g++ myFile).
● Some screenshots will use green arrows and red circles to highlight significant areas.
Table of Contents
1
Chapter 3
2
Vocabulary
CSIF : Computer Science Instructional Facility is a campus organization that manages the computer labs in Kemper Hall. The CSIF Facility is located in Kemper Hall on the basement level. The CSIF offers
computer labs to UC Davis students either taking Computer Science course(s) or in the Computer Science/Computer Engineering field of study. Because all CSIF computer accounts are saved on a
server, accessing your account on one machine will give you access to the same files/home directory
that you had when working on another machine.
Computer Lab: Separate from the CSIF, these are facilities where students can access virtual computers, computer programs, and printers .
Kerberos: Kerberos login is a username and password assigned to everyone at UC Davis (staff, students, faculty). This username and password are how students will access computers around the UC
Davis campus.
Log On: Students use their UC Davis Kerberos Username and Password to access/use the computers in the computer lab.
Log Off: This is when a student ends their computer session in the computer lab and allows for another student to login and access the programs.
Remote Computing (Remote Login) : This is how a UC Davis student can log in and access the CSIF computers while away from the computer labs (at home, off-campus, etc.)
Linux : Linux is an open-source operating system.
Ubuntu : Ubuntu is a Linux operating system; also open source.
Home Directory: A home directory is the name usually given to a user on a network (or Linux variant) operating system. This directory is where a user stores all their personal information and files as well as
login scripts and user information.
Open Source : This refers to a computer program that has the source code available to the general public for any and all use or modification.
Secure Shell (SSH): Secure Shell is a cryptographic network protocol for operating network services securely over an unsecured network. Students will use SSH to remotely access CSIF computers.
Secure Shell File Transfer Protocol (SFTP): Secure Shell File Transfer Protocol is a network protocol used for secure file transfer over secure shell.
Terminal : The terminal is an interface in which you can type and execute text based commands.
3
1.1 Locating the CSIF at UC Davis:
The CSIF is the Computer Instructional Facility at UC Davis located in room 075 (there are additional computer
labs listed below). Some students know this facility as The Dungeon. This facility is in the basement level of
Kemper Hall. Kemper Hall is one of the many Engineering buildings housed on the UC Davis campus. Kemper
Hall is located at Bainer Hall Drive and Bioletti Way. Kemper Hall is also located next to Bainer Hall and Ghausi
Hall. The photo below the map is of Kemper Hall. From this perspective, Bainer Hall would be the big white
building to your left. Ghausi Hall would be down the bike path (Meyer Hall Bikeway) between Bainer Hall and
Kemper Hall.
Kemper Hall - Photo Credit: UC Davis College of Engineering (Flickr)
(Continued)
Figure 1.1
4
1. When you arrive at Kemper Hall, enter through the set of glass doors as shown by the green arrow.
Kemper Hall - Photo Credit: UC Davis College of Engineering (Flickr)
a. You are now in Kemper Lobby (The Bruce & Marie West Lobby). There should be a staircase to
your right-side as you enter through the doors. There will be desks and chairs to sit at.
b. The elevators are to your right near the staircase.
2. Walk straight ahead through the lobby until you see a hallway on your left side, go left down this
hallway.
3. Inside the hall, enter the third on the left for the stairs down to the basement of Kemper Hall. The sign
next to the door is labeled with a “Stairs” sign.
a. You will pass a drinking fountain on your left.
4. Exit the stairwell through the door to enter the basement level.
5. Enter through the first set of double doors on the left (the doors are usually already open).
a. If you’re facing in the direction of the doors and look behind you, you should see a blue AMCat
(Advanced Materials Science) Laboratory sign.
(Continued)
Figure 1.2
5
6. The CSIF Dungeon is located through the 3rd door on the right hand-side of the hall.
a. On the left-side of the hallway you will pass the restrooms and see the elevator sign ahead on
the left-side.
b. The Open Access Lab is in Room 075. Room 061 and 071 also contain CSIF computers. If the
room is locked, call CSIF: (530) 754 -8249.
Figure 1.3
6
1.2 Logging On to the UC Davis Computers:
1.2.1 Regular UC Davis Computers (Windows/Macintosh)
1. If the computer is not turned on, turn it on.
a. A screen will appear that will direct the student to log in .
2. Select the login button.
3. Use your Kerberos username and password to sign on and access computer programs.
1.2.2 Ubuntu Computers in CSIF
1. Turn the computer on if it is off.
a. The computer might be on, but in sleep mode; wiggle the mouse to check.
b. If the computer is still not on, try another computer in the lab.
c. If none of the computers are turned on, call CSIF: (530) 754 -8249.
d. If the computer is on, a home screen will appear.
(Continued)
Figure 1.4
7
2. At the home screen, press the spacebar to bring up the Ubuntu startup screen.
a. The Ubuntu startup screen will appear with a username prompt.
3. Log in using your Kerberos username, then select next.
4. Enter your Kerberos password.
a. The screen will go black while the computer loads and then the desktop screen will
appear.
Figure 1.5
8
1.3 Logging Off of the UC Davis Computers:
1.3.1 Regular UC Davis Computers (Windows)
1. Save and close any open documents/projects.
2. On the bottom left-hand of the screen on the toolbar, select the Windows icon.
a. A side-bar menu appears. On the menu, select Account icon.
b. Select “Sign Out.”
i. If you did not save your work, you will be prompted to do so before logging out .
Figure 1.6
Figure 1.7
9
1.3.2 Regular UC Davis Computers (Macintosh)
1. Save and close any open documents/projects.
2. On the top left-hand side of the screen on the toolbar, select the Apple icon.
a. A menu appears. Select “Log Out .”
i. If you did not save your work, you will be prompted to do so.
Figure 1.8
Figure 1.9
10
1.3.3 Ubuntu Computers in CSIF
Note: There are many options for logging out , this is just one of them.
1. Save and close any open documents/projects.
2. On the top right-hand toolbar, select the Arrow icon.
a. A menu appears. Select “Log Out .”
Toolbar Screen Capture: https://www.howtogeek.com/wp-content/uploads/2014/05/04_selecting_log_out.png
i. If you did not save your work, you will be prompted to do so.
Figure 1.10
Figure 1.11
11
1.4 How to Access the Terminal on Ubuntu
The computer should be turned on and the desktop screen should be showing.
1. On the left-hand side of the screen, select the Squares icon.
a. A tiled menu with various icons will appear. A search bar will also appear above these
icons.
(Continued)
Figure 1.12
Figure 1.13
12
3. Type “ Terminal” into the search bar.
4. Select the Terminal icon.
a. The Terminal screen will appear and you are ready to type in a command.
i. Note: You will begin in the home directory.
(Continued)
Figure 1.14
Figure 1.15
13
Figure 1.16
14
1.5 Remote Log On to the UC Davis Computers:
Remote login allows you to connect to the UC Davis host computers via a network or direct
telecommunications link, and to interact with the host computers as if you were directly connected to
that host computer. The command SSH (secure shell) is used in order to gain remote access to a CSIF
computer and its files. SFTP (SSH File Transfer Protocol) is a process expanded from SSH that allows the
transfer of files from one computer to another across the internet.
There are 60 computers that you can remotely connect to. To check the status/availability for these
computers visit this link:
http://iceman.cs.ucdavis.edu/nagios3/cgi-bin/status.cgi?hostgroup=all
Green (UP) = Computer is Available
Red (DOWN) = Computer is Unavailable
1.5.1 SSH Remote Login for Windows Computers via PuTTY
PuTTY is a free program that allows for SSH Connection.
To download PuTTY, click on the following link:
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
Once PuTTY has been successfully installed, running the application will open up a PuTTY
configuration window.
(Continued)
Figure 1.17
15
In the box underneath the title “Host Name (or IP address)”, enter the address of the
computer you would like to connect to and click “Open” on the bottom right. The image
below shows what you would type in to connect to Computer 23. Additionally, ensure
that the box underneath the title “Port” is set to 22 and SSH is selected under
“Connection type”.
If a window appears that says “The server’s host key is not cached in the registry”, click
“Yes”.
(Continued)
Figure 1.18
16
When a terminal window appears prompting you to log in, type in your kerberos ID.
After pressing enter, you will be prompted to enter your Kerberos password.
Figure 1.19
Figure 1.20
17
1.5.2 SSH Remote Login for Macintosh Computers
Open the terminal application (Press ⌘ + Spacebar and type “Terminal”). Once the
terminal is opened, refer to the Log On instructions for Debian Linux below.
1.5.3 SSH Remote Login with Linux
Enter the command “ssh” into the terminal followed by your Kerberos username “@”
the ip address of the computer you wish to connect to:
ssh kerberosid@pc23.cs.ucdavis.edu
This would be used to connect to CSIF computer 23 using the Kerberos username of
“kerberosid.” After pressing enter, you will be prompted to enter your Kerberos
password.
Debian Linux
Enter the command “ssh” into the terminal followed by your Kerberos username “@”
the ip address of the computer you wish to connect to:
ssh kerberosid@pc23.cs.ucdavis.edu
This would be used to connect to CSIF computer 23 using the Kerberos username of
“kerberosid.” After pressing enter, you will be prompted to enter your Kerberos
password.
Arch Linux and Minix
This process is the same as for Debian Linux, though you may need to include the
following command to install SSH capability first:
Arch Linux: pacman -S openssh [1.1]
Minix: pkgin install openssh [1.1]
18
1.5.4 File Transfer (SFTP) for Windows
The easiest way to use SFTP on Windows is to use the free software FileZilla. Download and
install FileZilla, then run it. You will see a window that looks like this:
Logging On to CSIF Computers Using SFTP
Enter the IP address of the desired CSIF computer under the “Host” textbox. Then, enter
your Kerberos username under the “Username” textbox as well as your Kerberos
password under the “Password” textbox. Finally, ensure the “Port” is the number 22.
Press “Quickconnect.” You will then be logged in. Go to the toolbar and select
Server->Disconnect or press Ctrl+D to logout.
Figure 1.21
Figure 1.22
19
Move Files from Local Machine to CSIF Computer
Once connected to the CSIF computer, click and drag folders/directories and/or files
from the left-hand file navigator to the right-hand file navigator. You will receive a
Windows notification when the transfer is complete.
Figure 1.23
20
Move Files from CSIF Computer to Local Machine
Once connected to the CSIF computer, click and drag folders/directories and/or files
from the right-hand file navigator to the left-hand file navigator. You will receive a
Windows notification when the transfer is complete.
1.5.5 File Transfer (SFTP) for Macintosh
Open the terminal application (Press ⌘ + Spacebar and type “Terminal”) Once the
terminal is opened, refer to the File Transfer instructions for Ubuntu.
1.5.6 File Transfer (SFTP) for Ubuntu
Log Onto the CSIF Computers Using SFTP
Open the Ubuntu terminal. Run the “sftp” command with your Kerberos username @
the IP address of the desired CSIF computer as the only argument. Example:
sftp kerberosusername@pc23.cs.ucdavis.edu
Then, enter your password when prompted. Use the command “quit” to logout .
Figure 1.24
21
Move Files from Local Machine to CSIF Computer
Once logged in, use the sftp command “put” followed by the path to the file to copy (on
the local machine) and then the path to the destination (on the connected machine):
put <Path To Local File> <Path To Destination File>
Where <Path To Local File> is the path to the file on the local system and <Path To
Destination File> is the path to where you want the file to be stored on the destination
system (remote system).
For example, if you wanted to place a file named “test.txt” from your local machine’s
home directory to the home directory of your CSIF account (naming it “remotetest.txt”),
you would type the following command (where kerberosid is your Kerberos username):
put test.txt remotetest.txt
Retrieve Files from Connected CSIF Computer
Once logged in, use the sftp command “get” followed by the path to the file you wish to
receive on the connected machine and then the path to the destination (on the local
machine):
get <Path To Remote File> <Path To Local Destination File>
Where <Path To Remote File> is the path to the file on the remote system and <Path To
Local Destination File> is the path to the desired destination on the local file system.
For example, if you wanted to place a file named “remotetest.txt” from your CSIF
accounts’ home directory to the home directory of your local machine (naming it
“localtest.txt”), you would type the following command (where kerberosid is your
Kerberos username):
get remotetest.txt localtest.txt
22
23
Chapter 3
24
Vocabulary
Operating System: The software that allows you and any applications you install to communicate with your computer. Windows, Mac OS, and Ubuntu are all examples of operating systems. The CSIF
computers use Ubuntu, which is a Linux operating system.
Command Line: The area for typing commands that the computer will execute. The command line can be accessed on the CSIF computers by opening the “Terminal” application.
Directory: A location on the computer’s hard drive that can contain computer files or other directories.
Parent Directory : A directory’s parent directory is the directory directly above it. In other words, directory “A” is the parent directory of directory “B” if A contains B.
Computer File: a collection of data that belongs to each other on a computer.
25
2.1 Basic Ubuntu Command Line/Terminal Controls:
Before learning any commands, it is important to understand the concepts of navigating through an
Ubuntu machine. Navigation through the command line consists of creating, deleting, or moving
between directories. Directories are locations on the computer’s hard drive that can contain computer
files or other directories. The directories in a computer are often expressed as diagrams, like this one,
where each directory contains all the objects connected to it from below.
In this example, the directory “Home” contains a computer file named “Book” and a directory named
“Pictures of Animals”. One directory can contain multiple other directories, each of which can also hold
directories, like branches on a tree. The first directory- represented here by “Home”, the highest
directory in the diagram- is known as the “Root”, and it contains every file on the computer.
While a terminal is opened, it is always inside of a directory known as its “working directory.” When
entering commands, the user does not have to specify the location of any files or directories inside the
working directory. For example, if the terminal’s working directory was “Dogs” and the command to
remove the computer file “Dog2” would be:
rm Dog2
If the terminal’s working directory was “PicturesofAnimals” instead, the command would be:
rm Dogs/Dog2
These commands as well as others important to navigation are explained below.
Figure 2.1
26
Sections for these instructions represent individual commands that are not necessarily used in the
given order.
Print the Directory (pwd)
The terminal always starts in the home directory, type the command
pwd
To make the terminal print your working directory. Right now, it should show the following
message in the terminal
/home/student
where student is your Kerberos login username
View Files (ls)
Type in the command
ls
To list all files and directories inside the current directory. If this is your first time using the CSIF,
there won’t be any files, so it will look like nothing happened.
Make Directories (mkdir)
To make a directory inside the current directory, type
mkdir <name>
Where <name> is replaced by the name of the directory. For example, to create a directory
named “dogs”, type
mkdir dogs
Change Directories (cd)
To change the current directory to another directory, type
cd <name>
Where <name> is replaced by the name of the directory. You can now have the terminal change
working directories to our new directory. Type
cd dogs
to move into the dogs directory. If you type pwd, it will now look like this
home/student/dogs
In the command line, typing “.” in place of a directory is a shortcut to refer to the working
directory. For example, if you wanted to move into a directory named “NewDirectory” inside of
the current directory, you would type
(Continued)
27
cd ./NewDirectory
Typing “..” in place of a directory is a shortcut to refer to the parent directory.
To return to the parent directory, type
cd ..
Remove Directories (rmdir)
Directories can be permanently deleted by typing
rmdir <name>
Where <name> is replaced by the name of the directory. To delete the dogs directory created
in this example, type
rmdir dogs
Directories can only be removed if they are empty.
Create Files (touch)
Files can be created inside the working directory by typing
touch <name>
Where <name> is replaced by what you want the file to be named. For example, typing in
touch file.txt
Will create a file in your working directory named “file.txt”. Be sure to include the file extension
(in this case .txt) when creating files. Now, if you type ls the terminal should list the name of the
file.
Remove Files (rm)
Files can be deleted by typing
rm <name>
Where <name> is replaced by the name of file. To delete the file created above, type
rm file.txt
You will be asked to confirm your decision to delete the file. To confirm or cancel, type either
y
Or
n
respectively.
28
2.2 Command-Line Text Editor Basics:
Either because you prefer using the command-line or you are logging in remotely, sometimes
you might be using a text editor that does not have a graphical user interface (GUI). In this case,
Emacs and VIM are your new best friends. They are popular command-line-compatible text
editors that are well-suited for the command-line. This section will cover the most important
aspects of using these text editors.
Emacs Basics
Open a Text File with Emacs
Use the command “emacs” followed by the name of the text file that you would
like to edit:
emacs <file name>
Where <file name> is the name of the file to open.
For example, to open “MyFile.txt,” use the following command:
emacs MyFile.txt
Navigate a Text File in Emacs
To navigate a text file in Emacs, use the arrow keys to move around the screen.
Typing characters will work similar to any other text editor in that they will
appear wherever the cursor is displayed. Backspace and delete work as
expected: backspace will delete the character before the cursor and delete will
delete the character at the cursor.
Save a Text File in Emacs
1. Press and hold the Control key.
2. While pressing control, quickly press and release the “x” key.
3. While still pressing control, quickly press and release the “c” key.
4. Release the Control key.
29
Undo a Change to the Text File in Emacs
1. Press and hold the Control key.
2. While pressing control, quickly press and release the “x” key.
3. Release the Control key.
4. Quickly press and release the “u” key.
Quit Emacs
1. Press and hold the Control key.
2. While pressing control, quickly press and release the “x” key.
3. While still pressing control, quickly press and release the “c” key.
a. If you get a notification asking if you wish to save the file, press “y” to
save it or “n” to close without saving.
b. If you pressed “n,” you may have to type “yes” to confirm this
operation.
4. Release the Control key.
Vim Basics
Open a Text File in Vim
To open a file in Vim, type
vim <file name>
Where <file name> is replaced by the name of the file you would like to open. F
for example, For example, to open “MyFile.txt,” use the following command:
vim MyFile.txt
Navigating and Editing in Vim
The cursor (represented by the small grey square) can be moved using the arrow
keys. To begin editing, press the “i” key once to enter insert mode. While in
insert mode, letters typed will be inserted to the left of the cursor. To exit insert
mode, press the “esc” key once.
30
Undo and Select Larger Portions in Vim
To undo the last operation, press the “u” key once.
Press the “v” key once to enter visual mode. Visual mode will highlight the text
from the position of the cursor when visual mode was entered. Visual mode is
exited using the “esc” key. The highlighted text can be deleted using the “del”
key.
Quit Vim
There are two ways to quit Vim. To save all work and exit, type
:wq
And press enter. To quit without saving, type
:q!
And press enter. Vim will exit WITHOUT WARNING, so be sure you do not want
to save if you enter this command.
31
32
Chapter 3
33
Vocabulary
File Extension : an optional addition to the name of a computer file that occurs after the last period in the name. It is used by programs that open computer files to discern how the data of the file should be handled. Examples are txt (text files), png (image files), and pdf (PDF files).
Compiler : a computer program that converts computer files into another computer program. It does this by evaluating a computer file written in a programming language and converts the statements and structures into instructions for the machine. It then saves those instructions as a computer program.
Interpreter : a computer program that evaluates each instruction in a computer file and translates it into computer instructions.
Computer File: a collection of data that belongs to each other on a computer.
Computer Program: a series of instructions for the computer to execute that is stored in a computer file for the purpose of manipulating the computer’s memory, hard drive, and other hardware components.
Argument: some sort of input, usually in text, that the user gives to a program upon running it that the program may or may not use/manipulate.
Programming Language: a series of instructions and logic structures that a programmer uses to create a text document that is then used by a computer compiler or interpreter to create a computer program.
Text Editor: a computer program that operates on computer files and saves a user’s input to the computer file. Examples of text editors include Notepad, Notepad++, and Microsoft Word.
Interactive Development Environment (IDE): a computer program that operates on computer files and takes in a programmer’s input similar to the function of Microsoft Word. Unlike Word, there are
generally less formatting options, certain keywords may be differently colored, it often includes
tab-to-complete suggestions based on previously written words (similar to Autocorrect on iOS), and
typically has functionality to invoke a compiler and run the computer program within the user interface.
Debug: the process of finding, understanding, and fixing errors in the behavior of a computer program.
Debugger: a computer program that helps the programmer debug by allowing the pause of execution and displaying the values of computer memory locations during runtime.
Pseudocoding: the process of roughly outlining in partial code the steps that a computer program must take to create its desired output.
34
3.1 Introduction to Creating Programs
Creating programs effectively involves five main stages: planning, writing, compiling, running, and
debugging. The programmer almost always jumps around this list and repeats steps as issues arise or
new ideas are formulated.
● Plan : this involves the programmer ensuring their understanding of the specifications desired
such as inputs, outputs, time effectiveness, and space effectiveness. Pseudocoding is
encouraged.
● Write : To write a program, the programmer must choose their IDE and create the computer
files that are necessary for the project. Then, the programmer writes the computer program in
the chosen programming language.
● Compile : to compile the program, the programmer must have a compiler which can be
executed from their IDE, or externally from a command-line. IDEs usually come with a compiler
that is executed at the click of a button, while command-line compiling might require the
programmer to supply the specific location of the computer files to compile as well as where to
save the new computer program. If using an interpreter rather than a compiler , the
programmer would skip this stage.
● Run : to run the program, the programmer executes the outputted program as they would any
other software application. If the programmer is using an interpreter, they would have to make
sure that they open the file with an interpreter computer program. The interpreter evaluates
the computer file and line-by-line converts each instruction to computer instructions that the
computer executes.
● Debug: based on the results of running the program, the programmer will debug the program
by using a debugger or adding print statements to check the results of certain values at certain
points in the program’s runtime. This is often a combination of the previous multiple stages.
Having understood the program’s requirements, written the actual code, compiled the program, and
tested it by running it and debugging when necessary, the program should be complete.
35
3.2 Run an Existing Program in the Command Line:
You may run a program using two different methods:
● Enter the name of the program in the command line while your current working directory is the
directory that the program belongs to.
○ Example: to run a program named “test” located within a directory named “folder” that
is in your home directory (working directory should be /home/kerberosid/folder/ where
kerberosid is your Kerberos username), enter the following command.
test
● Enter the path to the program ○ Example: to run a program named “test” located within a directory named “folder” that
is in your home directory, enter the path to the program.
/home/kerberosid/folder/test where kerberosid is your Kerberos username.
Alternatively, as previously mentioned, if you are located in your home folder you could
use “.” to indicate your current working directory.
./folder/test
36
3.3 Compile in C++:
Once a computer file written in C++ is ready for testing, it may be compiled by a compiler into a
computer program that can be run on the machine. Compiling a program, while possible with just one
command, internally takes multiple steps: preprocessing the file, compiling the file into object files,
assembling and linking these object files into a computer program.
3.3.1 Compile in One Command:
Invoke the C++ compiler to do all of these in one step.
Use the command “g++” along with the required argument of the name of the file to compile.
For example, if there was a file written in C++ named “MyProgram.cpp,” it could be compiled
using the following command:
g++ <path to file>
Where <path to file> is the path to the file you wish to compile.
For example, to compile a file named “MyProgram.cpp,” use the following command:
g++ MyProgram.cpp
It will then save this computer program and name it “a.out.” Run the computer program by
invoking its name or path in the command-line [3.1]:
./a.out
3.3.2 Customize the Program’s Name:
Choose the name of the program and simply append the “-o” argument at the end of the
command, followed by the required sub-argument indicating the desired name. Run the
following command to save the previous program as “runThis.exe”:
g++ <path to file> -o <path to save program>
Where <path to file> is the path to the C++ file and <path to save program> is the path to the
executable program that you wish to create.
(Continued)
37
For example, to create an executable program named “runThis.exe” from a file named
“MyProgram.cpp,” use the following command:
g++ MyProgram.cpp -o runThis.exe
It will then save this computer program and name it “runThis.exe.” Run the computer program
by invoking its name or path in the command-line [3.1] :
./runThis.exe
3.3.3 Compile Multi-File Dependent Projects:
Simply add dependent file names after the main file’s name before the “-o” argument to
compile a multi-file project:
g++ <path to file> <path to file 2> <path to file 3> <path to final file>
Where <path to file>, <path to file 2>, <path to file 3>, and <path to final file> are all paths to
files to compile. There is no set amount of files you can compile together. You can compile four
files together, three files, seven files, etc.
For example, to compile “MyProgram.cpp,” “Dependency1.cpp,” and “Dependency2.cpp”
together, use the following command:
g++ MyProgram.cpp Dependency1.cpp Dependency2.cpp
It will then save this computer program and name it “a.out.” Run the computer program by
invoking its name or path in the command-line [3.1]:
./a.out
3.3.4 Compile and Link Object Files Separately:
Use the “-c” option after “g++” to only compile each file individually into object files:
g++ -c <path to file>
Where <path to file> is the path to the C++ file.
(Continued)
38
For example, to compile a file named MyProgram.cpp, use the following command:
g++ -c MyProgram.cpp -> generates “MyProgram.o”
This will not link them, only compile them.
After generating the object files, link them together using the g++ command on the objects:
g++ MyProgram.o -> generates “a.out”
It will then save this computer program and name it “a.out.” Run the computer program by
invoking its name or path in the command-line [3.1]:
39
3.4 Pass Arguments to C++ Programs:
3.4.1 Accept Arguments in Code
To pass arguments to your C++ program, you must write your “main” function to accept them.
To do so, ensure that your “main” function takes in the following arguments:
● int argc
● char ** argsv
Your main function declaration should look like this:
int main(int argc, char ** argsv)
To access an argument passed in from the command line, you can easily do so by referencing
argsv at any index between 0 and argc - 1:
cout << argsv[1] << endl; // works when argc > 1
Note: argsv[0] is always the command used to run the called program.
A sample program that prints all arguments passed to it can be observed in Figure 3.1:
Figure 1.11
Figure 3.1
40
3.4.2 Pass Arguments in the Command Line
Execute the program as usual, but after referencing the name of the program, insert the text
arguments that you wish to give the program in sequential order. For example, if you wanted to
program in Figure 1 to print “Test,” you could run the following command:
./a.out Test
Output:
./a.out
Test
Note: It also printed “./a.out” because the program prints argsv[0].
41
3.5 Compile in C:
Compiling in C is very similar to C++. Reference the instructions Compile in C++ with the following
change to compiling:
Compile:
Instead of using “g++,” use the command “gcc” to run the C compiler:
gcc <path to file>
Where <path to file> is the path to the C file.
Unlike C++ files that use the file extension of “cpp,” use the extension of “c” for C files
(example: “MyProgram.c”).
It will then save this computer program and name it “a.out.” Run the computer program by
invoking its name or path in the command-line [3.1]:
./a.out
42
3.6 Interpret in Python:
Once a computer file in Python is ready for testing, you may run it using the Python Interpreter. Since
the CSIF computers include an interpreter for Python, there is no need to compile a program written in
Python; you may simply just run it using the interpreter.
Run the Interpreter:
Use the command “python3” in the terminal followed by the path to the python file that you
wish to run:
python3 <path to file>
Where <path to file> is the path to the python file.
Python files should use “py” as their file extension (example: “MyProgram.py”).
43
Glossary
Argument: Some sort of input, usually in text, that the user gives to a program upon running it that the program may or may not use/manipulate.
CSIF : Computer Science Instructional Facility is a campus organization that manages the computer labs in Kemper Hall. The CSIF Facility is located in Kemper Hall on the basement level. The CSIF offers
computer labs to UC Davis students either taking Computer Science course(s) or in the Computer Science/Computer Engineering field of study. Because all CSIF computer accounts are saved on a
server, accessing your account on one machine will give you access to the same files/home directory
that you had when working on another machine.
Command Line: The area for typing commands that the computer will execute. The command line can be accessed on the CSIF computers by opening the “Terminal” application.
Compiler : A computer program that converts computer files into another computer program. It does this by evaluating a computer file written in a programming language and converts the statements and structures into instructions for the machine. It then saves those instructions as a computer program.
Computer File: A collection of data that belongs to each other on a computer.
Computer Lab: Separate from the CSIF, these are facilities where students can access virtual computers, computer programs, and printers .
Computer Program: A series of instructions for the computer to execute that is stored in a computer file for the purpose of manipulating the computer’s memory, hard drive, and other hardware components.
Debug: The process of finding, understanding, and fixing errors in the behavior of a computer program.
Debugger: A computer program that helps the programmer debug by allowing the pause of execution and displaying the values of computer memory locations during runtime.
Directory: A location on the computer’s hard drive that can contain computer files or other directories.
File Extension : An optional addition to the name of a computer file that occurs after the last period in the name. It is used by programs that open computer files to discern how the data of the file should be handled. Examples are txt (text files), png (image files), and pdf (PDF files).
Home Directory: A home directory is the name usually given to a user on a network (or Linux variant) operating system. This directory is where a user store all their personal information and files as well as
login scripts and user information.
44
Interactive Development Environment (IDE): A computer program that operates on computer files and takes in a programmer’s input similar to the function of Microsoft Word. Unlike Word, there are
generally less formatting options, certain keywords may be differently colored, it often includes
tab-to-complete suggestions based on previously written words (similar to Autocorrect on iOS), and
typically has functionality to invoke a compiler and run the computer program within the user interface.
Interpreter : A computer program that evaluates each instruction in a computer file and translates it into computer instructions.
Kerberos: Kerberos login is a username and password assigned to everyone at UC Davis (staff, students, faculty). This username and password are how students will access computers around the UC
Davis campus.
Linux : Linux is an open-source operating system.
Log In / On: Students use their UC Davis Kerberos Username and Password to access/use the computers in the computer lab.
Log Off: This is when a student ends their computer session in the computer lab and allows for another student to login and access the programs.
Navigation : Navigation through the command line consists of creating, deleting, or moving between directories. Directories are locations on the computer’s hard drive that can contain computer files or
other directories. The directories in a computer are often expressed as diagrams, where each directory
contains all the objects connected to it from below.
Open -Source: This refers to a computer program that has the source code available to the general public for any and all use, or modification.
Operating System: The software that allows you and any applications you install to communicate with your computer. Windows, Mac OS, and Ubuntu are all examples of operating systems. The CSIF
computers use Ubuntu, which is a Linux operating system.
Parent Directory : A directory’s parent directory is the directory directly above it. In other words, directory “A” is the parent directory of directory “B” if A contains B.
Programming Language: A series of instructions and logic structures that a programmer uses to create a text document that is then used by a computer compiler or interpreter to create a computer program.
Pseudocoding: The process of roughly outlining in partial code the steps that a computer program must take to create its desired output.
Remote Computing (Remote Log On): This is how a UC Davis student can login and access the CSIF computers while away from the computer labs (at home, off-campus, etc.)
45
Secure Shell (SSH): Secure Shell is a cryptographic network protocol for operating network services securely over an unsecured network. Students will use SSH to remotely access CSIF computers.
Secure Shell File Transfer Protocol (SFTP): Secure Shell File Transfer Protocol is a network protocol used for secure file transfer over secure shell.
Terminal : The terminal is an interface in which you can type and execute text based commands.
Text Editor: A computer program that operates on computer files and saves a user’s input to the computer file. Examples of text editors include Notepad, Notepad++, and Microsoft Word.
Ubuntu : Ubuntu is a Linux operating system; also open source.
46
References
[1.1] http://csifdocs.cs.ucdavis.edu/about-us/csif-general-faq
[3.1] https://www.geeksforgeeks.org/compiling-with-g-plus-plus/
47
Additional Resources:
CSIF Website: http://csifdocs.cs.ucdavis.edu/ CSIF Machine Status Website: http://iceman.cs.ucdavis.edu/nagios3/cgi-bin/status.cgi?hostgroup=all FileZilla Website: https://filezilla-project.org/ PuTTY Website: https://www.chiark.greenend.org.uk/~sgtatham/putty/
48