Caveat Lector: These are some notes for a basic course on Unix which I co-taught many years ago at the University of Calgary. I keep them online in the hope that they may be useful to someone. However, they are not maintained. They may contain information specific to one (historic) network, which will not apply universally. Links may be broken.

[ home ]


Computer Science 001

Introduction to Unix

September 1998

Part One



 

The File System:

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Multi-User systems:

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Multi-tasking systems:

Processes:

Networking:


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Working with Unix:

                                          Login:
                                        Password:
 
 
 
 

                                        <text>

                                        %                                                                     (the prompt)
 
 
 
 
 
 
 

User accounts:

The Shell:

 

The Online Manual Pages:


 

man(1)                                                     man(1)
 

NAME
       man - format and display the on-line manual pages
       manpath - determine user's search path for man pages

SYNOPSIS
       man [-acdfhkKtwW] [-m system] [-p string] [-C config_file]
       [-M path] [-P pager] [-S section_list] [section] name  ...

DESCRIPTION
       man  formats  and displays the on-line manual pages.  This
       version knows about the MANPATH and (MAN)PAGER environment
       variables, so you can have your own set(s) of personal man
       pages and choose whatever program you like to display  the
       formatted  pages.  If section is specified, man only looks
       in that section of the manual.  You may also  specify  the
       order to search the sections for entries and which prepro-
       cessors to run  on  the  source  files  via  command  line
       options  or  environment  variables.  If name contains a /
       then it is first tried as a filename, so that you  can  do
       man ./foo.5 or even man /cd/foo/bar.1.gz.

OPTIONS
       -C  config_file
              Specify  the man.config file to use; the default is
              /etc/man.config.  (See man.config(5).)

       -M  path
              Specify the list of directories to search  for  man
              pages.  If no such option is given, the environment
              variable MANPATH is used. If  no  such  environment
              variable  is  found,  the  default list is found by
              consulting /etc/man.config.  An empty substring  of
              MANPATH denotes the default list.

       -P  pager
              Specify  which pager to use.  This option overrides
              the MANPAGER environment variable,  which  in  turn
              overrides the PAGER variable.  By default, man uses
              /usr/bin/less-is.

       -S  section_list
              List is a colon separated list of  manual  sections
              to search.  This option overrides the MANSECT envi-
              ronment variable.

       -a     By default, man  will  exit  after  displaying  the
              first  manual  page  it  finds.   Using this option
              forces man to display all  the  manual  pages  that
              match name, not just the first.

       -c     Reformat  the  source man page, even when an up-to-
              date cat page exists.  This can  be  meaningful  if
              the cat page was formatted for a screen with a dif-
              ferent number of columns.
 

       -d     Don't actually display the man pages, but do  print
              gobs of debugging information.

       -D     Both display and print debugging info.

       -f     Equivalent to whatis.

       -h     Print a one-line help message and exit.

       -k     Equivalent to apropos.

       -K     Search for the specified string in *all* man pages.
              Warning: this is probably very slow!  It  helps  to
              specify  a section.  (Just to give a rough idea, on
              my machine this takes about a minute  per  500  man
              pages.)

       -m  system
              Specify  an  alternate  set  of man pages to search
              based on the system name given.

       -p  string
              Specify the sequence of preprocessors to run before
              nroff  or troff.  Not all installations will have a
              full set of preprocessors.  Some of the  preproces-
              sors  and  the  letters used to designate them are:
              eqn (e), grap (g), pic (p), tbl  (t),  vgrind  (v),
              refer  (r).   This  option overrides the MANROFFSEQ
              environment variable.

       -t     Use /usr/bin/groff -Tps -mandoc to format the  man-
              ual page, passing the output to stdout.  The output
              from /usr/bin/groff -Tps -mandoc  may  need  to  be
              passed  through some filter or another before being
              printed.

       -w or --path
              Don't actually display the man pages, but do  print
              the  location(s) of the files that would be format-
              ted or displayed. If no argument is given:  display
              (on   stdout)  the  list  of  directories  that  is
              searched by man for man pages. If manpath is a link
              to  man,  then  "manpath"  is  equivalent  to  "man
              --path".

       -W     Like -w, but print file names one per line, without
              additional  information.   This  is useful in shell
              commands like man -aW man | xargs ls -l
 

