UCSCBaskin School of Engineering  
General Information Events, News & Organizations Degrees & Departments Research Classes Admissions & Advising People & Jobs Administration
CMPS 012A/L - Week 1 Lab

Unix and AFS

For the week of Jan 9-13, 2006

Preparation

Additional Information

  • Many Unix commands expect one or more filenames as input (e.g. grep <word> <file>, (do not type the < or > characters) looks for word in file). Whenever a list of files is expected you can instead you "wildcards" to specify a group of files. The simplest wildcard is "*" which can stand for anything. E.g. more *.java will list the contents of all files ending with .java in the current directory. You can even use just "*" which will match all files in the current directory.
  • To move down into a subdirectory type cd subdirName. To move up to the parent directory type cd .. (that's cd followed by a space followed by two dots with no intervening space).
  • If you ever want to learn more information about a Unix command, type man <commandName> which will show you the manual page (man page) for the command.

Procedure

Introduction to Unix

  1. Log on to one of the lab machines. Enter your username. Then select Options/Session/GDE (Gnome Desktop Environment). Enter your password. On your own time you are encouraged to explore both desktop enviroments and see which you like best.
  2. If you aren't already very familiar with the "bash" shell, I strongly encourage you to switch from the default "csh" shell to "tcsh". You do this by:
    1. Log into meow by typing "ssh meow", then your username and password when prompted. These are the same ones you used to login to the lab machine.
    2. Once logged into meow type "chsh".
    3. When it prompts you for your new shell type "/usr/bin/tcsh".
    4. Type "logout" to leave meow and go back to working on the lab machine.
    5. The result may not take effect immediately. You can always invoke tcsh directly, just type "tcsh". (Do it now for today's lab.)
  3. The tcsh shell does everything csh does but also has some additional features. Most importantly are filename completion, command editing, and command history.
  4. After typing several commands using tcsh, try using the arrow keys to see what happens. You can edit previous commands and then execute the modified command. You do not need to move the cursor to the end of an edited command, just hit the return key when ready.
  5. Type cd /afs/cats/courses/cmps012a-cm/b but DO NOT hit the return key, instead hit the tab key. Notice how tcsh is able to complete the filename for you (there is only one way to finish).
  6. Now hit the return key to actually cd into that directory. Type cd c and the tab key. Notice that this time your computer will beep after partially completing the filename. There are multiple ways to continue. You can type Control-D to see a list of completions or type some more characters if you know what you want next.
  7. Filename completion and command editing can save a lot of time and typing.
  8. Get back to your home directory by typing "cd" (then hit return/enter which you always need to finish a command).
  9. Make a class directory called "12a" (use the mkdir command).
  10. Change to the new directory.
  11. Make two subdirectories, "lab" and "programs".
  12. Change into your "lab" directory, and create a directory called "lab1."
  13. Change back to your home directory (just type "cd").
  14. Type "ls -R > 12A/lab/lab1/lab1mkdir.txt" which will put a listing of your directories into "lab1mkdir.txt" in the lab1 directory you just made. (You may get some error message about OldFiles which you can ignore.) You can see what is in the file by changing back into your lab1 directory and typing "more lab1mkdir.txt". The ">" in the command means, instead of sending the output to the console so you can read it, "redirect" the output into the file that comes next--in this case "lab1mkdir.txt".
  15. Use grep to find out which file(s) in /afs/cats/courses/cmps012a-cm/book-examples/chap2 contain the word "height". You might want to use cd to first get into the chap2 directory. (Hit, use man grep to look at the manual pages for the grep command. )
  16. Pipe the output of grep into wc to find out how many lines in that same directory (.../chap2) contain the text "int". If you don't know what "pipe" means, search for "pipe unix" on Google.
  17. Try logging into unix.ic.ucsc.edu using ssh.
  18. Working with the person next to you, try transfering some test file from their directory to yours using sftp.
    1. Create a file to transfer. One simple way to do this is type:
      1. cat > testfile
      2. something here.. type as much or as little as you want over several lines
      3. When done, type Control-D on a line by itself. That is hold down the control key and type the D key.
    2. Type "sftp username@unix.ic.ucsc.edu" to connect.
    3. Once connected you can use "ls", and "cd" just like at a normal Unix prompt. To see and move around in the directories on the remote machine (unix.ic).
    4. Once you are in the directory where the file you want resides, type "get filename" to download the file from the remote computer to the one your are working at (the lab computer or your home computer). The file will be put in whatever directory you were in when you started sftp.
    5. You can also use "put filename" to upload a file from your computer to the remote computer (unix.ic).
    6. When you are done type "quit".
    7. You can read about downloading an sftp program for your home computer at http://www2.ucsc.edu/cats/sc/software/ssh/.

Introduction to AFS

If time allows, continue on to this part of the lab.
  1. Like with the last exercise, you will need to work with a partner for this part of the lab.
  2. Give your partner lookup, read, write, and insert access to the lab1 directory. Note that "fs sa somedir someuser write" gives MORE than write access and is not what you should be using (see the section "The fs command" in the AFS primer that was part of the preparation for this lab).
  3. Have your partner login to unix.ic using ssh from a console window. They do that by typing "ssh partnerLogin@unix.ic". You should each have one terminal/console window open.
  4. Test the access setup for your lab1 directory by having your partner (from their computer), create a file in your directory, and modify an existing file in the directory that you create. You can create a file using any editor. Try "pico" if you don't already know some other Unix editor.
  5. Have your partner attempt to delete a file from your lab1 directory, this should fail. The command to delete a file is "rm" (short for remove).
  6. Document that you have completed the above using "script". Script is a program that records a terminal session in a file. You start recording by typing "script <filename>" or just "script" which will put the session into the default file "typescript". When you are done recording type "exit". You can review the contents of the recording by opening the file with an editor or just dumping it with "more <filename>".
  7. To create the script file:
    1. cd into your lab1 directory.
    2. Start recording with "script lab1.txt".
    3. Type "ls -l" to print a detailed listing of the contents of the directory.
    4. Type "pwd" to print the full path of the current directory.
    5. Type "fs la" to print the access setup for the directory.
    6. Type "exit" to end the script recording.

General info · News · Events · Degree Programs · Research · Classes · Admissions · Advising · People · Jobs · Administration
SOE Webmail · SOE SSH · SOE Wiki · Search · Sitemap · Contact us · Driving directions · Privacy · UCSC
© Baskin School of Engineering, University of California, Santa Cruz
1156 High St., Santa Cruz, CA 95064 · (831) 459-2158 · webmaster@soe.ucsc.edu