01 Introduction Unix Os

48
Introduction to UNIX CET 421 Objectives Motivate the use of UNIX Introduce basic UNIX features (e.g. using directories,  files) Introduce vi and emacs

Transcript of 01 Introduction Unix Os

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 1/48

Introduction to UNIXCET 421

Objectives

Motivate the use of UNIX

Introduce basic UNIX features (e.g. using directories, files)

Introduce vi and emacs

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 2/48

Contents

1. Background on UNIX

2. Starting / Finishing

3. Typing UNIX Commands

4. Commands to Use Right Away

5. UNIX help

continued

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 3/48

6. The UNIX File System

7. Working with Directories

8. Working with Files

9. Communicating with People

10. E-mail

11.  vi/emacs

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 4/48

1.Background on UNIX

1.1. What is UNIX?

1.2. Histor y

1.3. Why use UNIX?

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 5/48

What is Unix?

 A f ully featured moder n operating system 

It is available in a variety of ³flavors.´ 

It¶s comprised of  simple tools that perform a single f unction well.

These tools can be used together  to perform complex tasks.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 6/48

1.1. What is UNIX?

The UNIX Operating System (OS) is a large program (mostly coded in C) that tur ns the computer  into a useable machine.

It provides a number  of  facilities:

management of  hardware resources

director y and file system loading / execution / suspension of programs

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 7/48

History

Beginnings in 1969  AT & T Bell Laboratories

Ken Thompson and Dennis Richie

Working version (in 1970) on a DEC PDP 11/70

UNIX and C Relationship June 81: Berkeley UNIX 4.1 BSD (enhanced with vi , csh, and 

virtual memory management )

1983: Berkeley UNIX 4.2 BSD (added TCP/IP networking, 

sockets and a new file system) Later   UNIX/32V, SYSTEM III, SYSTEM V

and then Linux

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 8/48

1.2.(Brief)

H

istory 1969 First UNIX at Bell Labs

1975 Bell Labs makes UNIX freeware

1970¶s Berkeley UNIX (BSD)

1980¶s TCP/IPMIT X-Windows

1990¶s The Web,LINUX

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 9/48

1.3. Wh

y Use UNIX? multi-tasking / multi-user 

lots of  software

networking capability

graphical (with command line)

easy to program 

portable (PCs, mainframes, super -computers)

continued

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 10/48

free! (LINUX, FreeBSD, GNU)

popular 

profitable1996 Sales: US$34.5 Billion, up 12%

not tied to one company

active community

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 11/48

UNIX Hardware is surrounded  by the operating system 

software

Operating system is called the system ker nel

The ker nel is the core of  an operating system and manages the machine¶s hardware resources (including the processor  and the memor y), and provides and controls the way any other  software component canaccess these resources.  The ker nel r uns with a higher privilege than other programs 

(so-called user -mode programs).  Comes with a number  of user  services and interfaces

Shell

Components of  the C compiler 

GUI or Command Line Interface

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 12/48

UNIX

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 13/48

M

odern UNIX Systems System V Release 4 (SVR4)

Solaris 9

4.4BSD

Linux

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 14/48

Unix is Made Up of ProcessesProcesses

Running ProgramsRunning ProgramsUser  owned User  owned 

System ownedSystem owned

FilesFiles

Regular Files: Regular Files: 

 ± ± DataData

 ± ± Executables <Executables <---- usually start a processusually start a process

Director y FilesDirector y Files

 ± ± Contain other  files and directoriesContain other  files and directories

Special FilesSpecial Files

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 15/48

UNIX Kernel

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 16/48

Modern UNIX Kernel

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 17/48

Unix Help

There is online help available on any Unix system.

The help system is call the "Unix man pages"set of  help files and a command to view them.

the book has some of  the same information, but you might need to check the man pages for your  specific system for  details.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 18/48

RTFM

The acronym RTFM (commonly found innewgroups and other  sources of  information for  Unix users and System Administrators) stands for:

Read The « Man page (or Read The « Manual).

It's common for  beginners to str uggle instead of  reading the man pages « it takes a while to get the hang of  how to decipher  the man pages.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 19/48

Learning Unix

In class we will have:

lectures

demonstrations

thought exercises

You need to spend time playing on a Unix system to lear n!

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 20/48

Operating Systems

 An Operating System controls (manages) hardware and software.

provides support for peripherals such as keyboard, mouse, screen, disk drives, «

software applications use the OS to communicate with peripherals.

The OS typically manages (starts, stops, pauses, etc) applications.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 21/48

Single vs. Multitasking

Some old operating systems could only do one thing at a time (DOS).

Most moder n systems can support multiple applications (tasks) and some can support multiple users (at the same time).

Supporting multiple tasks/users means the OSmust manage memor y, CPU time, network interfaces, ...

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 22/48

User Interfaces

The User Interface is the software that supports interactions with a human.

Some operating systems directly provide a user  interface and some don't.

Windows is an example of  an Operating System that includes a user  interface.

Unix (the OS) does not directly provide a user  interface.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 23/48

Unix and Users

Most flavors of Unix (there are many) provide the same set of  applications to support humans 

(commands and shells).  Although these user  interface programs are not 

part of  the OS directly, they are standardized enough that lear ning your way around one flavor  

of Unix is enough.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 24/48

Flavors of Unix

There are many versions of Unix that are used by lots of people:

