Top Banner
CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE
150

CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Dec 26, 2015

Download

Documents

Esther Briggs
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

CIS 14A - Operating Systems(UNIX)

Markus Geissler, MBA

Nghiep Nguyen, MSEE

Page 2: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

About the Instructor...

Nghiep Nguyen, MSEE-Sacramento High School, 1983- AA in Math and Science

Sacramento City College, 1985-BS in Electrical Electronics Engineering

UC Davis, 1987

-MS in Electrical Electronics Engineering

CSUS, 1993

Page 3: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Experience

- Electronic Engineer, 87 - 90

Sacramento Army Depot

Write Test Program Sets for Unit Under Test for Tomahawk Computer.

- Software Engineer, 90 - 95

McClellan Air Force Base

Operational Flight Program for A-10

Page 4: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Experience

- Electronic Engineer, 95 -96

Tinker Air Force Base

B-2 Stealth Bomber

- Software Engineer, 96 - 98

McClellan Air Force Base

A-10 aircraft

Page 5: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Experience

- Associate Programmer 1/98 - 10/98

P.O.S.T: Work with PowerBuilder, SQL

- Associate Systems Software: 10 - 11/98

F.T.B: Sybase DBA

- Systems Software Specialist, 11/98 to Present

Legislative Data Center

Unix (Sun Solaris) System Administrator

Page 6: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Experience

Adjunct Faculty: 8/97 to Present

Cosumnes River College

Unix, Internet, HTML

Java, Visual Basic Visitor Lecturer: 8/02 – 6/03

California State University, Sacramento

Visual Basic, Java

Page 7: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Office Hours

None E-mail: [email protected] Work: [email protected] Web site: http://

www.geocities.com/nghiep_nguyen

Page 8: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Textbook(s)

Required– UNIX System V - A Practical Guide (Third

Edition)• by Mark G. Sobell• Addison-Wesley Publishing Company

Strongly recommended– CIS 14A Lecture Slides

• By Markus Geissler• Download from website

Page 9: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Reverse Flows of Knowledge

Examinations– Hands-on in Classroom – One make-up exam per person at the

instructor’s convenience • No more than 90% possible on makeup exams

Homework projects

Page 10: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Other Resources

UNIX Utility Program Reference– Back of textbook (starting on p. 521)

Page 11: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Things You Should Know Before Starting This Course A basic understanding of the

components of a computer system– CIS 1

Page 12: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

UNIX

What exactly is UNIX?– Computer Operating System– large set of utility programs

• general user• programmer• communication• administrative commands

Page 13: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Operating System

Definition:An operating system (OS) is a set of instructions that manages all computer operations and provides an interface between user(s) and system resources.

Page 14: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

UNIX

Computer operating system (OS)– Large set of utility programs– Based on C programming language– Used in enterprise networks

OperatingSystem

OperatingSystem

Disk DriveDisk Drive

MonitorMonitor

KeyboardKeyboard

MouseMouse

PrinterPrinter

ApplicationApplication

Page 15: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

What Can UNIX Do For You?

General user applications Programming environment Typesetting tasks Communication applications Administration commands

Page 16: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The Inner Workings of a Computer - Summary Central Processing Unit Memory Storage I/O

Page 17: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Central Processing Unit (CPU)

“Brain” of the computer– Executes instructions from programs and

processes– Manufacturers include

• Intel• Advanced Micro Devices (AMD)• Cyrix• Motorola• Sun Microsystems

Page 18: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Memory

RAM (Random Access Memory)– Volatile

• Information disappears when electrical power to RAM is interrupted

• Capacity measured in Megabytes (MB)• Access speed measured in Nanoseconds (ns)

– Holds data before and after CPU processes them

• Program instructions• Application data

Page 19: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Storage

Hard disk– Installed inside computer’s case

Floppy/ZIP®/JAZ®/SyQuest® disks– Portable; require disk drive

Disks are typically non-volatile– Data called into memory when needed

• Capacity measured in Gigabytes (GB)

Magnetic Tape– Largely used for data backup

Page 20: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Input/Output (I/O)

Reads input from a device into memory– Keyboard– Mouse

Writes output from memory to devices– Monitor– Printer

Disk drives are input and output devices– long term storage devices

Page 21: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

