Contents

Introduction to Linux - CPSC 213

Introduction

For the fall term of 2020, I will be a TA for CPSC 213, an introduction to Computer Systems.

I have TAed this course three times before, and since this term will be the first fall term the course is held online, I have been thinking hard about the troubles that students may face, and what I could do as a TA to make it easier.

CPSC 213 is typicaly the first time students are expected to use a Linux development environment. This is often overwhelming for students, especially the “terminal” side of things. Before CPSC 213, students are used to using an IDE, which would contain the compiler, the debugger, the code editor and everything else that the student would need. Now however, students have to start using Linux environments, which includes interacting with a command line.


I decided to take a crack at creating some material that can help the students setup faster, and overall have a nicer experience. This blog post is meant for them, so if you’re one of the students taking CPSC 213, this is for you! For everyone else, feel free to read on if this is useful to you 😄

Note

I also uploaded a video describing the content of this post, here’s a link to the video.

You can also find the slides here

What is a Linux environment?

Linux is a family of operating systems. Windows and MacOS are operating systems, and the operating systems in the linux family satisfy the same essential use case!

Why should I care about Linux?

The majority of “servers” are running Linux operating systems. There are multiple reasons for this, but I’ll leave that for you to look up 😉. The implication of that is that the software you develop must run on a Linux server!

Hold up, what the heck is a server?

A server is a fancy word used for a computer that is typically somewhere else. You generally connect to servers remotely - And we’ll explain how you do that in a bit - and from there you can let your server do a variety of things (You can run a website for example).

Why are you telling me this?

Well, in CPSC 213, most of your development will be tested on the department’s servers, which run - you guessed it! - Linux. This means that you will be expected to do your work in a Linux environment, and hand-in your work in a Linux environment!

Tip
In the wild, Linux is used everywhere! So learning how to work with it is a very employable skill

Okay, how can I get one of those?

Well lucky for you, the CPSC department has a Linux server with your name on it!

Note
Well you’re sharing the server with quite a few students, but hey, you have a profile with your name on it!

And all you need to access it is an ssh client. There’s some explanation on exactly what that is in this wikipedia page, but you don’t need to know all its ins and outs to get started.

All you need to know is that ssh is what is used to access a remote server and run a terminal there. You’ll also need an SFTP client to easily transfer files, but we’ll get to that in a bit.

There are a few ssh clients out there you can get, I’ll break it down by your operating system and I’ll also write my Tarik Approved recommendation after.

Windows

If you are running windows, a commonly used tool for students is Xmanager, it includes an ssh client called XShell and an SFTP client, called Xftp. You can follow instructions on how to download it for free as a student in this CS website

Mac

If you are on a Mac, you should have an ssh client active by default. You can try this out by typing on a Terminal (You can get a terminal by searching Terminal in you Mac search bar):

1
ssh

And you should get an output that looks like this

1
2
3
4
5
6
7
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
           [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
           [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
           [-i identity_file] [-J [user@]host[:port]] [-L address]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-Q query_option] [-R address] [-S ctl_path] [-W host:port]
           [-w local_tun[:remote_tun]] destination [command]

You might want to however install an SFTP client, and CyberDuck and FileZila are commonly used ones.

Note
I don’t go over the details of the installation, but feel free to ask TAs questions if you have trouble downloading something or need any type of guidance!

If you are like me, and don’t want to install a billion things in order to get some work done I have the thing for you!

VS Code is a code editor that you can use to… edit code! The cool part is that VS Code supports almost every programming language, and has an awesome extension that allows you to connect directly to a remote server. Here are the steps to setting it up:

  1. Download VS code form the link above
  2. Run VS code
  3. Download the following VS Code extension
  4. You might need to restart VS Code, but you’ll now see a new logo on the left side of VS code that says “Remote Explorer”, click on it
  5. Make sure your are on ssh Targets and click the âž• sign.
  6. Insert the following command:
1
ssh <CWL>@remote.students.cs.ubc.ca
  1. You will be asked to input you password, once you do that, it will direct you to open a folder, pick the home folder.
  2. Celebrate because you just connected to your first Linux remote server!
Tip
The server is now saved, and will show up when you click the “Remote Explorer” extension

Lets learn Linux!

Okay so that was a lot to take in, so it’s okay if you had trouble going through it or still are missing a few pieces. TAs are there to help and if you have ANY questions, we would love to help guide you!

Now that you have access to the server, it’s time to learn the most important linux commands! (Note that the $ denotes the start of a command)

  • cd: short for “Change directory” changes your current directory to which ever one you pass to it, with . being the current directory and .. being the parent directory. Example:
1
2
3
4
tarikesh@valdes:~/tarik/code$ cd ..
tarikesh@valdes:~/tarik$ cd code
tarikesh@valdes:~/tarik/code$ cd .
tarikesh@valdes:~/tarik/code$
  • ls: Lists files and directories, for example
1
2
3
4
5
6
tarikesh@valdes:~/tarik$ ls
code
tarikesh@valdes:~/tarik$ cd code
tarikesh@valdes:~/tarik/code$ ls
file1.txt file2.txt
tarikesh@valdes:~/tarik/code$ 
  • pwd: Print working directory, prints the path to where you are right now
1
2
tarikesh@valdes:~/tarik/code$ pwd
/home/tarik/code
  • cat: short for concatenate, it lists the contents of a file
1
2
tarik/code$ cat file.txt
Hello I am a file!
  • cp: copies a file from one place to another
1
2
3
4
5
6
7
tarikesh@valdes:~/tarik$ ls
code
tarikesh@valdes:~/tarik$ cd code
tarikesh@valdes:~/tarik/code$ cp file.txt ../
tarikesh@valdes:~/tarik/code$ cd ..
tarikesh@valdes:~/tarik$ ls
code file.txt

This should be enough for you to move around and inspect your linux environment!

What you need for 213

  • A folder named cs-213 in your user’s home directory. You can do that by running:
1
mkdir ~/cs-213
  • A folder named a1 for assignment 1, a2 for assignment..etc
1
mkdir ~/cs-213/a1

From there, you should be able to run the handin command! Which is what we use in CPSC 213 to hand-in your assignments. Here’s how you run it:

1
handin cs-213 a1

or if you want to overwrite an existing submission:

1
handin -o cs-213 a1

Each assignment will include a list of deliverables that you will place inside the aX folder (where X is the number of the assignment)

Wrap up

There are a few omitted details, so if you have any questions please feel free to ask a TA, and feel free to send me an email at tarikesh@student.ubc.ca.

I hope this helps save you a bit of time, and can act as a referrence as you progress through the course.

I might write another one of those with more details if the need arises, but for now, happy coding!