----- Introductory Unix Walkthrough ----- This walkthrough provided by UW ACM Questions to awong@cs First, log in to your unix account using Start | Programs | Unix Connectivity | X Connections | SSH-X attu Now, we'll make a directory to place your tutorial files in. Let's place the new directory immediately below your home directory: > cd ~ > mkdir tutorial-files Let's view your new directory (and any other files in your home directory): > ls A useful flag to ls is -F (which indicates which enrties are executable, directories, etc): > ls -F Let's change into the directory you created: > cd tutorial-files A really easy-to-use text editor is pico, which is the text editor used in pine. Let's try creating a file in pico. Remember: Ctrl-o saves a file in pico, and Ctrl-x exits. Open pico and type some stuff. Make sure you save your file. > pico Use pico to create a simple java class "Test" > pico Test.java Then type in the following (or just cut and paste it): public class Test { public static void main(String [] args) { System.out.println("Hello!"); } } Let's compile this file. > javac Test.java If the command returned with no errors, then it probably worked. To be sure, let's look for the Test.class file in our directory. > ls If the Test.class file exists, then you're all set to run the program. If not, ask someone next to you for help, or e-mail awong@cs. Assuming your program did compile correctly, try to run it using the java interpreter. > java Test That should have printed "Hello!". Okay. Let's try something more complicated. Pico can be sued to edit existing files, so let's copy a sample java program from the acm directory. Remember that the syntax for cp is cp . Also, the abbreviation for the current directory is a period (.). Note that there is a period at the end of this command! > cp /org/acm/tutorials/intro-unix/colorwindow.java . Try to compile this file. > javac colorwindow.java The compilation should fail since the class name is ColorWindow and not colorwindow. Rename the file to the correct name. Remember, file renamining is done with the 'mv' command. mv is similar to cp; that is, it's mv > mv colorwindow.java ColorWindow.java Now, let's try compiling it again: > javac ColorWindow.java Hmm .... that still didn't go too well. Look at the error messages gcc has produced and see what line numbers the error(s) occur on. Open ColorWindow.java and fix the errors. Don't forget to save with Ctrl-o! Also: - You may find it convenient to have two windows side-by-side, one to compile in, and the other to run pico. Login a second time to get another window. - Hitting Ctrl-c in pico will tell you the line and column number the cursor is currently on. The command line to open the file in pico is: > pico ColorWindow.java Compile again: > javac ColorWindow.java And try running: > java ColorWindow Voila! You've got a color changing window! This is working because you have an "X-server" running in the background which is allowing the unix machine to send graphics to your local computer. Let's see what happens if you manage to close the X-sever. First, close the color changing window by hitting the X. Next, look at your system tray (the thing next to the clock) for an icon that looks like a green pyramid with an 'X' in it. This is the icon for your X-sever, Reflection X. Right click on this icon and choose exit. Click 'OK' on the dialog box that says "This will end your Reflection X session" Now try running the color window again: > java ColorWindow You will get an error saying something like "X connection to broken". This means that the program cannot find the X-server to send the graphics to. Restart reflection X by running: Start | Programs | Unix Connectivity | Reflection | Reflection X Click through the dialog boxes (being sure to say 'No' when you are asked to run the performance tuner) and then minimize the X Client Manager. When you run Reflection X this way, you get the "Client Manager" rather than the System Tray icon. Just minimize the sucker and don't touch it and you'll be fine. Now, try running the color window again: > java ColorWindow It should work again. What's basically happening is this. You have an "X-server" running on your machine that is able to accept graphics from unix programs. You login session via SSH has "X tunneling" enabled, which allows programs on the remote machine (attu) to send graphics to the X-server on your local machine. You need both the X server and an ssh session with tunneling opened to get graphics on your local box. All this is automatically setup if you use the SSH-X icons or log into a linux machine. You can perform "X tunneling" with almost any ssh client. However, by default it isn't enabled. So if you have the X-server running, but you can't get graphics from your ssh session, check and make sure "X tunneling" is enabled in your ssh program and _log in again_. The last step is important as tunneling changes will not take effect until you login again. You're a Unix master, now! Okay, let's clear up our files and get out of here! Let's find out what files you've created thus far: > ls Hmm .... that's a lot. Well, you could manually remove each file with rm: > rm ColorWindow.java > rm ColorWindow.class ...etc... Or you could chain them together: > rm a.out sum ... But that's still kind of a lot of typing. Wildcards to the rescue! Remember that * stands for "zero or more charecters." So if we wanted to delete all the .c files, you could delete *.c. But wildcards are kind of dangerous, so it's a good idea to list all the files you intend on deleting _before_ deleting them, so you know _exactly_ what's about to be deleted (remember, there's no undelete in Unix!) > ls *.java > rm *.java Or, you could just delete EVERYTHING (not just the java files) with *, since * matches everything: > rm * Finally, let's delete the tutorial-files directory. We want to get to the parent directory before we do that, however: > cd .. > rmdir tutorial-files Now that we've done it the hard way. Here's an easier way to delete the directory tutorial-files and everything in it. Careful though! This command will delete whole directory trees without asking questions! > rm -rf tutorial-files Before we head home, let's check our dante email. Remember: telnet is insecure; we want to use ssh. So: > ssh @dante.u.washington.edu You may recieve a message about a "key" and the question "Are you sure you want to continue connecting (yes/no)?". Just type "yes". When you're done with dante, just logout as normal, and you'll be returned to your CS Unix prompt. You're done! Just type: > exit and head home for a well-deserved rest! :)