Using Linux in CSE 410

Computing Platform: klaatu.cs.washington.edu

There are many possible ways to get your work done in this course. That said, the course work is designed on the assumption that you will be working by remote login to klaatu.cs.washington.edu. Registered students will have an account created there (by the first day of classes) with username the same as your uw netid and with a random password that will be provided to you by email.

klaatu is a Rocky Linux system. In theory, you could use any system to get your work done, including your personal Windows or Mac machine. We acknowledge that possibility but do not recommend it, as he course software will have been installed on klaatu and homework instructions may be written assuming you are using it. By far the simplest way forward is to work remotely on klaatu. You can work on other systems if you want. Whatever system you use, it is your responsibility to make sure that submissions work on klaatu, as all grading of any programming exercises will take place there.

Accessing klaatu.cs.washington.edu

klaatu.cs.washington.edu is a (virtual) machine in one of the CSE buildings. You access it by using "an ssh client" on the machine you have in front of you, whatever it is. ssh is a program and a protocol that allows secure (authenticated and encrypted) connections between machines. Once you establish "an ssh connection" between your machine and klaatu, what you type is sent to klaatu, which then does whatever you asked, and the output produced by the action on klaatu is sent back to your machine and displayed. Easy enough. It's not graphical, though. What is sent to and received from klaatu is text. The course will help you master the CLI (command line interface) manner of interacting with a computer, but just to the level we need it.

There are many programs that implement the ssh protocol and so can be used to connect to klaatu. We list here only the ones we might consider using, depending on the operating system running on the machine in front of you.

Connecting from Windows

We suggest two methods:

  1. PuTTY:

    PuTTY is lightweight SSH client endorsed by UW IT. The download site is here. When you launch it, you will see something like this:

    Hit Open and a window will appear. Type your klaatu username and then password and you will be logged in.

    Anything you type in that window will now be sent to "the shell" running on Windows. We discuss the shell a bit later.

    To log out, either type exit or else type ctrl-d (hold down the ctrl key and type d at the same time).

  2. Windows Subsystem for Linux (WSL)

    Almost any relatively recent version of Windows will let you install a Linux subsystem. You can install it through the Microsoft Store- search for "linux". I use Ubuntu, which provides this page as a starting point for installation of WSL/Ubuntu. The Linux flavor you install doesn't matter, though.

    Once installed, you can launch a bash shell window on your Windows machine like this:

    and then connect to klaatu using the ssh program, like this:

    (Use your own login, of course. It is the same as your UW netid. Your password will be supplied by email to your UW account when it is created.)

Connecting from Mac

The Mac Terminal behaves very similarly to most linux shells. As a result, most of the commands on Terminal will be the same as those described for a linux shell. Open a Terminal shell and issue an ssh command to connect to klaatu as shown above for Windows.

Connecting from Linux

Open a shell window and ssh to klaatu, as above.

Linux Files and Directories

Files in Linux are a lot like files on whatever system you're accustomed to. There are special files that hold other files. In Windows, those are called folders. In Linux, they're called directories.

The Linux file system is hierarchical: every file is contained in a directory except for one, the root directory. Files can be named using absolute names, which start with the root directory, whose name is "/". For instance, /homes/zahorjan/cse410/22wi/solution.txt identifies a file named solution.txt contained in a directory named 22wi, which is contained in a directory cse410, which is contained in a directory zahorjan, which is contained in a directory homes, which is contained in the root directory.

It's easy to see that absolute names can get pretty long and inconvenient. Linux therefore also provides relative names. Every shell instance always has a current working directory. A relative name implicitly prepends the name of the current working directory to the relative name you type, thus creating an absolute name. When you login, the shell that is created has its working directory set to your account's home directory, which for me is /homes/zahorjan.

For instance, suppose a shell's current working directory is /homes/zahorjan and that directory contains a file named .bashrc. Then these two commands are equivalent:

Because the second version uses an absolute name, it's meaning is the same no matter what the shell's current working directory is. The first one does what I intend only when the shell's current working directory is /homes/zahorjan.

Every directory contains two special names, . (dot) and .. (dot dot). . means "this directory." .. means "the parent of this directory." So, assuming the current working directory is /homes/zahorjan, these commands are equivalent:

When typing files names to the shell, you can use the tilde character (~) as a shortcut to mean the absolute path to your home directory. So, the command ls ~/.. also lists the non-dot files in /homes. The shell understands the file name as /homes/zahorjan/...

