COSC 102 Basics
Table of contents
What is this?
This page can be used as a reference for the basics of the COSC 102 course. It is not meant to be a complete reference, but rather a quick reference for the most common things you will need to know.
Keep in mind
This page is aimed at Unix/Linux computers. If you are using Windows, it’s more or less the same, but some of the syntax is slightly different like how Windows uses \
instead of /
for paths, and the file system structure is different. (e.g. C:\
is the root directory for Windows, but /
is the root directory for Unix/Linux. C:\Desktop
is the Desktop folder for Windows, but /home/<username>/Desktop
is the Desktop folder for Unix/Linux.)
Copying to/from the lab machines
-
scp
- Stands for Secure Copy. This command allows you to copy files from a remote server to your local computer or vice versa.
From your computer to the lab computers
1
|
scp <file> <netid>@tesla<number>.eecs.utk.edu:<destination>
|
From the lab computers to your computer
1
|
scp <netid>@tesla<number>.eecs.utk.edu:<file> <destination>
|
File |
NetID |
Number |
Destination |
The path to the file you want to copy |
Your UTK NetID |
Any number [0,30] |
The path to the location you want the file copied |
Note
The brackets <>
are placeholders. You don’t actually include them in the final command, just the contents within them
Common SCP FAQs/Errors
If you’re copying a file from your computer to the lab computers, you need to make sure one of the following is true:
- You are in the same directory as the file you want to copy
- You provide the full path of the file you want to copy
If you aren’t in the same directory as the file you want to copy, then you can use cd
to navigate to the directory that contains the file you want to copy. Or you can provide the full path to the file you want to copy. (e.g. scp ~/Desktop/file.txt
as opposed to scp file.txt
)
1
2
3
4
5
|
scp ~/Desktop/file.txt <netid>@tesla<number>.eecs.utk.edu:<destination>
# as opposed to
scp file.txt <netid>@tesla<number>.eecs.utk.edu:<destination>
|
If you are in the same directory, then the path you use for the file you want to copy is just the name of the file.
If you’re copying a file from the lab computers to your computer, then <file>
& <destination>
will always be the full path to the file you want to copy. (e.g. ~/cosc102/labs/lab1.cpp
for <file>
). You can however copy a file to your current directory by using .
as the destination.
1
|
scp <netid>@tesla<number>.eecs.utk.edu:~/cosc102/labs/lab1.cpp .
|
Compiling and Running C++ Programs
-
g++
- Stands for GNU C++ Compiler. This command is used to compile C++ programs. It is the default compiler for C++ programs on Unix/Linux systems. It is also the compiler we will be using in this course.
There are many ways to use the g++
command, but the most common way is to use the following syntax:
1
|
g++ -std=c++11 -o <binary> <source>.cpp
|
binary |
source |
The name of the binary (final executable) you want to create |
The name of the source file (your code) you want to compile |
Example
1
|
g++ -std=c++11 -o lab1 lab1.cpp
|
This will compile the lab1.cpp
file and create a binary called lab1
that you can run with
We use ./
to tell the computer that we want to run a binary in the current directory. If you want to run a binary in a different directory, you can use the full path to the binary without the .
Later in the course, you may be required to compile programs with extra flags that are specific to the lab. These flags will be provided to you in the lab instructions, but it’s paramount that you compile with these flags when required. Often times they affect the way your program runs, and if you don’t compile with the correct flags, your program may not run correctly, or it may not compile at all, which will net you a 0 on the lab without chance for appeal.
Other commands you should know
ls
-
ls
- Stands for List. This command is used to list the contents of a directory. It is often used to see what files are in a directory, or to see if a file exists in a directory. There are multiple flags you can use with ls
that alter the output
1
2
3
|
ls -a # lists hidden files/directories (ones that start with a . character)
ls -l # a more detailed list of the current directory. It shows things like file mod times, permissions, and more
ls <directory/file> # lists the contents of a specific directory/lists whether a file exists in the current directory, respectively
|
cd
-
cd
- Stands for Change Directory. This command is used to change the current directory. It is often used to navigate to a specific directory, or to navigate back to your home directory.
1
2
3
|
cd <directory> # changes the current directory to the directory specified
cd .. # changes the current directory to the parent directory of the current directory (moves back one)
cd ~ # changes the current directory to your home directory
|
pwd
-
pwd
- Stands for Print Working Directory. This command is used to print the current directory. It is often used to see what directory you are currently in.
mkdir
-
mkdir
- Stands for Make Directory. This command is used to create a new directory.
1
|
mkdir <new-directory-name>
|
cp
-
cp
- Stands for Copy. This command is used to copy a file or directory.
1
2
|
cp <source> <destination>
cp -r <source-directory> <destination-directory>
|
mv
-
mv
- Stands for Move. This command is used to move a file to a different location. You can also use it to rename a file.
1
|
mv <source> <destination> # moves source to destination or renames source to destination
|
rm
-
rm
- Stands for Remove. This command is used to remove files and directories.
1
2
|
rm <file> # removes a file
rm -r <directory> # removes a directory and all of its contents
|
touch
-
touch
- This command is used to create a new file.
cat
-
cat
- Stands for Concatenate. This command is used to print the contents of a file to the terminal.