Due: After you are done, submit the science.txt, linux_info.txt, and hello.c files to CMS by Sunday 1/27 at 11:59 PM
This part can be used to reference terms you don't know, but is not necessary for completing the lab. You should skim it.
What is Linux?
Linux is an operating system that is free to the public to download, since it was created as an open-source program. The system is based on an older OS version called UNIX. To navigate through a Linux or UNIX system, you need to type in instructions to the computer using what is called a command-line prompt (nowadays, we often use graphical user interfaces (GUIs) to click on folders instead of typing commands to find those folders). You can even download software using the command-line prompt. Later, you will learn some of the most common Linux commands.
What is Ubuntu?
It is an African word meaning "the belief in a universal bond of sharing that connects all humanity" (https://en.wikipedia.org/wiki/Ubuntu_(philosophy)).
More seriously, it is a version of Linux. Some of the most popular distributions include names like Ubuntu, Mint, Fedora, openSUSE, and Debian, though there are dozens more. Ubuntu is known for being kind to beginners with its software center and media management while Debian is less user friendly and geared towards more technically oriented users. We will be using Ubuntu for our OS. In fact, we have created an Ubuntu version specifically for this class!
What is a Virtual Machine (VM)?
A virtual machine is an application that can imitate hardware such that you can run more than one operating system on your own computer. For example, I can run Windows on a Mac computer using a virtual machine. The VM can run while my usual operating system running without requiring a reboot. It works like any other application, sitting in a window you can minimize when you want to go on Facebook and maximize when you want to work on CS 3410 again. In case you hear this terminology, the Host OS refers to your computer, while the Guest OS is the operating system you are running on the VM.
(So why do people use dual booting? Well, one reason is that VMs tend to have higher overhead, such as being slow with 3D graphics, but booting one OS at a time means that the OS can use the computer’s full speed.)
Instructions to download our VM are in Part 1a.
What is a kernel?
The kernel is a program that has complete control over the whole operating system. It is the first program loaded when the OS starts up, placed in a safe location in memory to prevent being overwritten. It handles all the interfacing between the hardware and software. For instance, it may take input requests from a keyboard translate them into instructions the CPU understands.
What is a shell?
It is a program that provides the user interface for the kernel. This is where you type in the commands we mentioned earlier. Just as there are various Linux versions, there are also several shell versions, such as sh, bash, csh, tcsh, and ksh. Again, these versions came about due to improvements or extra features implemented by others (e.g. bash built upon sh by adding command completion and command history). On a Mac, the shell is called the Terminal. On Windows, the analogous form is the Command Prompt.
What is SSH?
SSH (Secure SHell) is a method of remotely connecting to and running commands on another computer (“remote” meaning something far away, so we are connecting to a computer far away). It can be accessed using the ssh command in a shell (like the Mac Terminal). It lets you access the resources of another computer that you may not have on your own computer. However, you cannot use SSH without an Internet connection. Cornell makes Ubuntu computers available to computer science students, which you can access remotely with SSH.
How to SSH is explained in Part 1b.
Windows does not come with an SSH client, which means you will need to install one on your computer if you are a Windows user. The we suggest Git (or Cygwin). Git lets you use the basic Linux commands that you'll need for this class. Cygwin puts a full UNIX environment (or close to it) but it has more overhead and you do not need it.
For this class, you will have the option of either using the VirtualBox VM to run Ubuntu or using SSH to remotely connect to a Cornell Ubuntu machine. Choose either Part 1a or Part 1b to ensure you have access to an Ubuntu machine. SSH is preferred by most of the TAs. VM is okay if SSH does not work or you don't have internet connection.
Why are going through all the trouble of setting this up?
For one, it's often very difficult to get all of the course software on the variety of different computers and operating systems that everybody brings to the class. But more importantly, we want to ensure that the everyone is working in the same environment so that we can guarantee that if it works for you, it will also work for us (and our autograder). We therefore require that you do all of your projects work on the Ubuntu environment that we set up for you, because some of the projects we will be doing later on may work differently in different environments. We want to avoid anyone submitting anything that works on their computer but then doesn't work on our machines because the environment is different.
For the setup:
* You can learn more about VirtualBox at https://www.virtualbox.org/manual/ch01.html
SSH (Secure shell) is a method of remotely connecting to and running commands on another computer. Cornell makes Ubuntu machines available to computer science students and we have created one specifically for this class that is equivalent to the VM that is made available.
Important Note for SSH
This is a system that will work anytime you’re connected to the internet... on Cornell Campus. Cornell's SSH network requires being connected to the same network as the machine you’re connecting to. Never fear though, the solution to this is called a VPN - a Virtual Private Network. This is a service that routes your traffic through a server (in this case on Cornell campus) so that you can connect to the VPN even when not on Cornell Wifi.
You can find the VPN installation and connection instructions here. After installation, follow the connection tutorial at the same page to set up the connection.
Important: If you use Windows, your computer does not come with an SSH client. Skip down to "For Windows users only", then come back here to complete the process"
For everyone:
ssh netid@ugclinux.cs.cornell.edu
, where you replace netid with your netidexit
or hit Ctrl-DFor Windows users only:
Choose one of the two options:
Now that we are using a Linux environment (via SSH or VM), let’s learn some commands to make your Linux machine do your bidding! But first, we have a few more bits of knowledge for you. Note that there are some necessary tasks to complete along with the reading!
Which type of shell are we using?
We are using the bash shell, which is a typical default for Linux systems. Type in the following command into your shell to check!
echo $0
Can we use text editors within the shell?
Yep. You have several at your disposal - vim, emacs, and nano. Each have their own set of commands for various behaviors like saving text, exiting, etc. If you have never used any of these editors before, we suggest getting started with vim, one of the most popular text editors.
Complete the following:
vim
into the shell. You are now using vim in Command mode which means you will not be able to type normally.i
key. You can now type as you would expect.ESC
key to do so. Then type :w science.txt
which will appear at the bottom of the terminal. This writes the file to the given file name./science
, hit Enter
, and watch the cursor jump to the start of the first occurrence of “science”. To again find the same string, hit n
. Hit N
one more time to return to the first occurrence.:wq
to write and quit, or :q!
to discard all of your unsaved edits and quit.vim science.txt
. Because you opened a file with a name, to save you can just use the command :w
to save your work, without specifying the filename.How do I get files from my computer to the remote machine and back?
For this class, the best option is to use your git repository. Complete the following to get the repository on your remote machine:
git clone your_repository_link
, where your_repository_link
is what you found in step 3.You should now be able to navigate through the downloaded directory. Use the git commands to add, commit, push, pull, etc. to update your files. See the tutorials on how to use Git in the Git, etc. section of the course resources page.
For this lab (and most of the class) you will only need a few commands:
git clone REPO_LINK
cd REPO_NAME
git pull
git add .
git commit -m "MESSAGE_ABOUT_CHANGES"
git push
git clone REPO_LINK
if you don't have the repo cloned yet.cd REPO_NAME
and then git pull
git clone REPO_LINK
if you already have the folder) every time you want to transfer code.What are man pages?
These are manual pages, not pages for men. If you cannot remember what parameters you need for a command, you can type in man command_name
to obtain a description. For example, try man mv
. Use the up and down arrows to scroll, and use q
to leave the screen. You can even do man man
to get information about man
itself.
Read this whole part carefully before starting!
Complete Tutorials 1, 2 (see note below), and 3 from the UNIX Tutorial for Beginners.
For the second command under Section 2.1 Copying Files, instead of copying the file given on the website, copy your previously made science.txt
file from the unixstuff
parent directory using
cp ../science.txt .
(note the dot at the end - there are four in this line!)
Save information about your Linux distribution to a file called linux_info.txt
. This is to verify that you genuinely have the correct environment set up. Try running the command lsb_release -a
and looking at the output. The lsb_release
command prints out information about your Linux distribution (Ubuntu). LSB stands for Linux Standard Base, which is a project to help standardize the various distributions of Linux. It should look something like this:
No LSB modules are available. Distributor ID: LinuxMint Description: Linux Mint 17.3 Rosa Release: 17.3 Codename: rosa
The above is an example of lsb_release -a
output created by running the command on a different version of Linux. Yours should look very similar. Do not copy ours.
Yes, you will see the message No LSB modules are available.
From what we can figure, Ubuntu is not totally LSB compliant since it is "a considerable amount of work for little measurable benefit" according to those working on the Debian project.
Put the output of this command in a file by redirecting
the output of the command, which you should have learned in Tutorial 3 of the UNIX commands. The redirection you learned redirects only stdout
(standard output), which means the No LSB modules are available.
line will still be output to the terminal and not to the file. This is because that line is output to stderr
(standard error), and so isn't redirected with the rest of the text. This is fine - we're only looking for your file to contain the lines outputted to stdout, which means the contents of your file should look similar to the block above but missing the first line.
Some useful tips:
tab
key to autocomplete commands, file/directory names, etc.tab
twice to get a list of the possible commands, files, directories, etc.Welcome to C! It is a programming language that was first introduced almost half a century ago but is still one of the most commonly used programming languages due to its speed, efficiency, and ability to closely interface with hardware.
Let's get to coding in C. On your Ubuntu machine (VM or SSH), open up a text editor (vim) and create a new file called hello.c
. You can create and name the file in one step by entering the command vim hello.c
. Type in the following C program (remember Insert mode):
#include <stdio.h> int main() { printf("Hello world! I am [netid].\n"); return 0; }
But replace [netid]
with your NetID (don't print square brackets). When you are done typing, save the file and exit the editor (remember Command mode and :wq
?). Now you are ready to compile and run the program you just created! In your terminal, navigate to where you saved hello.c
. Now run the command:
gcc -o sayhello hello.c
The C compiler (GCC) has compiled your source code hello.c
into an executable named sayhello
. The -o
option allows us to name the resulting executable file anything we want. Without the flag, the default name given to the executable is a.out
.
If this gives you any errors, make sure you are in the right working directory (use ls
to confirm that hello.c
is in the same directory). If you are in the right location, then you did not enter the program correctly — go back to your editor and fix the program. Otherwise, you have just compiled a C program. You can run your program by running the command:
./sayhello
And your program should run! It should print Hello world! I am [netid].
and do nothing else. For example, if your NetID is "abc123", then compilation and execution would look like something like this:
~$ gcc -o sayhello hello.c ~$ ./sayhello Hello world! I am abc123.
What does ./sayhello
mean? The command ./sayhello
means, run the executable sayhello
which is located in the current directory (remember .
means current directory and ..
mean parent directory).
That's it! Now look back at how to transfer files using git and submit science.txt, linux_info.txt, and hello.c to CMSX