You change a shell's current working directory with the cd command. For instance, cd /homes/zahorjan/cse410 would make /homes/zahorjan/cse410 the current working directory. If the current working directory were /homes/zahorjan, the commands cd cse410 and cd ./cse410 would do the same. The command cd ~/cse410 would take the shell to that directory no matter where it was when you issue it. The command cd ~ takes the shell to your home directory, no matter where it starts.

You make directories with the mkdir command. For instance, mkdir cse410 will create a new directory named cse410 in the current working directory, if one doesn't already exist. You delete directories with the command rmdir, as in rmdir cse410. It fails unless the directory is empty.

Command options & man

Commands typically support switches that customize their behavior The switches are usually specified by giving a modifier like "-l" after the command name and before any other command arguments. For instance, the command ls lists just the names of the files in the current working directory, while ls -l gives a long format listing that includes when the file was last modified, its size, and access permission (among other things).

The command man is used to obtain documentation about commands. For instance, man ls will tell you what the ls command does and will list the switches available when using it. man pages typically tell you more than you want to know, and so can be somewhat challenging. (Try man man, for instance.) You get used to them after a bit, though, and they are the quickest way to understand what a command does and how to customize its behavior.

Some Probably Useful Commands

You can use the man command for help information on each of these commands. Each has greater functionality than is described here.

Command Use Example common use(s)
pwd print the name of the current working directory pwd
mkdir create a new directory mkdir cse410
cd directory Set the current working directory to directory cd cse410
cd ~ # cd to your home directory
cd # also cd to your home directory
cd .. # cd into parent directory of the current working directory, whatever it is
ls Print the names of the files in the current working directory ls # list names of files and directories that don't start with a period (dot)
ls -a # list names of all files and directories
ls -l # list extended information on "non-dot" files
ls -al # list extended information on all files
rm Delete a (non-directory) file rm testfile # irretrievably delete testfile
cp Make a copy of a file cp testfile testfile-copy
mv Move (rename) a file or directory mv testfile productionfile
cat filename Print the contents of the file to the window cat testfile
less filename Print the contents of the file to the window, but paginate the output. space moves down a page. 'u' moves up a page. 'q' quits. less testfile

Creating and Editing Files

We'll sometimes need to create and modify (edit) files on klaatu. There are two primary ways you could do that:

  1. create/edit a file on your local machine using an editor you are accustomed to, and then copy the file to klaatu.

    We don't recommend this method, but if you want to try it you should read about using the scp command in a local shell, which will copy files to or from klaatu.

  2. create/edit a file on klaatu, using an editor you're not likely to be already accustomed to.

    We do recommend this approach. It will probably require learning a small amount about a new editor.

Linux editors: vim and emacs

There are many popular editors used on Linux, but we're pointing you to only vim and emacs. If you already know another editor, or even if you want to spend your time learning some different editor, that is perfectly fine.

Both vim and emacs are intended as general purpose text editors, meaning they do not inherently know anything about what the text is you're editing: is it a C program or is it your latest novel? Don't expect them to immediately notify you if what you're typing is a C program and you make some mistake in C.

Every text editor has the issue that the keyboard is used both to insert new text into the file and to issue commands to the editor itself. So, suppose the editor uses the key 'f' to mean "move the insertion cursor forward one character." Then how do I tell the editor to insert an 'f' character into my document?

What is always done is that some special keyboard input is used in some way. For instance, the Home key is often used as a command to the editor, and it's unambiguous when typed because there is no Home character that could be inserted into the file. So, "special keyboard input" is always used, one way or another.

vim operates by always being in one of two modes: insert mode or (what I'm calling) control mode. When in insert mode, almost everything you type is considered to be something to be inserted into the file. The primary exception is the special character escape, which takes you out of insert mode and into control mode. In control mode, the keys you type are commands to the editor (e.g., to move the cursor or save the file). The command 'i' is a request to transition into the insert mode.

emacs takes almost the opposite approach. You're always in insert mode, and so to issue a command to the editor you have to type something that couldn't be input. Typically, that is done by holding down the control key while typing some other key. For example, ctrl-f (hold down control and type f) moves the cursor forward one character.

We don't require much from the editor, but you will want to know at least the basic commands for the one you choose. There are a lot of tutorials you can find online. Here is one suggestion for each editor:


This document is derived from one originally written by Andrew Reusch (areusch@gmail.com) and updated by Sarang Joshi (sarangj@cs.uw.edu) and Justin Hsia (jhsia@cs.uw.edu).