----- Introductory Unix Walkthrough ----- This walkthrough provided by UW ACM Questions to hctang@cs First, let's set up your Unix account to use the cool features provided by /uns. This involves running their setup scripts: > /uns/examples/setup-tutorial Now, logout and log back in. 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 Let's go back up one level to our parent directory: > cd .. Pico can also open existing files, so let's copy a sample .c program from /uns. 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/complex-number.c . Let's rename it to complex.c. Remember, file renamining is done with the 'mv' command. mv is similar to cp; that is, it's mv > mv complex-number.c complex.c Wait, we changed our minds! Let's move complex.c to our tutorial-files directory, and then change our directory to tutorial-files: > mv complex.c tutorial-files > cd tutorial-files Now, let's try compiling complex.c. The C compiler is called gcc: > gcc complex.c Hmm .... that didn't go too well. Look at the error messages gcc has produced and see what line numbers the error(s) occur on. Open complex.c 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. - Hitting Ctrl-c in pico will tell you the line and column number the cursor is currently on. Let's open and edit complex.c in pico: > pico complex.c Compile again: > gcc complex.c By default, gcc (and g++) produces an executable called a.out, which is not an informative file name. Let's recompile the file. This time, specify the name of the executable which gcc should produce using the -o flag. Let's call the executable 'sum', since it adds two numbers. > gcc -o sum complex.c Just for kicks, let's watch how ls -F shows the difference between the two different types of files: > ls -F To execute a program -- whether yours, or one of the system's (like 'ls') -- you need to type its name at the command prompt. > sum Unlike the system tools, however, you need to specify the _your_ program's path. Remember that the period '.' specifies the current directory. So let's try again: > ./sum One important note: when compiling with gcc/g++, you should specify the -ansi and the -Wall flags. -ansi ensures strict ANSI compliance, and -Wall stands for "Warnings: All", meaning that it will warn you about everything (-g is nice, too -- it allows your program to be debugged). Let's try it again: > gcc -ansi -Wall -o sum complex.c Looks like we missed something the first time. Let's edit the file again: > pico complex.c Recompile and re-execute: > gcc -ansi -Wall -o sum complex.c > ./sum 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 a.out > rm sum 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 *.c > rm *.c Or, you could just delete everything 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 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! :)