UNIX Facts

Created in 1969– by Kent Thompson

Based on C language AT&T (Bell Labs) shared UNIX with colleges

and universities– Colleges made enhancements– Berkeley Software Distribution (BSD)

See Introduction to UNIX– by Fiamingo, DeBula and Condron

Page 22: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Linux

Compact version of UNIX for PC– Created by Linus Thorvald

Not yet standardized– Supported by a large, active user

community Free versions available on the Internet

– approx. $50 for RedHat Linux

Page 23: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Major UNIX Components

Kernel Shell File System

KernelKernel

Shell & UtilitiesShell & Utilities

HardwareHardware

Page 24: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Kernel

Core of UNIX OS– Manages hardware, memory and file

system resources– Controls transmission of information

between user application and CPU– Stores information about the arrangement

of the computer system and the network

Page 25: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Shell

Interface between user and OS Korn shell

– Most robust features Bourne shell

– Subset of Korn shell C shell

– Not related to other two shells– Most widely used in SunOS

Page 26: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

UNIX OS Components

Shell– Shell program are interpreted, not compiled

• commands are read and executed one by one• compiled program is read and converted to a

machine language then execute all at once• slower than compiled language such as C

Three types of Shells: Korn, Bourne, and C

Page 27: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Shell History

Bourn -- Steve Bourne at AT&T Bell Labs– Original UNIX shell -- compactness & speed– lack features for interactive use

C -- Bill Joy (SUNW)– friendly features for users– larger and slower than Bourne

Korn -- David Korn of AT&T Bell Labs– faster than C shell, will run Bourne Script

Page 28: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File System

Organizes data on disk in a hierarchical structure of directories

File– Program or data

Directory/folder– Similar to file drawer

• Each disk has root directory

Subdirectory– Directory/folder within other directory

Page 29: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File System Structure

Root (/)– /etc : system administration files– /usr : executable commands, s.a. utilities– /opt : third-party software– /export/home or /home : user’s home

directory

Page 30: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Multitasking OS

Used to approach 100% of computer resource utilization while increase user productivity– Reduced cost per user

• Time slicing

– Users can run multiple processes• Increases user productivity

UNIX refers to task as “process”– Usually maximum of 25 concurrent processes per

user session

Page 31: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Multi-User OS

Supports 1 - 2000 users– Users share system resources

To approach 100 percent in computer resource utilization while reducing the cost per user

Share system resources

Page 32: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Interactive Mode

Immediate response to keyboard or mouse input

“No news is good news”– Display returns shell prompt after

commands are issued• Different shells have different prompts

– Detailed feedback only when errors made

Page 33: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Networking Terms

Host - a computer system Host Name - a unique name for a system IP address - a number used by networking Network

– connects machines to enable comm. between users on other systems.

Server provides resources to one or more clients on the network

Page 34: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

More Terms

Client is a machine that uses services from one or more servers on a network

NFS (Network File System) enables files to be shared across the network.

NIS (Network Information Services) enables system administration functions to be centralized on a server.

Client-Server

Page 35: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Network

Connects computers to enable communication between users on multiple systems

Page 36: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Clients vs. Servers

Server– Provides resources to one or more clients on

the network– Usually requires more powerful equipment than

clients Client

– Computer that uses services from one or more servers

Front end vs. back end

Page 37: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Set Up

User Account– must have it set up before a user can log in– contains essential user account info

• User name identifies a user to the system

– is created by System Administrator. Bring your class registration/schedule to

the computer lab. The lab assistant will set up the Unix account for you

Page 38: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Logging into CRC’s LAN

Login name– First four letters of your last name– Last four digits of student ID number

Initial password: new2lan– Change password right away

Page 39: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Password Security

Do not choose a password that can be related to you!

Use a password that does not resemble a word in the dictionary– Case sensitivity

Page 40: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Password Guidelines

No less than six characters Must contain at least two alphabetic

characters and at one numeric or special character– can have spaces, avoid special characters

Cannot be login name or reverse New password must differ from old

password by at least three characters

Page 41: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Accessing CRC’s UNIX Box

From Windows 95 or Windows NT– Connect to Internet via your ISP– Start, Run…– TELNET 165.196.137.125

orTELNET cosumn.crc.losrios.cc.ca.us

