Homework 1: Setting Up

Questions?

If you have a question, just send email to 354-help@cs.wisc.edu and we'll try to get back to you quickly. Don't worry, it's just to the TAs and professor.

How to send a good email: Put a lot of information in it! For example, cut and paste what you typed on the screen, and what was printed on the screen as a result. Don't just say that something didn't work!

Part 1: Logging into a CSL Machine

The first challenge is simple: being able to use one of the Linux machines made available by the CSL (Computer Systems Lab) here at Wisconsin. The lab provides a number of different Linux systems for you to use; the list is available here.

To log in, you must know your CS login (which the Lab should have mailed you about already). If you don't have one, please first read about activating your account , and also read about your account as well, to see if you can figure it out. If not, you can always email the lab (lab@cs.wisc.edu) for help.

Once you know what your login is, you have to pick a machine and use SSL to log in. The set of machines available as of January 17, 2017 are:

  • emperor-01.cs.wisc.edu ... emperor-07.cs.wisc.edu
  • rockhopper-01.cs.wisc.edu ... rockhopper-09.cs.wisc.edu
  • royal-01.cs.wisc.edu - royal-30.cs.wisc.edu
  • snares-01.cs.wisc.edu - snares-10.cs.wisc.edu
You can log into one of these machines by typing, at a command shell prompt, something like this:
prompt> ssh -l your_user_name -X emperor-03.cs.wisc.edu
My user name is remzi , so I would type:
prompt> ssh -l remzi -X emperor-03.cs.wisc.edu

Note that we use prompt> to indicate what the shell shows you when asking for you to type a command; undoubtedly, it will say something different than prompt> (and in fact, you should eventually customize this in a way that suits you).

It may seem kind of arbitrary to pick a particular machine, instead of (say) an unused or lightly-used one. To have the CSL pick a machine for you, log into any one of the following: best-emperor.cs.wisc.edu, best-rockhopper.cs.wisc.edu, best-royal.cs.wisc.edu, best-snares.cs.wisc.edu. In other words, just replace emperor-03.cs.wisc.edu in the ssh line above with best-emperor.cs.wisc.edu instead.

If you are using a Windows machine, you'll probably need to use Putty to log into the CSL machines. If so, learn how to use Putty!

Part 2: The Shell

Ok, great. So you've logged in. Now, you need to start getting familiar with the command shell you are using. Most of you are probably using bash . However, you are free to use any shell you like, such as tcsh, zsh, ksh, etc. The important thing: pick one, read about it, and learn how to use it. There are many online tutorials for shells, and spending some time learning your way around is useful. So go do it!

Some things worth learning: how to personalize your shell to have a different command prompt, how to be able to readily recall and edit shell history to avoid repetitive typing, how to set your search path for executables, how to redirect input and output to and from files, maybe how to construct loops and other little in-shell programs, and certainly many other similar things. The key goal: to be as efficient as possible when using the shell.

One thing you'll need to know is how to move around the file system hierarchy. A Unix file system is just what CS types call a tree , which has a single root and many children. At the root is a directory (or folder) called the root directory . In Unix, we refer to the root as / (a forward slash). All other files and directories (folders) are located somewhere in that tree.

When you log into one of those Linux machines, you'll be placed into what is called your home directory. To see what directory that is, type:

prompt> pwd
The pwd command Prints the Working Directory, which should be something like this:
/afs/cs.wisc.edu/u/r/e/remzi
This entity is called a pathname and it should be interpreted as follows. In the root directory (/), there is another directory called afs; in that directory, there is another directory called cs.wisc.edu ; in that one, there is another directory called u, etc., on down to the last directory called remzi. The symbol / (in addition to being the name of the root directory) is used as a separator in the path; in other words, it separates each directory (or file) name from the others in the path.

Now, let's do some simple shell stuff just to warm up. First, check out the files and directories in your home directory. To do this, you will run a program called ls which lists files and directories.

prompt> ls ...
You should see some interesting output there, including some directories (like private/ and public/ among others) and perhaps a few files.

Let's now create a file, to see how that works. Type the following at the command prompt:

prompt> echo hello > file.txt
at the command prompt. Here, the program echo simply prints out whatever you pass in as an argument to it. In this case, it will print hello. However, it doesn't print it to the screen, because of what is called the file redirection indicator (>), or what looks like a greater-than sign. This redirection symbol tells the shell to arrange so that the output of the echo is sent to the file file.txt instead of the screen. How does that work? Well, it's a long story that requires some OS knowledge, so we'll just leave it as magic for now.

To check if your file exists now, type:

prompt> cat file.txt
hello
If you did it correctly, you should see the word hello as shown above.

If you don't want that file around, use the file deleting command rm to remove it:

prompt> rm file.txt
However, please be VERY careful with this command. It can delete your files(!). There are many stories about accidental deletes of huge amounts of information; here is a story about how Pixar almost deleted Toy Story 2 (oops!).

Part 3: Actually Doing Some Homework

The actual homework part of this homework is pretty easy. It's just about converting some numbers from decimal to binary and hex forms. To start this assignment, let's use our old friend cd to switch into the correct directory. Let's assume the user's name is remzi and thus remzi would type:

prompt> cd ~cs354-3/handin/remzi/hw1/
That first symbol before cs354-3 is called a tilde and it is often used to refer to a particular user's home directory. For example, remzi's home directory is ~remzi. In this case, we are cd'ing into a user named cs354-3's (not a real person, don't worry) home directory, into a subdirectory called hw1 (for homework 1) under the generic handin directory. Each homework you turn in will be placed in a directory such as this.

Now that you've correctly cd'd into that directory, you can type ls to see what files are there. You should see no files at all -- an empty directory.

To do the homework, first change directories into your hw1/ handin directory. That is, type:

prompt> cd ~cs354-3/handin/USERNAME/hw1/
where USERNAME is your user name.

From that directory, run a simple program that prints out some problems for you to solve:

prompt> ~cs354-3/public/hw1/hex-run.py
This program, hex-run.py, simply prints out five numbers for you to transform from decimal into binary and hex forms. So do this!

To turn in your answers, simply create a file called hex.out in your hw1/ directory, and put the answers into it in this form:
decimal_value_1 binary_value_1 hex_value_1
decimal_value_2 binary_value_2 hex_value_2

The file should have five lines in it, one for each answer you need to put in there. Probably the hardest part of this will be figuring out what editor to use.

For example, if one question was asking you to translate the number 3 into binary and hex forms, you would include a line as follows into your hex.out file:

3 0011 0x3
Pretty easy!

An editor is the main way a programmer interacts with the programs they write (and, as above, other text files too). Thus, it is imperative you become good at editing files in at least one such editor. The standard Unix way to do this is to use emacs or vim which have both been around for a long time and are powerful editors; of course, there are many other options. They key for you will be to be able to use any one such editor in our Linux platform and be able to edit files as need be.

Thus, a hidden part of this assignment is to spend some time learning on of these editors. Learn how to open a file, edit it, save it, quit the editor (sometimes harder than it should be!), and even how to customize the editor. Again, the goal is efficiency: there are many ways to take shortcuts, and the more tricks you learn, the more proficient of a programmer you will become.

Finally, once you have created this file with your answers, you can even check if you have done so correctly. To do this:

prompt> ~cs354-3/public/hw1/hex-check.py
If you've done it all right, it should say something like this:
5 correct (out of 5)
At this point, you are done with this (very) easy homework 1.