How to Use Linux in 351

This is a quick little tutorial on how to get yourself up and running on the linux machines in the lab. You can also develop at home...those instructions are coming.

Getting a Shell

The shell is the bread and butter of linux. I know, graphical things are nice, but the linux shell brings you a lot of power with not very many key presses. As most companies in the industry will require you to use the linux shell at some point, it's better to just get used to it. You may be asked about it in an interview.

On Windows

On Windows, we will use something called an SSH client. An SSH client lets you interact with another computer over the Internet. SSH clients usually look old skool, like something they would have used in the 80s. Why? They allow you to interact with a program on another computer called a shell. You can also run graphical programs on those computers through your SSH client, but that's for another time.

The Windows machines in the labs come with Secure Shell, which isn't a very good SSH client. Instead, you should download PuTTY. Just putty.exe, will suffice for our purposes. Here's a short list on how to get PuTTY up and running.

On Linux

The linux machines in the department come pre-installed with all of the tools you'll need to work on the 351 projects. In addition, things are set up so that your files are in the exact same places as on attu. You won't need to do any special setup on Linux. Just click Applications at the top, mouse to Accessories, and click Terminal.

Accessing attu from Linux

Occasionally, you will need to access attu from your linux machine. Attu is a powerful computer sitting in the CSE building that is ready to run your work, except that it has no screen. It runs linux, and can only be accessed over the network. Anybody with a CSE account can use attu. Accessing attu is the same as accessing attu on your Mac OS X computer or home linux computer. First, open a Terminal:

Now that you have a terminal up, type:
ssh <your CSE username>

Press enter. If prompted about a server key, type yes and press Enter. When prompted, enter your Kerberos password and push Enter. Like PuTTY, it won't look like you're typing. This is done on purpose :)

At Home

At home, you'll need to access attu. Follow the instructions in the lab writeup to copy and uncompress the lab on attu. See the section on Editing Files for information on how to quickly edit files from home.

Finding your way around the shell

How files and folders work on Linux

First off, folders are a fancy word that Microsoft invented to make comptuers seem more human. While folders are great, they're called directories on linux.

The first thing that most new users shifting from Windows will find confusing is navigating the Linux filesystem. The Linux filesystem does things a lot more differently than the Windows filesystem.

For starters, there is only a single hierarchal directory structure. Everything starts from the root directory, represented by '/', and then expands into sub-directories. Where DOS/Windows had various drives (C:, D:, etc) and then directories under those partitions, Linux places all the drives under the root directory by 'mounting' them under specific directories. Closest to root under Windows would be C:.

Another point likely to confuse newbies is the use of the frontslash '/' instead of the backslash '\' as in DOS/Windows. So c:\windows\system would be /c/windows/system. Well, Linux is not going against convention here. Unix has been around a lot longer than Windows and was the standard a lot before Windows was. Rather, DOS took the different path, using '/' for command-line options and '\' as the directory separator.

Your Home Directory

To keep people from stepping on everybody's toes, everybody has one folder or directory that they can write and make changes to. This is called your "home directory". On any unix system, you can refer to the home directory with a tilde, so a folder called frogs inside of your home directory would have a path like:

When you run a command, your shell will replace ~ with the path to your home directory. If you want to know what that is or how to manipulate the shell, read the next section on basic unix commands.

Basic Unix commands