SysV (from AT&T)BSD (from Berkeley)

Solaris (Sun)

IRIX (SGI)

 AIX (IBM)

LINUX (free software)

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 25/48

POSIX

POSIX is a standard that describes a single interface to a Unix like operating system.

POSIX is not an implementation - it is a description!

Most vendors are supporting POSIX (by making sure their  version of Unix adheres to the standard).

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 26/48

Unix History and Motivation

The first version of Unix came from AT&T in the early 1970s (Unix is old!).

Unix was developed by programmers and f or  programmers.

Unix is designed so that users can extend the f unctionality - to build new tools easily and efficiently (this is important for programmers).

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 27/48

Some Basic Concepts

Unix provides a simple interface to peripherals (it's pretty easy to add support for  a new

peripheral). Unix includes a basic set of  commands that 

allow the user  to view/change the system resources (filesystem, processes, peripherals, 

etc.).

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 28/48

What we will look at

In this course we will lear n about:

Unix user  accounts

the core set of Unix commands

the Unix filesystem

 A couple of  special programs called "shells".

 A number  of  commonly used applications:

Window system, text editors, programming tools.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 29/48

The power of Unix is that you can

extend the basic commands We will also look at how to extend the basic 

f unctionality of Unix:

customize the shell and user  interface. string together  a series of Unix commands to create 

new f unctionality.

create custom commands that do exactly what we 

want.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 30/48

Our View of the World as Users

Unix Shell

Your ShellYour Shell

 A shell is a process  A shell is a process that acts as anthat acts as aninterface to the OS. It interface to the OS. It allows the user  to r unallows the user  to r un

programs individuallyprograms individuallyand together  to and together  to 

accomplish a task.accomplish a task.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 31/48

While graphical user  interfaces are available and often used on Unix systems you must have a working knowledge of  the standard command line utilities, pipes, and I/O redirection to benefit from the considerable strengths of Unix.

Use th

e command line

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 32/48

Simple Unix

Directory Structure/

usr  etc home bin var ...

local bin ... class home ugrad ...

u1 u2 ...

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 33/48

 Your First Command

Syntax: man topic 

man provides online documentation on nearly ever ystandard command and configuration file.

Optional Syntax:  man -k k eyword 

man man for  more details

Man(manual) -- Documentation is your friend

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 34/48

Special DirectoriesHome Director y /home/u1

~u1

~

 A user  generally has permission to freely manipulate files within this director y and its children.

Users start with their  home director y as their pwd when they login.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 35/48

Changing Directories The cd(Change Director y) command is used to change 

directories

cd  path

Paths can be relative or  absolute

pwd reports present working director y

cd when entered by itself  sets the pwd to the user¶s home director y.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 36/48

 Your Prompt Helps you Navigate

The default prompt on your user  account tells you what director y is your pwd(where you are at the moment).

Some Examples:

csy12:~/bin>

csy12:/home

csy12:/usr /man

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 37/48

Other File System Utilities

ls Lists all files in a director y

cp Copies files

mv Moves files

rm Deletes files

mkdir Makes directories

rmdir  Removes directories 

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 38/48

Basic Syntax ls ls

cp cp source dest  ORcp source « dir 

mv mv source dest  OR

mv source « dir 

rm rm f ile

mkdir mkdir   new directory name

rmdir rmdir   directory to be removed 

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 39/48

Other Comands

Ever y Unix distribution comes with hundreds of  other  standard commands that can be used for  ever ything from viewing and 

searching files to developing software. 

Look through /bin, /usr /bin, and /usr /local/bin on most systems system and look at the man pages for  the programs in those directories for  more information.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 40/48

Using Other Commands

Syntax: command file

cat Echoes file contents to the screen

grep Searches a file for  a string

more Echos a file a line at a time

less Same as more but more features

wc Counts the words in a file and more

sort Sorts the contents of  a file

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 41/48

Pipes and RedirectionThe Unix ³philosophy´ involves a set of  generic tools which each do one thing well. Using these tools together  

allows you to appreciate the power  of  the Unix command.

In Unix ever ything (including hardware devices) is treated as a File that can be read from and written to.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 42/48

Pipes Pipes connect stdout of  one command to stdin of  

another  comand. 

i.e.

ls | less

cat student_list | grep senior  | sort 

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 43/48

I/O Redirection I/O redirection allows the user  to change where input to 

a command or  output from a command goes to/comes 

from.

cat student_list > outfile

program < infile 

program < infile > outfile

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 44/48

Standard File HandlesEver y Unix process automatically comes with three file handles or  descriptors. 

These are:

Standard Input (stdin) 

Keyboard

Standard Output (stdout) 

Display

Standard Error (stderr)

Display (unbuff)

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 45/48

Three Default Open Files

Program

stdinstderr 

stdout Buffer 

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 46/48

Standard File Handles All standard shells provide a facility to re-map

these three file handles to other  devices and files 

in addition to other  commands. 

This allows one to use several simple Unix 

commands to perform a complex task.

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 47/48

Pipes

Program 1

Program 2

Program 3

stdinPipe

stdout

Pipe

stdout

stdin

8/8/2019 01 Introduction Unix Os

http://slidepdf.com/reader/full/01-introduction-unix-os 48/48

Shell/Environment Variables

Parent Process

VAR=1

Child Process

VAR=????

Shell Variables

Parent Process

VAR=1

Child Process

VAR=1

Environment Variables