Lecture 1

Agenda

  1. Course Information.(Sign-In sheet)
  2. Intro to UNIX
  3. Getting Started
  4. Files

Definitions:

1. Operating System:
An operating system is the program that controls all the other parts of a computer system - both the hardware and the software. Most importantly, it allows you to make use of the facilities provided by the system. Every computer has an operating system.
Eg: UNIX, DOS, Windows-95
The UNIX operating system has three important features; a kernel, the shell and a filesystem.

Draw U.I, Shell, Kernel diagram

2. Kernel:
It is at the core of each UNIX system and is loaded in whenever the system is started up - referred to as a boot of the system.

3. Shell
Interfaces User and O.S.  Whenever you login to a Unix system you are placed in a program called the shell. You can see its prompt at the bottom left of your screen. To get your work done, you enter commands at this prompt. A quick way to see what shells are available on a your system is to display the file /etc/shells. For example:

   cat /etc/shells

4. POSIX.2:
9 proposed stds. Only 2 were finalized and published.
0.1 Library functions for Kernal.
0.2 Shell and Standard utilities.

5. History:
first UNIX system Bell Labs 1969, Thomson and Ritchie
MULTICS(Bell, MIT, GE) large scale OS
Design decisions: Simplicity, small kernel, single task well 1973 C lang kernel in C
UNIX versions System V bell (next few years)
                         BSD UCal Berkeley
            POSIX Standard(80's)

6. Open Systems:
Defining OS std does not mean whole system is specified. Hardware issues(equipment & s/w issues. working on system A no guarantee will work for system B if it works for system A
Handle incompatibilites vendors of h/w and s/w make a conscious decison to create products which will work together. POSIX is wide ranging. In practice minor problem.
UI,COSE,OSF are consortia by manufaturers to promote open systems.

Why learn UNIX?

  1. UNIX features: Simple programs, Single tasking very well, Easy linkage of programs, Build complex programs Small kernel(in C), C compliant.
  2. Not just an OS. It is a philosophy of programming
  3. Learning UNIX involves becoming familiar with commands and methodology it employs
  4. Very powerful for experienced practitioners, daunting for novices.
  5. This course:

Getting started

To login to your account:

    login: calvin
    Password:

This logs in the person who has been given the username calvin on this system. UNIX is case sensitive. If your username is "hobbes", do not enter HOBBES or Hobbes.

Logging out

To finish using a UNIX system you must go through a process known as "logging out".

To logout enter the command logout or exit. If this does not work press Ctrl-D.
 

To change your password:

   passwd
   Old password: enter your current password
   New password: enter your new password
   Retype new password: re-enter your new password

Enter the command passwd and then respond to the prompts by entering your old password followed by your new
one. You are then asked to confirm your new password.

Date

*    date
      Tue Dec 5 13:00:00 EST 1999

*    uname       (OS)
      OSF1

     uname -a     OS, name of machine, release, version, h/w)
OSF1 siren.cs.umass.edu V3.2 62 alpha

     Options -m(machine), -n(nodename) , -s(system name), -v(version
uname -r -v
uname -v -r
uname -rv
uname -vr

*    tty  displays terminal

/dev/ttyp1

who      lists those currently loged on by username

araja       ttyp1       Jan  5 10:40
pxuan       ttyp2       Dec 29 19:32
pxuan       ttyp4       Dec 29 14:08
bhorling    ttypa       Dec  8 11:06

*who -u

-u  Displays the username, terminal name, login time, line
           activity, and process-ID of each current user.

araja       ttyp1       Jan  5 10:40       .       20216
pxuan       ttyp2       Dec 29 19:32      old      14141
pxuan       ttyp4       Dec 29 14:08      0:05     13884
bhorling    ttypa       Dec  8 11:06     23:57     28138
 

Files

*  ls

 * vi myfile

 * emacs, pico

Input/Output streams

figure 2.4
 
 
 
 
 
 

Each command has associated with input/output streams. called standard input, std output and std error
*I/O streams. Input from keyboard and output and error to terminal screen.
0 for input (command input), 1 for output(command output) and 2 for error(wartning messages, try to print a file that does not exist, general info also not output).

* cat myfile
hello
there

* cat (no args, input from std input)
abc       standard input
abc       standard output
def        input
def        output

Redirection:

< input
> output
>> append

 cat <myfile

 date >xyz

 cat myfile xyz

 cat <myfile >def

 cat myfile >def

?? cat a >a

cat myfile -

Q) Create a file called theusers containing a list of those users currently logged in

who >theusers

*rm -i theusers (remove with confirmation)

 cat myfile nofile
hello
there
cat: nofile: No such file or directory

??cat myfile nofile 2>error 1>output

cat output
hello
there

cat error
cat: nofile: No such file or directory

date >outfile
date >>outfile
cat outfile
Tue Jan  5 11:00:20 EST 1999
Tue Jan  5 11:00:24 EST 1999

Emergency
^C Big file, interrupt command
^D Simply closes input stream

* more /usr/dict/words
Space next page
b prev page
Ret scroll forward one line
? print page of help
q quit

*mailx -s "hw" sam
Hello Sam
Have u finished the hw?
^D
 

mailx
lists mails
 

**************************End of lecture*************

Pipes
Diagram?? Figure 2.9

*X|Y  == X > tmp & Y < tmp
 

Q) Send email msg to sam which will inform sam of current time and date??
date send to stdout the time and date and mailx sends a msg from input stream.

date | mailx -s "Todays time and date" sam

Scripts

file whenandwho with
date
who

*sh whenandwho

* echo Hello there (Useful for writng scripts)
Hello there

?? A script called niceday which will output today's time and day with a user friendly message.

The time and date are now:

araja:~$ cat >niceday
echo The time and date are now:
date
echo Have a nice day!

araja:~$ sh niceday
The time and date are now:
Tue Jan  5 11:17:05 EST 1999
Have a nice day!

Script can have redirections and pipes

eg: Mail sam a message which says running my script now

echo running my script now  | mailx -s "What I'm doing" sam
 
 
 
 

Making copies of input/output

Suppose u want to print something to the screen and save in afile

Send user jo and keep a mcopy of the message in file jo_message.
tee jo_message | mailx jo
hi
^D

cat jo_message
hi
 

Getting help
man who

Name, Synopsis, Description, Option

Find out how to print the current h/w type on which your system is running by using uname

man uname

and -m option does it
 

Q) To find command which will print out just your login name
man -k  login
logname
 

Files:
Diagram of directory structure

*
*
*

pwd(Current location within file system)
/nfs/mesmer/u1/dis/araja

cd /usr/ugrad/sam
cd /squiggle
/squiggle no such file or dir

ls /        lists files in root
cdrom/ etc/

cd  /bin
pwd
ls

To list files in adi's homedir
ls ~adi
 
 

Filesystems
df

Manipulating files

mkdir dir1
ls
myfile

cp myfile foo(creates new inode)

mv myfile bar

ls

ln /cs/grad/sam/datafile samsdata (links -s  )

      -f     Forces the removal of existing target pathnames before
               linking.

       -s  Creates symbolic links.

       -n  If  the target already exists, do not create the link,
           and issue an error message. -f overrides -n.  Requires
           the  environment  variable  CMD_ENV to be set to svr4.
           This mimics the behavior of the  ln  command  with  no
           flags when CMD_ENV is not set.