Welcome to Lab 1! The main purpose of this lab is to begin to get you familiar with the command-line environment that we’ll be using for this course (and that you’ll likely be using many more times in the future). For most of the course, you will be connecting to a remote machine (portal) to compile and run your code.
The lab is broken down into four components:
- Installing (or accessing) an SSH tool for connecting to remote machines
- Experiment with the BASH command-line shell (through interactive games!)
- Log into the UVA CS department’s portal
- Begin using a command-line text editor (nano or vim)
After this lab, you should be able to:
- Navigate in a shell, into and out of directories, listing what is in a directory and seeing its contents
- Edit files from the shell
- we don’t care which CLI editor you use: nano, vim, emacs, any is fine.
.as meaning “the current directory”
..as meaning “the directory containing the current directory”
~as meaning “my home directory” – i.e.,
SSH (Secure SHell) is a ubiquitous tool for running arbitrary programs on remote machines. We will use it extensively this semester. It comes bundled with a few related tools, like SCP (Secure CoPy), that we will also use.
You’ll need to know how to run SSH:
|If you are running||Then you should use|
|Linux||open a terminal and use the built-in |
|MacOS||open the |
|Windows 10 / 11||install OpenSSH Client (following the “from the Settings UI” directions) once; then open the |
|Haiku||open a terminal and use the built-in |
|FreeBSD||open a terminal and use the built-in |
|OpenBSD||open a terminal and use the built-in |
|Irix||open a terminal and use the built-in |
SSH gives you a shell; shells have long been ubiquitous tools in all systems except Windows, and they are increasingly used in Windows too. The shell is sometimes also called the “command line” or the “console”. It is a program that gives you a text interface to interact with the system. In the UVA CS department, the default shell provided is the BASH shell.
The shell provides a LOT of power. You are also able to interact with the system in a way that you can’t with a graphical interface. There is typically a learning curve when beginning to use a shell, but once you are familiar, you may find you’ll be using it more and more often.
To overcome this learning curve, many have created games and tutorials to become familiar with this new way of interacting with the system. Visit http://web.mit.edu/mprat/Public/web/Terminus/Web/main.html, a somewhat cheesy introduction to the basics of the command line. Explore it until you:
- feel comfortable with the use of
cd ..), and
- have learned about
There is a lot more you can do (creating a magic locker, explore a hidden tunnel, learn about
rm, etc.), but those are the most important basics.
Avoiding excessive typing
While in a shell, there are several keys to make you life easier; the most important are
- Up and Down
- The up and down arrow keys navigate through a history of previously-typed commands. On some systems, page-up and page-down also navigate in large chunks.
- Pressing the tab key when the cursor is preceded by an incomplete word that can only be completed in one way will fill in the rest of the word.
Pressing tab twice when the cursor is preceded by an incomplete word that can be completed in several ways lists all of the completions the command line knows about.
Another shell-learning game requires the use of the terminal (or command line) and SSH. This will begin to get you familiar with connecting to the CS portal, which we’ll do next. To begin, visit http://overthewire.org/wargames/ and read the instructions for “Bandit”. Many of the pages also list web resources to help you learn more.
If you don’t like reading, you can skip ahead to
$ ssh email@example.com -p 2220
and consult http://overthewire.org/wargames/bandit/bandit0.html to get started.
For lab, we will ask that you complete level 0 and 1 of Bandit, which includes connecting with SSH and looking for files. However, since there is no homework this week, we suggest getting to level 4 of Bandit on your own (either during or after lab), though you might find other levels and games there interesting. The more time you put into learning the shell, the more familiar you will be when we start using it more often this semester.
At some point you should have received an email from the CS department with a CS login. You should be able to use that to SSH into mst3k
@portal.cs.virginia.edu, an account we will use many times this semester.
Try to connect to the CS department portal using SSH. Note: unlike the bandit example above, you will not need the “-p 2220”.
$ ssh firstname.lastname@example.org
Once connected, you should first run our course set-up script. You will only need to run this command once, but it will set up all the tools we will be using throughout the semester. You can do this by running
/bigtemp/cso1/cso1-setup.sh and following the prompts:
Afterwards, test out some of the commands you’ve learned in the games and tutorials above. You will initially be placed in your home directory, which will be empty. Next, we will create our first text file using a command-line text editor.
If you are unable to log into the portal, you may need to reset your password. To reset your password, use the password reset tool at https://www.cs.virginia.edu/PasswordReset/. This tool will not work unless your account was setup at some point, a task that typically happens 3-5 days after you add the class.
Sometimes you need to edit a file on a remote computer over SSH. We’ll see other ways of doing this as the semester progresses, but you’ll often need to work in a command-line interface (CLI).
A text editor is a tool designed for editing text, only. They typically provide programming language syntax highlighting (i.e., strings show up in a different color from integers) and sometimes other customizable features, but typically they do no have error checking, compiling, executing, and other features of an IDE.
There are three main CLI editors in common use today; you should pick one to learn. We recommend GNU nano if you want your learning to be over quickly or VIM if you want to have a lot of power after you learn.
- VI (VIM)
- VI (released 1979), or more commonly the updated version VIM, is probably the most widely used CLI editor today. It has a large set of features and an idiosyncratic set of commands involving two modes: “normal” mode where virtually every letter and number key has a special meaning and often a special meaning in a sequence and “insert” mode where those same keys instead type.
To begin learning VI, go to https://www.openvim.com/ and follow along. Then open a shell (or the equivalent on your own machine if you’ve installed VI), type
vim, and try it out. You’ll probably need a cheat-sheet to remember all the keys: https://vim.rtorr.com/.
You can also try running
vimtutorfrom a shell for a different approach to learning VI. There is also a game-based tutorial, VIM Adventures: https://vim-adventures.com/.
VI comes with Linux and MacOS, and can be downloaded for Windows: https://www.vim.org/download.php
You will likely see Prof Hott use VIM extensively. However, the learning curve is steeper with VIM than with nano.
- GNU nano
- GNU nano (released 2000) is a much simpler (i.e. both easier to learn and less powerful) editor than the other two, with more traditional key commands and an on-screen summary of the most-used commands.
To learn nano, open a shell (or the equivalent on your own machine if you’ve installed nano), type
nano, and follow the on-screen instructions. Nano lists the available commands at the bottom of the terminal window.
Note that in the instructions
^Xmeans Ctrl+X and
M-Xmeans Alt+X (or Esc+X if you are on MacOS and Alt does not work for you).
Nano comes with Linux and an old version comes with MacOS; it can be downloaded for Windows (via the chocolatey package manager) by typing the following two lines into the PowerShell app:
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install nano
- EMACS was one of the first widely-used powerful CLI editors (released 1976). It has a large set of features and an idiosyncratic set of commands, many of which involve pressing Ctrl+X followed by another Ctrl+something command.
As EMACS has lost popularity in the past decade, more and more servers choose not to install it.
EMACS comes with Linux, and can be downloaded for Windows and obtained via homebrew for MacOS: https://www.gnu.org/software/emacs/download.html
Become sufficiently familiar with at least one of these editors that you can open, modify, and save files.
In order to receive full credit for this lab, please show your lab TA:
- An open terminal/SSH window that is logged into the portal via SSH.
- Open a file new file,
lab1.txtin the editor of your choice.
- Add your name to the file, then save it.
- List the contents of your home directory displaying the new