(Not to hand in, but try to do by Wednesday 1/13. UNIX will also be covered in discussion section.)
To access your UNIX account from the lab NT network, you can run the XWIN32 program, which may on the desktop or in the Internet folder or on the Start menu under Internet. This emulates X-Windows, which is the windowing system used with UNIX, so it's just as though you were using a UNIX workstation. The windows work somewhat like those in Windows NT. Most important is that the cursor should be in the window in which you intend to type. To telnet from outside, you can use the hostname hermosa.pic.ucla.edu [We need to double-check this; if it doesn't work check the PIC 40 home page for updated information.]
more /usr/dict/words (and press the RETURN or ENTER key, depending on what your keyboard has)
Now press the space bar to see a page at a time (``more and more'' of the file), or the d key to see half a page at a time. You can use q to quit.
There is a directory in which course materials will sometimes be provided, but it has a complicated name. Make a simpler name for it, h in your own home directory, by creating a symbolic link:
ln -s /usr/class/handout/class/pic40.1 h
(This is called the ``class handout'' directory, but it's for providing files, not for regular kinds of handouts.) Try these:
ls (list the current directory)
ls h (list the contents of h )
more h/wds
cd h (change the current directory to h )
more wds
pwd (print working directory--in other words, where am I?)
cd (go to your home directory)
Note: Path names starting with a slash are ``full path names'', usually not in your personal ``directory tree''. Path names starting without a slash are assumed to start in the ``current directory''. Your own home directory can always be called ~ ; for example, later on when you have lots of directories if you're in one you could say
cd ~/h (go to the subdirectory h of your home directory)
Another note: cd .. goes up a directory, but if the directory is a symbolic link it may go up to one you didn't intend.
wc /usr/dict/words
(Why are the first two of the three numbers the same?) If you want only the line count, use
wc -l /usr/dict/words
man wc ( man is controlled like more )
In UNIX a command may be followed by ``arguments'', some of which may be file names. Others, with minus signs, are ``switches'' or ``options'' that tell the command to do something special. The manual page lists optional arguments in brackets [] and then explains any options below.
Later, in Perl, you'll learn how to write programs that have a name that you choose and that grab the arguments, which are simply strings, and interpret them any way you want. This can also be done in C++.
grep boo /usr/dict/words
If you're at home connected via a phone line, be careful not to try a selection that prints out more than the line can handle. If you do start getting too much output from a program, stop it with ^C (control C), meaning to hold the CRTL key down like a shift key and press c . Do not type ^ !
You can ``pipe'' the output of one program as the input to another by using a vertical bar:
grep boo /usr/dict/words | wc -l
What do you get? Try searches with some other substrings.
grep boo /usr/dict/words | grep -??? book (Again, don't type these question marks!)
How would you have the computer count the answers?
sort h/wds
sort < h/wds (standard input from a file)
grep ob < h/wds | sort ( grep from a file, sort from a pipe)
sort (standard input from the keyboard)
In this last one, the computer will stop dead waiting for you to type something. So type several lines, each ending with a RETURN (or ENTER, depending on your keyboard labels). Then type ^D as the newline marker (meaning to hold the CTRL key down and press d ). You should get your lines back, sorted.
sort < h/wds (standard output to the screen)
grep ob < h/wds | sort (standard output of grep is piped to standard input of sort )
Now try this:
sort < h/wds > tmp (standard output to a file named tmp )
Use more to view the file tmp to see if this worked. When you're through, remove tmp by the command
rm tmp
On the other hand, these programs also can be used with filename arguments, even more than one. Try
wc /usr/dict/words h/wds
echo hi there
echo hi there | wc
echo lee@ucla.edu > .forward (if that's your address)
Check the file with more
cp myfile1 myfile2 (copies an existing file to a second file, creating the second file if it doesn't exist, or overwriting if it does; you may be asked to confirm that you want an overwrite)
mv myfile1 myfile2 (moves an existing file to a second file, the same thing as renaming)
lpr myfile (send a file to the printer)