To move around through the directory structure in your terminal window, you'll need to know a few basic Unix commands.
attu4% mkdir mydir
attu4% ls
mail  mydir
attu4% cd mydir
attu4% pwd
attu4% exit
In the above (the things within the quotation marks are commands to type, don't type the quotation marks themselves): These are just the very minimum basics, or course.

Changing your shell

The shell is the program where you type in commands. There are different shell programs, which are all similar but have different rules and features. For sake of uniformity, we will use a shell called "bash" but it's likely that your account is set-up such that when you create an terminal the shell it uses is "csh". You can change this for the time being or once and for all. We strongly recommend the latter, but we'll explain the former first to help you understand what is going on.

For the time being: Type

attu4% bash
Now you may have a different looking prompt (such as bash-3.00$). Otherwise at this point you will not notice any differences, but that's only because you don't know any differences between bash and csh. When you type
bash-3.00$ exit
you'll be back to the shell you were running when you typed bash. That is, you started running a different shell and when you exited, you just went back to the outer one.

Once and for all: You could type bash every time you create an terminal, but that's a pain and you could get confused if you forget. So you can tell the operating system once and for all that for your account, the "first shell" for every terminal should be bash. From any prompt, type:

chsh -s /bin/bash
You are running the "change shell" program and specifying that your new shell can be found at /bin/bash. It's almost that simple: As a final note, if your shell already is bash, chsh will just say "Shell not changed."

Editing Files

First thing's first: What I say here is not final. There is a ton of debate on this.

CSE 351 Text Editing

For this course, you can use something as simple as Notepad. However, we strongly recommend something better. Here is a list of things, by OS, that we recommend:

A word about working at home

When working at home, you'll notice that you need to have your files on attu in order to compile and test your work. You can edit with nano, pico, emacs, or vi on attu, just by typing those commands and pressing Enter. However, depending on the latency between your computer and attu (i.e. the time that goes by before you press a key, attu receive the key, and tells your computer what to print on the screen in response), this might not be practical.

A better way is to download the lab to your hard drive, then use a Windows text editor to make changes. After that, you'll need a program called WinSCP to copy your changes to attu and compile them.


Viewing all of the output when you run commands

When you run a command like btest on attu, you may see something like the following:

  Gives 1942614435[0x73c9f1a3].  Should be 204869213[0xc360e5d]
... 9 total errors for function abs
Test abs score: 0.00/4.00
Test addOK(-2147483648[0x80000000],-2147483648[0x80000000]) failed.
  Gives -2147483648[0x80000000].  Should be 0[0x0]
Test addOK(-2147483648[0x80000000],2147483647[0x7fffffff]) failed.
  Gives -2147483648[0x80000000].  Should be 1[0x1]
Test addOK(-2147483648[0x80000000],-3[0xfffffffd]) failed.
  Gives -2147483648[0x80000000].  Should be 0[0x0]
Test addOK(-2147483648[0x80000000],811666840[0x30610d98]) failed.
  Gives -2147483648[0x80000000].  Should be 1[0x1]
Test addOK(-2147483648[0x80000000],-2147483647[0x80000001]) failed.
  Gives -2147483648[0x80000000].  Should be 0[0x0]
... 321 total errors for function addOK
Test addOK score: 0.00/3.00
Overall correctness score: 14.00/36.00
1541 errors encountered.

What happened to the first part of it? Answer: it scrolled up past the top of your terminal. You'll have to tell attu you want to save all of that output somewhere, like this:

./btest >feedback_filename

If you run btest (or any command) like this, linux will save its output in the file called "feedback_filename" for you to view later in your favorite text editor (see above section).

Alternatively, if you just want to see the output once, try it this way:

./btest | less

You can then use the up/down arrow keys to move around your output in a quick n dirty fashion. Use the 'q' key to quit. Be aware: Once you quit, the output is gone for good! But, luckily for you, you can just re-run btest to get it back. You can also use less to view the output from your saved file, like less feedback_filename.

Make clean and corrupt builds

Not everything is perfect, sadly :(. One of those is our build system. Though it is unlikely, the rule of thumb when running the make command is:
If something really doesn't look like it's running right, do a make clean, then a make and try it again.

To save time, make and gcc will save some of the computation required to build your software. However, at times, this can become corrupt and interfere with changes you're making.

Written by Andrew Reusch
With help from the 303 documentation and the web.
Last modified: Tue Apr 6 20:12:39 PDT 2010