Page 42: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

User Account

Required for user login Identifies user to the system Contains essential user account info

– Special environment settings for user– Mail file

Page 43: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Logging into CRC’s UNIX Box

Log into system– Initial username is same as for CRC’s LAN– Initial password: new2mini– Password will not display when typed– Connection times out if you take too long

Use exit command at the $ prompt to log out– Also possible to disconnect within TELNET

application

Page 44: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Entering UNIX Commands

Type commands with keyboard To correct a typing error, use Delete

key– NOT the Backspace key

Press Enter key to send command to kernel

Page 45: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Changing Your Password

Use passwd command at $ prompt to change your password– Type old password first– Type new password twice

• Password will not be displayed when typed• Password has to have at least one number in it• Suggestion: Use same password as LAN

account and add a number, if necessary

Page 46: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Getting Help in UNIX

Use man command Include command about which you want

help– man ls– Use man ls | more to display one page at a

time• “Pipe” character

– Use Ctrl-C to interrupt file display• If file is too long for one screen

Page 47: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Logging a TELNET Session

Record all activity within a session In TELNET utility

– Choose Terminal, Start Logging…• Specify filename to which to log

– Local drive– Network drive (U: drive in CRC lab)

» Up to 5 MB of space

– Choose Terminal, Stop Logging to stop writing to log file

Page 48: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The script Command

Logs commands entered and results displayed– If no filename specified, script logs to file

typescript Type exit to stop logging and close the

log file

Page 49: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Printing Log Files

Type lp filename to print to CRC lab FTP file to home computer and print to

local printer– Printing from DOS Editor may be easier

than from Notepad• Potential problems with line breaks• Turn off Word Wrap

Page 50: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

UNIX Commands

Command line format– command [ - option(s) argument(s)]

Options modify the command Arguments tell the computer to what to

apply the command Example

– cd [directory_name]– ls [aFIR] [pathname]

Page 51: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Command Syntax

Command Line Format– command [option(s)] [argument(s)]– case sensitive– blank space does matter since it is the

delimiter for the shell– do not necessary require all three parts– 256 characters can be entered on a single

command line

Page 52: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Commands

passwd ls cd pwd cp rm mv

Page 53: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Commands

cat more man mkdir rmdir date echo

Page 54: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Commands

cal head tail wc grep find

Page 55: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Commands

cd [ directory_name] pwd ls [ -aFlRt] [pathname] man command

Page 56: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Commands

pwd -- present working directory cd -- change directory mkdir -- create a new directory ls -- diplays contents of your directory

– l -- stands for long information– F -- File type option– a -- display all files (including customization files)– R -- display recursively all directories/sub-

directories and their corresponding files

Page 57: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Commands

ls -F will display the following symbols next the listing of files:

/ for directory

* executable file, shell script

@ symbolic link

nonetext file (ASCII)

Page 58: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Commands

rmdir - remove directory head -n --- displays the first n lines tail -n -- displays the last n lines wc -- word count command to display

numbers of lines, words, characters diff -- to display the differences between

two files.

Page 59: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Commands

grep -- search for a pattern in a file or files

Page 60: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The cal Command

Displays a calendar on the screen Syntax: cal [ [month] year]

– Month from 1-12

– Year from 1 to 9999 (!) Example: cal 1999

– Displays the calendar for 1999

– Eastern and Western calendars were combined in 1752

• Check out September 1752!

Page 61: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The who Command

Lists current system users– Syntax: who– Example: who | sort -r

• Sorts users in reverse order

– Example: who | grep geisslm• Allows you to check whether or not user

geisslm is logged-in

– More details on examples later

Page 62: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Directory Structure

/

/dev /usr /bin/home

/cis14a

/user A /user B/home

Page 63: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Path

Absolute path– Type pwd at $ prompt

• Present working directory• /usr/cis14a/user B/home

– To change to directory, typecd /usr/cis14a/user B/home

Relative path– From /usr/cis14a/user B directory, type

cd home

Page 64: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Path

absolute path -- Starts with / (stands for root directory) and go to where you want to go

relative path -- start from where you are and move to sub-directory or parent directory

Page 65: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The cd Command

Navigate directory structure Type cd .. at $ prompt to change to

