.ps +2
.vs +2

                                                slide0

Course:

        Introduction to Unix, a hands-on seminar.

Sponsor:

        St. John Fisher College
        Office of Professional Development

Course Leaders:

        Gerry Wildenberg (wizard)
        St John Fisher College

        Carol Freeman (apprentice)
        Finger Lakes Community College










.bp

        What is UNIX?                           slide1

         + Ken Thompson and Dennis Ritchie

         + What is an operating system?

         + What is a shell?

         + The C language

         + Unix and you

              + Electronic mail
              + File handling tools
              + Data base tools
              + Documentation facilities









.bp

        Getting started                         slide2


                   + Logging in
                        login: guest1
                        password:VAXsys   
                        (but you won't see it when you type it.)

                   + Prompts
                        Vary from system to system. Many books
                        use %. I'll use % or [] .

                   + Passwords
                        + passwd [1]
                        + various rules about length and 
                          variety of characters. Try some.

                   + Logging out
                        + logout (or exit or ... )

                   + Delete or backspace?
                        + User can set

                   + Some simple commands

                        + date [3]
                        + echo [5]
                        + cal [6]

                   + Correcting errors in the csh [2]

                   + Reading files with cat [16]

                   + more or less [11]
                        more is a "pager". It lets you page
                        through a file.
                        At the more prompt, h, b, q, <sp>, and <rtn> are
                        the most useful keys. /pattern will do a search.












.bp
       Which shell?                            slide2.1

                   + Changing shells -- csh, sh, or tcsh
                        + chsh



















.bp

        Elementary redirection                  slide3

        echo

                % echo This is sentence 1
                This is sentence 1

                % echo This is sentence 1 > sfile
                % echo This is sentence 2 > sfile
                % cat sfile
                This is sentence 2

                % echo This is sentence 1 > sfile
                % echo This is sentence 2 >> sfile
                % cat sfile
                This is sentence 1
                This is sentence 2
                
                % echo > sfile
                % cat sfile
                %





.bp



        cal                                     slide4

                %cal 3 1987
                   March 1987
                 S  M Tu  W Th  F  S
                 1  2  3  4  5  6  7
                 8  9 10 11 12 13 14
                15 16 17 18 19 20 21
                22 23 24 25 26 27 28
                29 30 31



                %cal 3 1987 > cfile




.bp

                                                slide4.1 Excercises

(1)  Login

(2)  Give yourself a password

(3)  Logout and login again

(4)  Print a calendar for your birth-year

(5)  Print a calendar for December 1995

(6)  What day of the week were you born?

(7)  How many days were in the month September 1752? Be sure
     to do this one, it's fun.

(8)  Try echoing some messages.

(9)  Find out the time and date.

(10) Change the erase key to '='. Try hitting <del>.  Change
     erase back to <del>


.bp


        Communications                          slide5


         + mail [7]

                mail
                mail name
                mail namealias

         + talk [8]

         + /etc/passwd [9]

         + grep [10]

         + who [4]






.bp

        mail and grep                           slide6
                % mail ggww
                Dear Gerry:

                I'm finally on the system!!!!!!!!

                David
                .
                %





                %grep Rako /etc/passwd
                bdr:v0rdA2Pe82jQE:22:700:RakoverBoris :/fs3/fac/bdr:/bin/csh

        





.bp
       mail - some details                     slide6.1


        Some commands to use at the "mail prompt".
                + t <message list>      type
                + n                     next message
                + v <message list>      edit waiting message
                + d     "     "         delete
                + s <message list> file saves messages in file
                + u <message list>      undeletes (only works if
                                        you are still in same mail session.)
                + r                     reply to everyone who received the letter
                + R                     reply to sender only
                + q                     quits (read mail is saved)
                + h                     print out headers



.bp


                                                        slide6.2

        biff -- the dog that barked at the mailman

                biff n
                biff y
                biff


        talk -- can be annoying, mesg can help


                talk joe

                mesg n or mesg y



.bp

        who and finger                          slide7


                %who
                ep7956   ttyaf   Feb 13 21:35
                ggww     ttyah   Feb 13 22:00
                uucp     ttyat   Feb 13 21:33
                sl8860   ttybb   Feb 13 21:35




                %finger
                Login       Name              TTY Idle    When            Office
                ep7956   Eric Periche          af  57  Fri 21:35 
                ggww     Gerry Wildenberg      ah      Fri 22:00 
                uucp     UNIX-to-UNIX Copy    *at      Fri 21:33 
                sl8860   Steven Lape           bb      Fri 21:35 




                %finger freeman
                Login name: clf                         In real life: Carol Freeman
                Directory: /faculty/clf                 Shell: /bin/csh
                Last login Wed Apr 27 21:13 on ttyp6 from ds703-Modem
                No Plan.




.bp


        Learning by yourself                    slide8

         + man [12]
                man cat

         + apropos [13]     (man -k if you don't like spelling apropos.)
                %apropos pascal
                pc (1)                  - Pascal compiler
                pdx (1)                 - pascal debugger
                pi (1)                  - Pascal interpreter code translator
                pix (1)                 - Pascal interpreter and executor
                pmerge (1)              - pascal file merger
                px (1)                  - Pascal interpreter
                pxp (1)                 - Pascal execution profiler
                pxref (1)               - Pascal cross-reference program

Time: 0:20;O:20 to infinity.


.bp

        Filenames in the shell                  slide9


                + Names may use any letters, numbers and
                  special characters.

                + E.g. legal names:
                   a
                   rumplestiltskin
                   123
                   file.out.bak
                   =
                   one big name

                + The following are metacharacters:

                        * ? [ ] ~ . ' " $ 
                        (Usually not a good idea to make them part
                         of a file name.)

                + / and \ (slash and back-slash) have special meanings

                + ! and ^ (bang and caret) have a special meaning



.bp

        Metacharacters                          slide9.1
                        *       matches any string

                        ?       matches any character

                        [...]   matches any character in the brackets

                        ~       short for: home directory

                        .       short for: current directory

                        '       quotes strings containing metachacters

                        "       quotes strings containing metachacters

                        $       used to denote shell variable

                        \       "Escapes" or "quotes" the next character

                        /       The separator in paths.

                        !^      The history mechanism.
.bp


        Cat and ls                              slide10

         + stdin and stdout

         + Creating files with cat

              + Redirection

               cat > newfile    

         + Combining files with cat

              + More redirection

                cat a b > c

                cat a>c

                cat b>>c


          + ls  is a simple command to list your files.
                (See slide 14 for more about ls)
.bp

                    SUGGESTED EXERCISES

(11) Create a file containing a calendar. (Inspect it, using
     cat  )  Add a line commenting on the calendar.  Inspect
     the file again.

(12) Create a file containing the  calendar  for  the  years
     1985, 1986 and 1987 Inspect this file using 'more'.

(13) Use cat to create a file. Use cat to combine two files.

(14) Use apropos to see if there is any  way  to  get  phone
     information.  Try it.

(15) By now you have a few  files.  Try  different  ways  of
     listing  them.   (ls, ls -a, ls -l,ls [a-z]*, etc.  Try
     listing only some of them.

.bp



        File handling commands                  slide11

         + Moving files with mv [17]

                mv oldname newname

         + Copying files with cp [18]

                cp oldfile newcopy

                cp file1 file2 file3 somedirectory

                cp ~ggww/teach-vi .

         + Removing files

                rm file1

                rm *

                rm -i




.bp




        Editing with the screen editor          slide12


         + vi [20]

                vi filename


                        Exercise

     A. Copy  /usr/local/skel/teach-vi to  your  directory.
     (cp /usr/local/skel/teach-vi . ) The '.' IS part of the
     command.  Then use vi to edit teach-vi.  (vi  teach-vi)
     Try the stuff in teach-vi.
     B. This is an alternative to A. (above) Use vi to  edit
     a file you've created.  Try the commands on the summary
     sheet.






.bp

        Editing with the line editor            slide13

         + ex (ed edit) [19]

        A few commands:
                :a      append (a line with only a period '.' ends inserting)

                :s      substitute

                :w      write current version of buffer

                :q!     Leaves the editor without saving the
                        changes made since last :w (If no :w
                        this session, then no changes are saved.)

                :q      quit editing

                :vi     Switch to visual editing.




.bp

        Magic characters in the line editor     slide13.1


                .       any character

                *       0 or more occurrences of a string character.

                [xyz]   Any of x,y or z]

                [a-z]   Any of a through z

                ^       Beginning of line.

                $       End of line.

                [^a-zA-Z]  Any non-letter.

                &       On right means string from left.

                \       Turns the magic off.




.bp

        Addressing instructions                 slide13.2



                :se nu          Line numbers are seen.
                :se nonu        No line numbers shown, but they still work
                :n1,n2          Print lines n1 to n2
                :.              Print this line
                :.,+10          Print this line and 10 more.
                :.,-10          Print this line and 10 preceding.
                :/str/          Find next occurrence of str.
                :?str?          Find previous occurrence of str.
                :/              Repeat the last search.
                :$              The last line in the buffer.
                :1,$            Print whole file.
                :%              Shorthand for 1,$
                :-10            Go back 10 lines.
                :.,.+10w! temp  Write this line and next 10 into a file
                                called temp, overwriting "temp" if it
                                previously existed.







.bp

        Some examples                           slide13.3


        :s/str1/str2/           The first occurrence of str1 on this
                                line is changed to str2.

        :1,10s/str1/str2/       On lines 1 to 10, changes the first
                                occurrence of str1 to str2.

        :%s/str1/str2/g         Change all occurences of str1 to str2.

        :g/^$/d                 Removes all blank lines.

        :/^[^a-zA-Z]/           Go to next line with a non-letter as first
                                character. (Note two uses of ^)

        :%s/[^:]*://            On every line remove everything up to
                                and including the first colon.

        :%s/:.*//               Removes the ':' and everything which
                                follows on the current line.


.bp



        Files and directories                   slide14


         + Your home directory's path name
                pwd

         + The file system


         + ls [15]

              + ls

              + ls -l

              + ls -a

              + ls -l a*



.bp

        Directories and abbreviations           slide15

         + Directories and files are a tree structure

         + Creating directories with mkdir [21]

         + Removing directories with rmdir [22]

         + Where am I? pwd [23]

         + Removing a non-empty directory with rm -r

         + Wild card abbreviations

         + Special abbreviations ( . .. ~ )

.bp

        Protection Codes                        slide15.1


         + Protection codes

              + chmod [24]

         + Protection codes for directories

         + ls with special treatment of directories.

              + ls -d

              + ls -d *

              + ls -ld




                                                slide15.2
                    SUGGESTED EXERCISES


(16) Rename some of your files.

(17) Copy a file. Remove the old one. (Use ls to verify  the
     copying and the removal.)

(18) Use ex on any file. Try some of the powerful  commands.
     (E.g.  Try inserting a space before any character which
     is not a space.)

(19) Change into the parent directory of your  "home".  Look
     around. Do the same for /usr/bin.

(20) Create a directory. Copy some files into the new direc-
     tory. Change to the new directory. Create some files in
     there. Change back to your home directory and try  some
     different 'ls' commands.

(21) Try pwd in different directories.  Try cd and cd  ..  .
     Create  and remove a directory. Try putting a file into
     the directory first.

(22) Change the protection code so that  your  neighbor  can
     read  one  of  your  files. Do this inside a newly made
     directory.
.bp



        Pipes and Filters                       slide16


         + What is a filter?

         + fmt [26] 

.nf
%cat sloppy
This is a sloppily written letter.
It has short lines like the one  above  and  lines  that  are  really much too long as is this one.
%fmt sloppy
This is a sloppily written letter.  It has short lines like the one
above  and  lines  that  are  really much too long as is this one.

         + wc [28]

                %wc sloppy
                2      26     135 sloppy

         + head (tail) [29]


.bp

        Sort [25]                               slide16.1


% cat inventory
McCall,Joan     :ATH  :       :MIC :Seequa Chameleon Plus      :10753
Continuing Ed   :CED  :       :PRT :Daisy Writer Printer       :41039078
Biology Lab     :BIO  :S-206  :MIC :Apple II Plus              :A252-359-792
Continuing Ed   :CED  :       :MIC :Seequa Chameleon Plus      :10387
Continuing Ed   :CED  :       :MIC :Seequa Chameleon Plus      :10664
McCall,Joan     :ATH  :       :PRT :Televideo Letter Quality   :613-08679
Continuing Ed   :CED  :K-202  :MIC :Seequa Chameleon Plus      :50505
Continuing Ed   :CED  :       :PRT :Mannesmann Tally Spirit 80 :1020450


%sort inventory
Biology Lab     :BIO  :S-206  :MIC :Apple II Plus              :A252-359-792   
Continuing Ed   :CED  :       :MIC :Seequa Chameleon Plus      :10387          
Continuing Ed   :CED  :       :MIC :Seequa Chameleon Plus      :10664          
Continuing Ed   :CED  :       :PRT :Daisy Writer Printer       :41039078      
Continuing Ed   :CED  :       :PRT :Mannesmann Tally Spirit 80 :1020450        
Continuing Ed   :CED  :K-202  :MIC :Seequa Chameleon Plus      :50505          
McCall,Joan     :ATH  :       :MIC :Seequa Chameleon Plus      :10753          
McCall,Joan     :ATH  :       :PRT :Televideo Letter Quality   :613-08679      




.bp

        Sort [25]                               slide16.2

%sort -t: +1 inventory
McCall,Joan     :ATH  :       :MIC :Seequa Chameleon Plus      :10753          
McCall,Joan     :ATH  :       :PRT :Televideo Letter Quality   :613-08679      
Biology Lab     :BIO  :S-206  :MIC :Apple II Plus              :A252-359-792   
Continuing Ed   :CED  :       :MIC :Seequa Chameleon Plus      :10387          
Continuing Ed   :CED  :       :MIC :Seequa Chameleon Plus      :10664          
Continuing Ed   :CED  :       :PRT :Daisy Writer Printer       :41039078      
Continuing Ed   :CED  :       :PRT :Mannesmann Tally Spirit 80 :1020450        
Continuing Ed   :CED  :K-202  :MIC :Seequa Chameleon Plus      :50505          

%sort -t: +4.3 inventory
McCall,Joan     :ATH  :       :PRT :Televideo Letter Quality   :613-08679      
Biology Lab     :BIO  :S-206  :MIC :Apple II Plus              :A252-359-792   
Continuing Ed   :CED  :       :PRT :Mannesmann Tally Spirit 80 :1020450        
Continuing Ed   :CED  :       :MIC :Seequa Chameleon Plus      :10387          
Continuing Ed   :CED  :K-202  :MIC :Seequa Chameleon Plus      :50505          
Continuing Ed   :CED  :       :MIC :Seequa Chameleon Plus      :10664          
McCall,Joan     :ATH  :       :MIC :Seequa Chameleon Plus      :10753          
Continuing Ed   :CED  :       :PRT :Daisy Writer Printer       :41039078      



.bp

                                                slide16.2.1



% sort -t: +1 -2 +5 inventory
McCall,Joan     :ATH  :       :MIC :Seequa Chameleon Plus      :10753
McCall,Joan     :ATH  :       :PRT :Televideo Letter Quality   :613-08679
Biology Lab     :BIO  :S-206  :MIC :Apple II Plus              :A252-359-792
Continuing Ed   :CED  :       :PRT :Mannesmann Tally Spirit 80 :1020450
Continuing Ed   :CED  :       :MIC :Seequa Chameleon Plus      :10387
Continuing Ed   :CED  :       :MIC :Seequa Chameleon Plus      :10664
Continuing Ed   :CED  :       :PRT :Daisy Writer Printer       :41039078
Continuing Ed   :CED  :K-202  :MIC :Seequa Chameleon Plus      :50505






.bp



        Pipes                                   slide16.3

         + What is a pipe?

         + Some examples of pipes

How many users are on?
%who | wc
8      40     240

Is there an English word that can be made using only the letters a, l, r, t?
%cat /usr/dict/words | grep l | grep a | grep t| grep r | grep -v '[b-km-qsu-z]'
altar

Find the five most frequent words in any file (slides in this example):
%cat slides | tr -sc 'A-Za-z' '\012' | sort | uniq -c | sort -n | tail -5
27 A
28 the
29 a
29 and
51 slide

A couple of other examples:

tail +200 anyfile | head -20      (Prints lines 200-219 of file.)

Exercise: Find line 9980 in /usr/dict/words

du -a | grep anyfile              (Useful for locating a "lost" file.)



.bp

        A few miscellaneous commands            slide16.4

        + su            changing identities

        + sed           a filter to learn someday
                        (Like awk but faster and easier and less powerful)

        + file          when you don't know what you have

        + od            for computer experts only

.bp

        Making UNIX suit you                    slide17


    + .login

        %cat .login
        set path=(. /usr/local/bin /usr/ucb /bin /usr/bin /usr/new /usr/rt11)
        echo ''
        stty crt

    + .cshrc

        set prompt='[\!]: '
        set history=10
        set mail=/usr/spool/mail/`whoami`
        alias cd 'cd \!*;dirs'
        alias h history -r
        alias l ls -la


         + .profile





.bp




        Your Own Commands                       slide18

         + alias  (C-shell only)

                alias back 'set back=$old; set old=$cwd; cd $back; unset back'
                alias ampex 'setenv TERM ampex;set term=ampex; stty erase '
                alias h history -r



         + Shell scripts

                + shells - write new commands into a file, then they
                  can be tested and modified without retyping each time.
                  But remember to make the file executable.

                + source        

                + csh




                       Exercises

(23) Use a pipe to write a one line command to find  out  if
     your  neighbor  is logged on. This command shouild have
     only one line of output

(24) Use fmt from inside of vi.

(25) Use "head /etc/passwd > shortpw" to  get  part  of  the
     passwd  file  into  your  own account. Use sort to sort
     shortpw in various ways.  (Note that the field  separa-
     tor is ":".

(26) Add a command or two to your .login file.  Add an alias
     to your .cshrc file. Login again and try them.

.bp

        Documentation aids                      slide19





         + nroff -me [30]

         + spell [31]

         + diction [32] (Often available, but not on this system.)











.bp





        C-shell features                        slide20



         + history [33]
                !!
                ls !$
                !12
                !ls
                !ls:p
                !ls:1-3
                !ls:^
                !ls:$


         + Stopping and restarting jobs

                <ctrl-z>
                fg
                bg


                      Suggested Exercises

(27) Start editing a file. Use <ctrl/z> to stop it. Try some
     other commands.  Restart the editing job.

(28) Use some features of the history  mechanism  to  repeat
     commands.


(30) Combine head and tail using pipes to see the 10th  11th
     and 12th lines of a file.

(31) Try the file command on various groups of files.

(32) How many files are in /usr/bin ?

(33) Print out the names of the five largest files in /etc











.bp

        Footnotes
        ---------

     [1] passwd-A program to change passwords.

     [2] csh-A popular "shell".

     [3] date-A program that prints the time and date.

     [4] who-A program that shows who else is working.

     [5] echo-A program that repeats it's input.

     [6] cal-A program that prints a calendar of any year or
     month.

     [7] mail-A program to send or read electronic mail.

     [8] talk-A program that allows  you  to  type  messages
     back and forth between terminals.

     [9] /etc/passwd-The password file.

     [10] grep-A string searching program.

     [11] more,less-Programs to examine  large  files  at  a
     relaxed pace. (Less is seen less often these days.)

     [12] man-A program that prints out  a  section  of  the
     manual.

     [13] apropos-A program that examines the manual's index
     and finds anything appropriate.

     [14] learn-A computer teaching program (now unavailable)

     [15] ls-A program that  lists  your  files  and  direc-
     tories.

     [16] cat-A program that outputs files.

     [17] mv-A program to rename files and move files into directories.

     [18] cp-A program to copy files.



.bp


        Glossary


     [19] ed,edit,ex-Different versions of the most  popular
     UNIX text editor.

     [20] vi-A visual (screen) editor.

     [21] mkdir-A program to create sub-directories.

     [22] rmdir-A program that removes (empty) directories.

     [23] pwd-Print Working Directory -  reminds  you  where
     you are.

     [24] chmod-CHange MODe, lets you make files and  direc-
     tories more or less available to others.

     [25] sort-Sorts files,by lines, almost any way you  can
     imagine.

     [26] fmt-The simplest formatting program in UNIX.

     [27] pr-A program that prepares files for printing.

     [28] wc-Word Count--Counts the lines words and  charac-
     ters in a file.

     [29] head (tail)-Lets you see  just  the  first  (last)
     lines of a file.

     [30] nroff-A word processing program.

     [31] spell-Checks your spelling.

     [32] diction-Checks for awkward or incorrect phrases.

     [33] history-Lists your recent commands.
                                                slide0
        What is UNIX?                           slide1
        Getting started                         slide2
        Which shell?                            slide2.1
        Elementary redirection                  slide3
        cal                                     slide4
        Communications                          slide5
        mail and grep                           slide6
        mail - some details                     slide6.1
        who and finger                          slide7
        Learning by yourself                    slide8
        Filenames in the shell                  slide9
        Metacharacters                          slide9.1
        Cat and ls                              slide10
                (See slide 14 for more about ls)
        File handling commands                  slide11
        Editing with the screen editor          slide12
        Editing with the line editor            slide13
        Magic characters in the line editor     slide13.1
        Addressing instructions                 slide13.2
        Some examples                           slide13.3
        Files and directories                   slide14
        Directories and abbreviations           slide15
        Protection Codes                        slide15.1
        Pipes and Filters                       slide16
        Sort [25]                               slide16.1
        Sort [25]                               slide16.2 slide16.2.1
        Pipes                                   slide16.3
        Making UNIX suit you                    slide17
        Your Own Commands                       slide18
        Documentation aids                      slide19
        C-shell features                        slide20