CAT PAGES
       Man will try to save the formatted man pages, in order  to
       save formatting time the next time these pages are needed.
       Traditionally, formatted versions of pages in DIR/manX are
 

       saved  in DIR/catX, but other mappings from man dir to cat
       dir can be specified in /etc/man.config.  No cat pages are
       saved when the required cat directory does not exist.

       It  is possible to make man suid to a user man. Then, if a
       cat directory has owner man and mode 0755  (only  writable
       by man), and the cat files have owner man and mode 0644 or
       0444 (only writable by man, or not writable  at  all),  no
       ordinary  user can change the cat pages or put other files
       in the cat directory. If man is not made suid, then a  cat
       directory  should  have  mode  0777 if all users should be
       able to leave cat pages there.

       The option -c forces reformatting a page, even if a recent
       cat page exists.

ENVIRONMENT
       MANPATH
              If MANPATH is set, its value is used as the path to
              search for manual pages.

       MANROFFSEQ
              If MANROFFSEQ is set, its value is used  to  deter-
              mine  the  set  of preprocessors run before running
              nroff or  troff.   By  default,  pages  are  passed
              through the table preprocessor before nroff.

       MANSECT
              If  MANSECT  is set, its value is used to determine
              which manual sections to search.

       MANWIDTH
              If MANWIDTH is set, its value is used as the  width
              manpages  should be displayed.  Otherwise the pages
              may be displayed  over  the  whole  width  of  your
              screen.

       MANPAGER
              If  MANPAGER  is set, its value is used as the name
              of the program to use to display the man page.   If
              not,  then  PAGER  is  used.  If  that has no value
              either, /usr/bin/less -is is used.

       LANG   If LANG is set, its value defines the name  of  the
              subdirectory  where  man first looks for man pages.
              Thus, the command `LANG=dk man 1  foo'  will  cause
              man   to   look   for   the   foo   man   page   in
              .../dk/man1/foo.1, and if it  cannot  find  such  a
              file, then in .../man1/foo.1, where ... is a direc-
              tory on the search path.

       NLSPATH, LC_MESSAGES, LANG
              The environment variables NLSPATH  and  LC_MESSAGES
              (or  LANG  when  the  latter does not exist) play a
              role in locating the  message  catalog.   (But  the
              English  messages  are compiled in, and for English
              no catalog is required.)  Note that  programs  like
              col(1) called by man also use e.g. LC_CTYPE.

       PATH   PATH  is  used  in  the construction of the default
              search path for man pages.

       SYSTEM SYSTEM is used to get the default alternate  system
              name (for use with the -m option).

SEE ALSO
       apropos(1), whatis(1), less(1), groff(1).

BUGS
       The  -t  option  only  works  if  a  troff-like program is
       installed.
       If you see blinking \255 or <AD> instead of  hyphens,  put
       `LESSCHARSET=latin1' in your environment.
 
 

Basic Commands:

 

 
 
 
 
 
 
 
 
 
 
 

Introduction to Unix Intermediate:

 

 
 
 

.....

Intermediate Commands:


From the network using rlogin/telnet


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Pipes and redirection:

 

File permissions and sharing:

 
 
 
 
 
 
 
 
 
 
 
 
 

Changing file permission modes:

dutton@coral:ddd>ls -l test
-rw-------   1 dutton   staff           0 Aug 28 20:51 test

dutton@coral:ddd>chmod g+r test
dutton@coral:ddd>ls -l test
-rw-r-----   1 dutton   staff           0 Aug 28 20:51 test

dutton@coral:ddd>chmod a+rw test
dutton@coral:ddd>ls -l test
-rw-rw-rw-   1 dutton   staff           0 Aug 28 20:51 test

dutton@coral:ddd>chmod a-w test
dutton@coral:ddd>ls -l test
-r--r--r--   1 dutton   staff           0 Aug 28 20:51 test
 
 
 

