Lab1 Unix

This lab will familiarize you with some basic Unix commmands.

Preparation

Before coming to lab you should have read the following and completed the online review questions (in the format of a WebCT quiz).

A few more things you need to know

What to do

  1. Log on to one of the lab machines. Enter your username. Then select Options/Session/CDE (Common Desktop Environment). Enter your password. There seem to be some problems with the default desktop if you do not select CDE. On your own time you are encouraged to explore both and see which you like best.
  2. Get to a command line shell (terminal window).
  3. 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. Type "chsh".
    2. When it prompts you for your new shell type "/usr/bin/tcsh".
    3. The result may not take effect immediately. You can always invoke tcsh directly, just type "tcsh". (Do it now for today's lab.)
  4. The tcsh shell does everything csh does but also has some additional features. Most importantly (in my view), are filename completion and command editing.
  5. 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.
  6. 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).
  7. 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.
  8. Filename completion and command editing can save a lot of time and typing.
  9. Get back to your home directory by typing "cd" (then hit return/enter which you always need to finish a command).
  10. Make a class directory called "12a" (use mkdir).
  11. Change to the new directory.
  12. Make two subdirectories, "lab" and "programs".
  13. Change to the new programs directory.
  14. Make a subdirectory for each of the 5 programming assignments. Call them prog1, prog2, ...
  15. Change back to your home directory (just type "cd").
  16. Type "ls -R > lab1mkdir.txt" which will put a listing of your directories into "lab1mkdir.txt". (You may get some error message about OldFiles which you can ignore.) You can see what is in the file by 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".
  17. 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.
  18. Use grep and wc to find out how many lines in that same directory (.../chap2) contain the string "int".
  19. Try logging into unix.ic.ucsc.edu using ssh.
  20. 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://its.ucsc.edu/services/software/vendors/ssh.php
  21. Answer the post-lab questions in WebCT for the first lab. IMPORTANT: Be sure and submit the post-lab questions BEFORE the end of lab. Even if you aren't finished, submit what you have. If you need extra time, you will have until after 11pm, but you can only get credit if you have attended lab and attempted a solution before the end of lab. This will be the same all quarter.
  22. Submit, using WebCT, the "lab1mkdir.txt" file that you created.