parent directory– Directory above current directory

Type cd without attributes to change to home directory

Page 66: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Special Directory Names

. represents current directory .. represents parent directory

– “Above” current directory in directory tree Combine .. and “sibling” subdirectory

name to move to “sibling” subdirectory– To change from /usr/cis14a/user B

directory to /usr/cis14a/user A, typecd ../user A

Page 67: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The ls Command

List the contents of current directory Type ls at $ prompt Directory entry types

– - (hyphen) for file– d for directory

Page 68: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

ls Command Options

Directory entry type User/group/other (world) permissions Number of links Owner name Owner group File size in bytes/blocks Date of file creation/last access Filename/directory name

Page 69: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

ls Command Options

ls -l lists details about contents– Long version

ls -F shows slash (/) after directory name listing

ls -R lists contents of entire tree (including subdirectories)– Recursive

Page 70: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

More ls Command Options

ls -r lists contents in reverse order ls -l (filenames) to list specific files ls -a displays all contents, including

hidden ls -s lists size of file/directory in blocks

– 1 block = 512 bytes ls -i displays system’s item number for

each directory entry

Page 71: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

More ls Command Options

ls [directory name] lists contents of other directory

Page 72: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Combining ls Command Options

Possible to combine ls command options– ls -a -F is the same as– ls -aF

| more option– Say “pipe more”– Lists one screen at a time

• Example: ls -R |more

• More on “piping” later

Page 73: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

UNIX Filenames

At least one character long– Maximum length: 255 characters

Case-sensitive!– Uppercase and lowercase characters are

distinct• Unlike DOS or Windows 9x

Page 74: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Special Characters in UNIX

Filenames cannot contain certain “special characters”– Special meaning to the shell