dutton@coral:ddd>chmod 600 test
dutton@coral:ddd>ls -l test
-rw-------   1 dutton   staff           0 Aug 28 20:51 test

dutton@coral:ddd>chmod 640 test
dutton@coral:ddd>ls -l test
-rw-r-----   1 dutton   staff           0 Aug 28 20:51 test

dutton@coral:ddd>chmod 666 test
dutton@coral:ddd>ls -l test
-rw-rw-rw-   1 dutton   staff           0 Aug 28 20:51 test

dutton@coral:ddd>chmod 444 test
dutton@coral:ddd>ls -l test
-r--r--r--   1 dutton   staff           0 Aug 28 20:51 test
 
 

Other useful commands:


NAME
     rlogin - remote login

SYNOPSIS
     rlogin [-8EKLdx] [-e char] [-k realm] [-l username] host

DESCRIPTION
     Rlogin starts a terminal session on a remote host host.


NAME
     chmod - change the permissions mode of a file

SYNOPSIS
     chmod [ -fR ] <absolute-mode> file...
     chmod [ -fR ] <symbolic-mode-list> file...

AVAILABILITY
     SUNWcsu

DESCRIPTION
     chmod changes or assigns the mode of a file.  The mode of  a
     file  specifies  its  permissions and other attributes.  The
     mode may be absolute or symbolic.


NAME
     chgrp - change file group ownership

SYNOPSIS
     chgrp [ -fhR ] group file

AVAILABILITY
     SUNWcsu

DESCRIPTION
     The chgrp utility will set the group ID of the file named by
     each  file  operand  to  the group ID specified by the group
     operand.


NAME
     chown - change file ownership

SYNOPSIS
     chown [ -fhR ] owner[:group] file...

AVAILABILITY
     SUNWcsu

DESCRIPTION
     The chown utility will set the user ID of the file named  by
     each  file  to  the user ID specified by owner, and, option-
     ally, will set the group ID to that specified by group.


NAME
     umask - get or set the file mode creation mask

SYNOPSIS
     /usr/bin/umask [ -S ] [ mask ]

  sh
     umask [ ooo ]

  csh
     umask [ ooo ]

  ksh
     umask [ -S ] [ mask ]


NAME
     touch - change file access and modification times

SYNOPSIS
     touch [-acm] [-r ref_file] file...
     touch [-acm] [-t time] file...
     touch [-acm] [date_time] file...

AVAILABILITY
     SUNWcsu

DESCRIPTION
     touch sets the access and modification times of  each  file.
     file is created if it does not already exist.


NAME
     cd, chdir, pushd, popd, dirs - change working directory

SYNOPSIS
     /usr/bin/cd [ directory ]

  sh
     cd [ argument ]
     chdir [ argument ]

  csh
     cd [ dir ]
     chdir [ dir ]
     pushd [ +n | dir]
     popd [ +n ]
     dirs [ -l ]

  ksh
     cd [ arg ]
     cd old new


NAME
     head - display first few lines of files

SYNOPSIS
     head [ -number | -n number ] [ filename...  ]

AVAILABILITY
     SUNWcsu

DESCRIPTION
     The head utility copies the first number of  lines  of  each
     filename  to  the standard output.  If no filename is given,
     head copies lines from  the  standard  input.   The  default
     value of number is 10 lines.


NAME
     tail - deliver the last part of a file

SYNOPSIS
     /usr/bin/tail [ + number [ lbcr ]] [ file ]
     /usr/bin/tail [ -lbcr ] [ file ]
     /usr/bin/tail [ + number [ lbcf ]] [ file ]
     /usr/bin/tail [ -lbcf ] [ file ]

     /usr/xpg4/bin/tail [ -f | -r ] [ -c number | -n number ]
          [ file ]
     /usr/xpg4/bin/tail [ + number [ l | b | c ] [ f ]] [ file ]
     /usr/xpg4/bin/tail [ + number [ l ] [ f | r ]] [ file ]

AVAILABILITY
  /usr/bin/tail
     SUNWcsu

  /usr/xpg4/bin/tail
     SUNWxcu4

