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
- 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.
- 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:
- 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.
- Once logged into
meow type "chsh".
- When it prompts you for your new shell type "
/usr/bin/tcsh".
- Type "
logout" to leave meow and go back to working on the
lab machine.
- The result may not take effect immediately. You can always invoke tcsh directly, just type
"
tcsh". (Do it now for today's lab.)
- The tcsh shell does everything csh does but also has some additional features. Most importantly
are filename completion, command editing, and command history.
- 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.
- 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).
- 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.
- Filename completion and command editing can save a lot of time and typing.
- Get back to your home directory by typing "cd" (then hit return/enter which you always
need to finish a command).
- Make a class directory called "12a" (use the
mkdir command).
- Change to the new directory.
- Make two subdirectories, "lab" and "programs".
- Change into your "lab" directory, and create a directory called "lab1."
- Change back to your home directory (just type "
cd").
- 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".
- 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. )
- 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.
- Try logging into
unix.ic.ucsc.edu using ssh.
- Working with the person next to you, try transfering some test file from their directory to
yours using sftp.
- Create a file to transfer. One simple way to do this is type:
- cat > testfile
- something here.. type as much or as little as you want over several lines
- When done, type Control-D on a line by itself. That is hold down the control key and type
the D key.
- Type "
sftp username@unix.ic.ucsc.edu" to connect.
- 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).
- 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.
- You can also use "
put filename" to upload a file from your computer to the remote
computer (unix.ic).
- When you are done type "
quit".
- 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.
- Like with the last exercise, you will need to work with a partner for this part of the lab.
- 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).
- 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.
- 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.
- 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).
- 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>".
- To create the script file:
cd into your lab1 directory.
- Start recording with "
script lab1.txt".
- Type "
ls -l" to print a detailed listing of the contents of the directory.
- Type "
pwd" to print the full path of the current directory.
- Type "
fs la" to print the access setup for the directory.
- Type "
exit" to end the script recording.
|