Examples– & ; | * ? ‘ “ ` [ ] ( ) $ < > { } ^ # / \– see p. 38 in Sobell textbook for list

Page 75: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

UNIX Wildcards

Wildcards replace characters– * replaces zero, one or more characters– ? replaces one character– [ ] match one of the choices inside brackets– { } match each of the choices inside braces

Example: ls ?h*e– Returns ah123e, bhe, 1h23e, etc.

Example: ls t[aeiou1-3]p– Returns tap, tep, tip, top, tup, t1p, t2p, t3p

Page 76: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Creating a Directory

Type mkdir command at $ prompt– Example: mkdir reports

Possible to create multiple directories with one command– Use space as delimiter– Example: mkdir memos letters

Page 77: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Clearing the Screen

Use clear or cls command to clear screen– Clears screen buffer– $ prompt only will appear at top of screen

Page 78: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

More mkdir Command Options

mkdir -p cis14a/hw1– Creates cis14a directory as well as hw1

subdirectory below cis14a directory Use -p option to create multiple

subdirectories at multiple levels at the same time– Example: mkdir -p cis14a/hw2 cis14b

Page 79: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The rmdir and rm Commands

Use rmdir to remove a directory– Current directory must be parent of directory

to be deleted unless absolute or other relative path is specified

If directory is not empty, use rm command– rm -r hw1 for recursive remove– rm -ir hw1 for interactive recursive remove

• System will prompt for confirmation

Page 80: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The cat and more Commands

cat [filename]– Displays contents of file

more [filename]– Displays contents of file in segments– Press Enter key to display one line at a time– Press Spacebar to display one screen at a

time Similar to pg [filename]

Page 81: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Ctrl Commands

Ctrl-c interrupts current activity Ctrl-u erases current command line Ctrl-w erases word in current command

line Ctrl-s stops scrolling screen output Ctrl-q restarts scrolling screen output Other commands can be customized for

user by administrator

Page 82: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The head and tail Commands

head [-n] filename– Displays top portion of file– head -5 hw1 displays first 5 lines of file

hw1 tail [-n] filename

– Displays bottom portion of file– tail -10 mbox displays last 10 lines of file

mbox

Page 83: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

UNIX Editors

Use editor to create and edit files Several editors available

– vi - most commonly used– pico - not included in SVR4

• Not available at CRC

– emacs - not included in SVR4• Not available at CRC

Page 84: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Visual Editor (vi)

Type vi at $ prompt to start editor– vi [filename] to edit existing file (p. 212)

Three modes (p. 183)– Command mode

• Hit Esc key to access command mode

– Input (Text) mode– Last-line mode ([shift]&[colon] keys)

Page 85: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Accessing vi’s Insert Mode

From command prompt, press– i to insert text before cursor– I to insert text at beginning of line– a to append text after cursor– A to append text at end of line– o to open new line below cursor– O to open new line above cursor

• Page 214

Page 86: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Accessing vi’s Last-Line Mode

From command mode, press : (colon)– Necessary to save file and exit vi

Page 87: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

vi Cursor Movements

Command mode– j or moves cursor down one line– k or moves cursor up one line– l or moves cursor to the right– h or moves cursor to the left– Ctrl-D moves down one half screen– Ctrl-U moves up one half screen– Ctrl-F moves forward one screen– Ctrl-B moves backward one screen

Page 88: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

More vi Cursor Movements

Command mode– w moves to next word– $ moves to end of line– G moves to last line– Many more...

Page 89: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

vi Commands

dd - delete one line to buffer ndd - delete n lines x - delete one character dw - delete one word to buffer d$ - delete to end of line to buffer d0 - delete to beginning of line to buffer

Page 90: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Command Mode

u -- undo a last command/change . -- do last change again Copy Text yy - yank a copy of a line to buffer nyy - yank a copy of n line to buffer yw - yank a copy of a word to buffer Past Text p -- put buffer after a cursor P -- put buffer before a cursor

Page 91: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Command Mode

cw -- change a word ncw -- change n words c$ -- change to end of a line r -- replace one character R -- replace the text (type over)

Page 92: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Last-Line Mode Commands

set showmode indicates Insert Mode or Command Mode– At bottom right of screen

set nu displays line numbers set nonu turns off line number display set list displays invisible characters set ic specifies that pattern search

should ignore case

Page 93: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Searching File Contents

Access vi’s command mode /[string] finds next occurrence of string

– /^[string] searches for string at the beginning of a line

– /\>[string] searches for string at end of word

• More examples on p. 197 of textbook

Page 94: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Last - line Mode

To turn off an option, put a “no” infront of the variable, i.e.,

set nu set nonu -- to turn it off Search for text /text -- go forward to the first occurence of text ?text -- go backward to previous occurence of

test

Page 95: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Moving and Deleting Lines

:3,8d deletes lines 3 to 8 :4,9m 12 moves lines 4-9 to line 12 :2,5t 13 copies lines 2-5 to line 13 :5,9w filename writes lines 5-9 to

filename

Page 96: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Management Summary

Copying Renaming Moving

Page 97: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The cp Command

Create an exact copy of another file– With the same name in a different directory

• Possible to specify target directory only

– With a different name in the same directory Syntax: cp [source] … [target]

– Example: cp misc ./w1/misc• Copies file misc to subfolder w1 with the same

name

Page 98: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

More About the cp Command

Example: cp w2/* w4– Copies all files from w2 directory to w4

directory– Does NOT copy subdirectories under w2

cp -r w2/* w4 also copies subdirectories– Recursive– Lowercase “R”!

Page 99: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Copying Multiple Files

Example: cp test test.out w3– Copies files test and test.out to w3

directory• w3 directory must exist

Page 100: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The mv Command

Moves and/or renames a file– Original file will disappear

• Different from cp command

Example: mv test exam– Renames file test to file exam

Example: mv exam w4– Moves file exam to directory w4

• w4 directory must exist

• mv command will not create it

Page 101: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Commands For Analyzing And Manipulating Files sort - sort file contents grep - search file for a pattern diff - point out differences between files comm - details file differences wc - counts words, lines and letters in file compress - reduce file size to conserve

disk space

Page 102: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The sort Command

Sort information within files and/or merge different files

Example: sort [filename]– Sorts [filename] alphabetically by first word

Example: sort -f +2 [filename]– Sorts [filename] alphabetically by third

word while ignoring case-sensitivity

Page 103: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The grep Command

Global regular expression pattern Find text patterns in files Syntax: grep [options] pattern [filelist] Example: grep echo test1

– Finds pattern echo in file test1 and displays lines matching pattern

Page 104: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

More grep Command Examples

Example: grep -c echo test1– Displays line count of lines matching

pattern Example: grep -l echo

– Displays name of file that contains one or more matches

Page 105: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The diff Command

Shows lines that are different between two files

Syntax: diff [filename1] [filename2] Example: diff t1 t2

– Lists line and column number– Lists different text patterns

Page 106: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The comm Command

Displays line-by-line comparison of sorted files– Files must be sorted!

Syntax: comm [filename] [filename] … Example: comm file1 file2

– Results displayed in three columns• file1 unique text patterns

• file2 unique text patterns

• common text patterns

Page 107: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The wc Command

“Word Count” Display number of

– Lines– Words– Characters

Syntax: wc [options] [file-list] Example: wc -lw memo

– Displays the number of lines and words contained in the file memo

Page 108: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The compress Command

Compresses files to reduce amount of space required on disk– Similar to ZIP utility in DOS/Windows– Compressed file cannot be viewed/executed until

decompressed Syntax: compress [filename]

– Results in file filename.Z Example: compress -v text

– -v option displays compression ratio

Page 109: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Limiting Access to Resources

Use permissions– Not available in DOS

• Usually available only on network operating systems (NOS)

Who can change permissions?– Owner of file or directory– Administrator

Page 110: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Cis-14A: Misc

Printing – lp (after using script command)– File Transfer Protocol (FTP)

• Open Dos Command window• ftp 165.196.137.125 to log in

– Telnet Preference menu• Name your file, and location• start logging, do work, and stop logging• Use word processor to print your file

Page 111: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Cis-14A: Misc

Turn in assignments 1 and 2 File Structure

– Tree structure– Directory, and Files– File names

• Extension

– Absolute and Relative Path– cd, mkdir, rmdir, rm, cp, mv

Midterm 1

Page 112: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Structure

Pyramid structure, inverted tree Each directory -- a subject

– a folder– can be divided into smaller directories for

more clarity or easy to use– sub-directory(ies) and/or file(s)– the end of a path

Page 113: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Structure

File Name– 14 chars, some has up to 255 chars– A-Z, a-z– 0 - 9– underscore (_)– period (.)– comma(,)

Page 114: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Structure

Filename Extension– usually after period (filename.ext)– can use more than one period– meaningful

• .ext, .c, .txt, .990206

– Invisible Filename• start with a period (.filename)• ls -a

Page 115: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Structure

Absolute and Relative Paths Commands that work with directory

– Change or go– create, delete– rename– copy– empty, or non-empty

Page 116: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Structure

Standard Unix Directories : / -- root– /home, /export/home– /usr -- system information

• /usr/bin• /usr/sbin

– /etc– /var -- files that vary as system runs– /tmp– /dev

Page 117: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Structure

File or Directory Permission– r read from the file– w write to the file– x execute the file

ls -l

Page 118: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Structure

chmod mode filename– mode

• who• op• permission

File owner or root can change permission of a file

Page 119: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Structure

Symbolic– chmod u+x,g+w,o+r

Numberic– r = 4– w = 2– x = 1

• rwx=7• rw-=6

Page 120: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Structure

Links– ln -- link command – ln associate_file destination– hard link– soft link– ls -i

Page 121: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Structure

Question

????

BREAK

Page 122: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Redirection

Standard Input Standard Output Redirect Output

– cat > test– cntl-d to end

Redirect Input– command [arg] < filename

Page 123: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Redirection

Appending– Use command >>

Examples

Page 124: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Pipes

command_a [arg] | command_b [arg] command_a > temp command_b < temp rm temp Examples

Page 125: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Filter

Processes an input stream of data to produce an output stream of data– who | sort | lp– who | tee test | grep user

Page 126: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Metacharacters

* ? [,,,] {...}

Page 127: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

UNIX/NFS Permissions

NFS file permissions– Read (r)– Write (w)– Execute (x)

Permissions listed in sequence of– User– Group– World (all other users on system)

Page 128: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

File Permissions vs. Directory Permissions

Permission File Directory

Read r display/ list contentcopy

Write w modify files add/delete

Execute x execute control directory

access

Page 129: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Default Permissions

Default permissions after creation

rw-r--r--rw-r--r--File:

rwxr-xr-xrwxr-xr-xDirectory:

Page 130: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The chmod Command

Change permissions– Syntax: chmod opcode filename

Example: chmod u+w test– Gives you permission to write to file test– Does not influence existing permissions

Example: chmod g+r test– Gives your group permission to read file test– Does not influence existing permissions

Page 131: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

chmod Permission Categories

u - user g - group o - others (world) a - all

Page 132: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Taking Permissions Away

chmod g-x– Takes execute permission away from

group– Does not change r and w permissions

Page 133: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Absolute Permissions

chmod o=x– Assigns execute permission to others

Example: chmod a=x test– Sets permissions to execute ONLY– r and w permissions are eliminated

Page 134: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Setting Permissions Using Symbolic vs. Numeric Mode Symbolic mode

– rwx rwx rwx– Example: chmod u+r test

Numeric mode– 421 421 421– Example: chmod 700 text

• Possible to set absolute permissions only

Page 135: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Redirecting Screen Output

Prevent output from echoing to screen– Is sent to file/printer instead– Example: ls > test.out

• Sends ls listing to file test.out

Caution: Existing file will be overwritten without warning!– Use >> option to append existing file– Example: ls >> test.out

Page 136: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Capturing Keystrokes

Record keystrokes– Use cat command– Syntax: cat > filename

• Type text to capture to file• Press Ctrl-D to stop capturing and write to

specified file

– Example: cat > test.out

Page 137: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Piping

Use the | (pipe) character– Modifies or redirects previous command in line– Example: man ls | more

• Displays help for the ls command one screenful at a time

– Example: who | sort | lp• Sends a sorted list of currently logged-in users to the

printer• Note: lp command must be last command

Page 138: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Communicating in UNIX

Real-time communication– write– talk

E-mail communication– mailx

Page 139: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The write Command

Send instant message to other user on UNIX system– Similar to “chatting”– Recipient must permit messaging

• Type mesg y at $ prompt

– Example: write geisslm• Opens write session with user geisslm

• End conversation with “oo” (over and out)

• Press Ctrl-C to end transmission

Page 140: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The talk Command

Similar to write command– Divides user screen into two windows– Statements displayed in opposite window

on other end of communication

My “talking” appears here

Your “talking” appears here

Page 141: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

The mailx Command

Send electronic mail from UNIX system– Syntax: mailx [username]

• Type subject line• Type message• Press Ctrl-D to send message

– Example: mailx geisslm• Type subject line and message

– Example: mailx geisslm < message.fil• Sends file message.fil to user geisslm

Page 142: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Using mailx Interactively

Many options available– Type ? at ? prompt to view list of available

options– Example: t 2

• Types second message on screen

– Example: delete 3 (or d 3)• Deletes message number 3 from message list

– Example: h• Displays list of message headers

Page 143: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Mail Message Listing

Message type– N - new message– R - read message– O - old message

Sender Date and time Size Subject

Page 144: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Changing Message Options

Possible to change options while typing message text– Use ~ (tilde) character options

• Be sure to specify option after issuing command• Otherwise information may be missing

Specify in mailx command line– mailx -s “E-mail test” geisslm < test.doc

• Sends file test.doc to user geisslm with subject “E-mail test”

Page 145: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

More About mailx

Replying– r replies to all recipients of original

message– R replies to sender of message ONLY

Page 146: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Exiting mailx Input Mode

quit command processes messages exit command leaves mailbox

“untouched”

Page 147: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Aliasing

Alias– For one username– For multiple usernames

• Distribution list

– Example: alias entry in .mailrc file• .mailrc is UNIX customization file• Entry: alias users user1 user2

– Mail sent to alias users is forwarded to user1 and user2

– Create current-session alias at $ prompt

Page 148: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Alias Advantages

Issue multiple commands through one alias– Example: alias home=‘clear;cd;pwd;ls’

• Clears the screen, changes to home directory, displays current directory and its contents

“Rename” UNIX commands to DOS commands– Example: alias dir=‘ls -l’

• Possible to issue DOS-like dir command to view contents of current directory

Page 149: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

Removing Aliases

Use unalias command to remove alias(es)– Example: unalias test

• Removes test alias in current session

Page 150: CIS 14A - Operating Systems (UNIX) Markus Geissler, MBA Nghiep Nguyen, MSEE.

That’s All, Folks!

Course Review Final Exam