DESCRIPTION
     The tail command copies the named file to the standard  out-
     put  beginning  at a designated place.  If no file is named,
     the standard input is used.


NAME
     finger - display information about local and remote users

SYNOPSIS
     finger [ -bfhilmpqsw ] [ username...  ]

     finger [-l ]  [  username@hostname1[@hostname2...@hostnamen]
     ...  ]

     finger [-l ] [ @hostname1[@hostname2...@hostnamen] ...  ]

AVAILABILITY
     SUNWcsu

DESCRIPTION
     By default, the finger command displays in multi-column for-
     mat the following information about each logged-in user


NAME
     who - who is on the system

SYNOPSIS
     /usr/bin/who [ -abdHlmpqrstTu ] [ file ]
     /usr/bin/who -q [ -n x ] [ file ]
     /usr/bin/who am i
     /usr/bin/who am I

     /usr/xpg4/bin/who [ -abdHlmpqrtTu ] [ file ]
     /usr/xpg4/bin/who -q [ -n x ] [ file ]
     /usr/xpg4/bin/who -s [ -bdHlmpqrtu ] [ file ]
     /usr/xpg4/bin/who am i
     /usr/xpg4/bin/who am I

AVAILABILITY
  /usr/bin/who
     SUNWcsu

  /usr/xpg4/bin/who
     SUNWxcu4

DESCRIPTION
     The who command can list the  user's  name,  terminal  line,
     login  time,  elapsed  time  since  activity occurred on the
     line, and the process-ID of the command interpreter  (shell)
     for   each  current  UNIX  system  user.   It  examines  the
     /var/adm/utmp file to obtain its information.   If  file  is
     given,  that file (which must be in utmp(4) format) is exam-
     ined.  Usually, file will be /var/adm/wtmp, which contains a
     history of all the logins since the file was last created.


NAME
     rwho - who's logged in on local machines

SYNOPSIS
     rwho [ -a ]

AVAILABILITY
     SUNWcsu

DESCRIPTION
     The rwho command produces output similar to who(1), but  for
     all  machines  on  your  network.   If  no  report  has been
     received from a machine for  5  minutes,  rwho  assumes  the
     machine  is down, and does not report users last known to be
     logged into that machine.

     If a user has not typed to the system for a minute or  more,
     rwho reports this idle time.  If a user has not typed to the
     system for an hour or more, the user  is  omitted  from  the
     output of rwho unless the -a flag is given.


NAME
     ruptime - show host status of local machines

SYNOPSIS
     ruptime [ -alrtu ]

AVAILABILITY
     SUNWcsu

DESCRIPTION
     ruptime gives a status line like uptime for each machine  on
     the  local  network; these are formed from packets broadcast
     by each host on the network once a minute.

     Machines for which no status report has been received for  5
     minutes are shown as being down.

     Normally, the listing is sorted by host name, but this order
     can  be  changed  by  specifying  one  of the options listed
     below.


NAME
     uptime - show how long the system has been up

SYNOPSIS
     uptime

AVAILABILITY
     SUNWcsu

DESCRIPTION
     The uptime command prints the current time,  the  length  of
     time  the system has been up, and the average number of jobs
     in the run queue over the last 1, 5 and 15 minutes.  It  is,
     essentially,  the first line of a w(1) command.


NAME
     du - summarize disk usage

SYNOPSIS
     /usr/bin/du [ -adkr ] [ -s | -o ] [ file... ]
     /usr/xpg4/bin/du [ -a | -s ] [ -krx ] [ file... ]

AVAILABILITY
  /usr/bin/du
     SUNWcsu

  /usr/xpg4/bin/du
     SUNWxcu4

DESCRIPTION
     The du utility writes to standard output  the  size  of  the
     file  space  allocated  to,  and  the size of the file space
     allocated to each subdirectory of, the file hierarchy rooted
     in  each of the specified files.  The size of the file space
     allocated to a file of type directory is defined as the  sum
     total  of space allocated to all files in the file hierarchy
     rooted in the directory plus  the  space  allocated  to  the
     directory itself.


NAME
     tar - create tape archives and add or extract files

SYNOPSIS
     tar c [bBefFhiloPvwX [ 0-7 ]] [ block ] [ tarfile ]
          [ exclude-file ] { -I include-file |
          -C directory file | file } ...

     tar r [ bBefFhilvw [ 0-7 ]] [ block ]
          { -I include-file | -C directory file | file } ...

     tar t [ BefFhilvX [ 0-7 ]] [ tarfile ]
          [ exclude-file ] { -I include-file | file } ...

     tar u [ bBefFhilvw [ 0-7 ]] [ block ] [ tarfile ] file ...

     tar x [ BefFhilmopvwX [ 0-7 ]] [ tarfile ]
          [ exclude-file ] [ file ... ]

AVAILABILITY
     SUNWcsu

DESCRIPTION
     The tar command archives and extracts files to  and  from  a
     single  file  called a tarfile.


NAME
     gzip, gunzip, zcat - compress or expand files

SYNOPSIS
     gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ... ]
     gunzip [ -acfhlLnNrtvV ] [-S suffix] [ name ... ]
     zcat [ -fhLV ] [ name ... ]

DESCRIPTION
     Gzip reduces the size of the named  files  using  Lempel-Ziv
     coding  (LZ77).  Whenever possible, each file is replaced by
     one with the extension .gz, while keeping the same ownership
     modes,  access  and modification times.  (The default exten-
     sion is -gz for VMS, z for MSDOS, OS/2 FAT, Windows  NT  FAT
     and Atari.)  If no files are specified, or if a file name is
     "-", the standard input is compressed to the  standard  out-
     put.   Gzip will only attempt to compress regular files.  In
     particular, it will ignore symbolic links.


NAME
     diff - display line-by-line  differences  between  pairs  of
     text files

SYNOPSIS
     diff [ -bitw ] [ -c | -e | -f | -h | -n ] file1 file2
     diff [ -bitw ] [ -C number ] file1 file2
     diff [ -bitw ] [ -D string ] file1 file2
     diff [ -bitw ] [ -c | -e | -f | -h | -n ] [ -l ] [ -r ]
          [ -s ] [ -S name ] directory1 directory2

AVAILABILITY
     SUNWesu

DESCRIPTION
     The diff utility will compare  the  contents  of  file1  and
     file2  and write to standard output a list of changes neces-
     sary to convert file1  into  file2.   This  list  should  be
     minimal.  No output will be produced if the files are ident-
     ical.


NAME
     sort - sort, merge, or sequence check text files

SYNOPSIS
     /usr/bin/sort [ -cmu ] [ -o output ] [ -T directory ]
          [ -y [ kmem ]] [ -z recsz ] [ -dfiMnr ] [ - b  ]  [   -
     t char ]
          [ -k keydef ] [ +pos1 [ -pos2 ]] [ file...]

     /usr/xpg4/bin/sort [ -cmu ] [ -o output ]
          [ -T directory ] [ -y [ kmem ]] [ -z recsz ] [ - dfiMnr
     ] [ -b ] [ -t char ]
          [ -k keydef ] [ +pos1 [ -pos2 ]] [ file...]

AVAILABILITY
  /usr/bin/sort
     SUNWesu

  /usr/xpg4/bin/sort
     SUNWxcu4

DESCRIPTION
     The sort command sorts lines of all the named files together
     and writes the result on the standard output.


NAME
     cut - cut out selected fields of each line of a file

SYNOPSIS
     cut -b list [ -n ] [ file ... ]
     cut -c list [ file ... ]
     cut -f list [ -d delim ] [ -s ] [ file ...  ]

AVAILABILITY
     SUNWcsu

DESCRIPTION
     Use cut to cut out columns from a table or fields from  each
     line  of  a  file;  in data base parlance, it implements the
     projection of a relation.  The fields as specified  by  list
     can  be  fixed  length, that is, character positions as on a
     punched card (-c option) or the length can vary from line to
     line and be marked with a field delimiter character like TAB
     (-f option).  cut can be used as a filter.


NAME
     ps - report process status

SYNOPSIS
     ps [ -aAcdefjl ] [ -g grplist ] [ -n namelist ]
          [[ -o format ] ... ] [ -p proclist ]
          [ -s sidlist ] [ -t term ] [ -u uidlist ]
          [ -U uidlist ] [ -G gidlist ]

AVAILABILITY
     SUNWcsu

DESCRIPTION
     The ps command prints information  about  active  processes.
     Without options, ps prints information about processes asso-
     ciated with the controlling terminal.  The  output  contains
     only  the process ID, terminal identifier, cumulative execu-
     tion time, and the command name.  Otherwise, the information
     that is displayed is controlled by the options.

OPTIONS
     The following options are supported:

     -a             Print information about  all  processes  most
                    frequently  requested:  all those except pro-
                    cess group leaders and processes not  associ-
                    ated with a terminal.

     -A             Write information for all processes.

     -c             Print information in a format  that  reflects
                    scheduler    properties   as   described   in
                    priocntl(1).  The -c option affects the  out-
                    put  of  the  -f and -l options, as described
                    below.

     -d             Print information about all processes  except
                    session leaders.

     -e             Print information  about  every  process  now
                    running.

     -f             Generate a full listing.  (See below for sig-
                    nificance of columns in a full listing.)

     -g grplist     List only process data whose  group  leader's
                    ID  number(s)  appears  in grplist.  (A group
 
 

Example:

dutton@csa:dutton>ps -af
     UID   PID  PPID  C    STIME TTY      TIME CMD
    root 19109 18537  0   Aug 24 pts/0    0:00 su
    root 19963 19109  0   Aug 24 pts/0    0:00 /usr/local/bin/less -eMq
    root 19585 19355  0 15:24:34 pts/1    0:00 ps -af
   royko 18554 18537  0   Aug 24 pts/0    0:01 xbiff
    root 19962 19109  0   Aug 24 pts/0    0:00 nroff -man mwm.1
 


 NAME
     kill - terminate or signal processes

SYNOPSIS
     /usr/bin/kill -s signal pid...
     /usr/bin/kill -l [exit_status]
     /usr/bin/kill [ -signal ] pid...

AVAILABILITY
     SUNWcsu

DESCRIPTION
     The kill utility sends a signal to the process or  processes
     specified by each pid operand.

     For each pid operand, the kill utility will perform  actions
     equivalent to the kill(2) function called with the following
     arguments:

          1.   The value of the pid operand will be used  as  the
               pid argument.

          2.   The sig argument is the value specified by the - s
               option, or by SIGTERM, if none of these options is
               specified.

     The signaled process must belong to the current user  unless
     the user is the super-user.


NAME
     which - locate a command; display its pathname or alias

SYNOPSIS
     which [ filename ] ...

AVAILABILITY
     SUNWcsu

DESCRIPTION
     which takes a list of names and looks for  the  files  which
     would  be  executed  had these names been given as commands.
     Each argument is expanded if it is aliased, and searched for
     along the user's path.  Both aliases and path are taken from
     the user's .cshrc file.

FILES
     ~/.cshrc            source of aliases and path values
     /usr/bin/which

SEE ALSO
     csh(1)

DIAGNOSTICS
     A diagnostic is given for names which are  aliased  to  more
     than  a single word, or if an executable file with the argu-
     ment name was not found in the path.

NOTES
     which is not a shell built-in command; it is the  UNIX  com-
     mand, /usr/bin/which


NAME
     whereis - locate the binary, source, and manual  page  files
     for a command

SYNOPSIS
     /usr/ucb/whereis [ -bmsu ] [   - BMS  directory...    - f  ]
     filename...

AVAILABILITY
     SUNWscpu

DESCRIPTION
     whereis  locates  source/binary  and  manuals  sections  for
     specified  files.   The supplied names are first stripped of
     leading pathname components and any (single) trailing exten-
     sion  of  the  form  .ext,  for example, .c.  Prefixes of s.
     resulting from use of source code  control  are  also  dealt
     with.   whereis  then attempts to locate the desired program
     in a list of standard places: