introduction to unix

27
Introduction to Unix CS240 Computer Science II

Upload: eldora

Post on 06-Jan-2016

24 views

Category:

Documents


1 download

DESCRIPTION

Introduction to Unix. CS240 Computer Science II. The UNIX Environment. Typical UNIX File System. Important Directories and Files. / (root): the top of the file hierarchy /export/home: usually contains all users’ subdirectories. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Introduction to Unix

Introduction to Unix

CS240 Computer Science II

Page 2: Introduction to Unix

The UNIX Environment

Hardware

UnixKernel

Shell

Page 3: Introduction to Unix

Typical UNIX File System

Page 4: Introduction to Unix
Page 5: Introduction to Unix

Important Directories and Files

• / (root): the top of the file hierarchy• /export/home: usually contains all users’ subdirectories.• /usr: traditionally contains subdirectories that keep

system information.• /usr/bin: usually contains the standard Unix utilities.• /usr/sbin: contains utilities for system administration.• /etc: keeps configuration and other administration files,

e.g., /etc/passwd contains a list of all users.• /var: contains files that vary as the system runs, e.g.,

users’ mailbox files, system log files, etc.• /dev: contains information about peripheral devices.• /tmp: used by programs to hold temporary files.

Page 6: Introduction to Unix
Page 7: Introduction to Unix
Page 8: Introduction to Unix
Page 9: Introduction to Unix

Unix Standards

• Two groups– System V: led by AT&T and Sun Microsystems;

newest version is System V Release 4.– BSD (Berkeley Standard Distribution): the Open

Software Foundation (OSF) led by IBM and HP; newest version is OSF/1.

• Both standards conform to standards set by Portable Operating System Interface (POSIX).– Solaris from Sun Microsystems– AIX from IBM– HP-UX from Hewlett Packard– IRIX from Silicon Graphics

Page 10: Introduction to Unix

Commercial Unix Systems

UNIX

System V BSD

V.2

V.3

V.4

V.4.1

4.2

4.3Apollo

HP/UXSun OS

IBMAIX

OSF/1

Page 11: Introduction to Unix

Utilities or Utility Programs

• More than 200 application programs such as editors, graphic user interface, search and sort routines, and some shell programs are integrated into the standard Unix operating system. Many other commercial and free programs such as compilers, spreadsheets, and desktop publishing tools are available and can be easily added to the system.

Page 12: Introduction to Unix

The Shell

• A shell is a command interpreter; it interprets the command enter by a user and calls the program the user wants.

• A shell can be used as a high-level programming language in that shell commands can be arranged and stored in a file for later execution.

• There are three popular shells in use today: the Bourne, the C Shell, and the Korn Shell. Korn shell is a superset of Bourne shell. A user may specify the shell he or she wants to use.

Page 13: Introduction to Unix

Run a Utility Program in a Shell

• Each utility program is uniquely identified by its name such as passwd, date, or ls, etc. To run a utility, just type in the name of the utility and press the enter key.

Page 14: Introduction to Unix

Frequently Used “Directory” Related Utilities

• pwd: displays current directory.• mkdir: creates a new subdirectory.• cd: changes to another directory.• rm: removes a file.• rmdir: removes a directory.• ls: lists contents of the current directory.• which: displays the full path name of a utility.• whereis: displays the pathname of a utility.

Page 15: Introduction to Unix

Frequently Used “File” Related Utilities

• pico: starts the “pico” text editor• vi: starts the “visual” text editor.• cat: displays the content of a file.• wc: counts the words in a file.• cp: copies a file.• more, page, head, tail: displays the content of a file.• file: displays information about the contents of a file.• diff: displays the difference between two files.• grep: searches for a particular strings in a file.• sort: orders a file by lines.• mv: renames a file.• lp: prints a file.• lpstat: displays the status of all print jobs.• cancel: removes specified jobs from the printer queue.• chmod: specifies the accessibility of a file.• ln: makes a link to an existing file.

Page 16: Introduction to Unix

Other frequently used utilities• passwd: changes password.• date: displays today’s date.• clear: clears the screen.• man: displays information about a particular utility.• groups: displays list of all the groups to which the user belongs.• mail, mailx: sends and reads emails.• who: • finger: displays information about users.• write: sends a message to another user who is logged in.• talk: initiates a online conversation with another user who is logged

in.• compress: compresses a file.• uncompress: restores a compressed file.

Page 17: Introduction to Unix

List of commands with more detailed discussions

• man• ls• vi• pwd• mkdir• rmdir• more• mailx• chmod

Page 18: Introduction to Unix

The man command

• lklm,

Page 19: Introduction to Unix

The ls command

Page 20: Introduction to Unix

The three modes of vi Editor

C o m m a n dM o d e

InputM ode

Last-lineM ode

Escape

Insert,Append,

Open,replace,Change

Return

:

Page 21: Introduction to Unix

Fucntions of the three mode in vi

• Input mode: allows text such as source code to be entered.

• Command mode: allows various commands to be entered for text editing and other purposes. Several commands such as insert, append, open, replace, and change that are issued in the command mode will take you to the input mode.

• Last-line mode: all commands that start with a colon : puts vi in the last-line mode.

Note: all text entered is temporarily kept in a buffer until permanently saved to disk.

Page 22: Introduction to Unix

Starting vi

Command Function

vi filename Create/edit filename starting a line 1.

vi +n filename Edit filename starting a line n.

vi + filename Edit filename starting last line.

vi -r filename Recover filename after a system crash.

Page 23: Introduction to Unix

Adding text filename: from command to input mode; must press Escape key to return to

command mode

Command Insert text

i Before the cursor.

I Before first non-blank character on line.

a After the cursor.

A At the end of the line.

o Open a line below the current line.

O Open a line above the current line.

Page 24: Introduction to Unix

Some moving cursors in the command mode

Command Cursor movement

Space, I, or Space to the right

H or Space to the left

w or W Word to the right or blank-delimited word to the right.

b or B Word to the left or blank-delimited word to the left.

$ End of the line.

0 Beginning of the line.

Page 25: Introduction to Unix

Miscellaneous Commands

Command Effect

:w filename Store contents of buffer to filename.

:q Quite vi.

:q! Quite vi with saving contents of buffer.

~ Change upper case to lower case and vice versa.

ZZ Store content of buffer and quit vi.

:f or Ctrl+G Displays the filename, the status,the current line number, the number of lines in the buffer, etc.

Page 26: Introduction to Unix

viewing different parts of the buffer in the command mode

Command Cursor movementCtrl + D Down (forward) one-half screen.

Ctrl + U Up (backward) one-half screen.

Ctrl + F Down (forward) one full screen.

Ctrl + B Up (backward) one-full screen.

nG To line n or to the last line if without n.

H To the top of the screen.

M To the middle of the screen.

L To the bottom of the scren.

Page 27: Introduction to Unix

Customizing the vi environment: the set command

• In the command mode type :set followed by a parameter listed below and press enter key.– all: lists a complete list of parameters and their current status.– atuoindent (or ai) creates tab stops; Ctrl+T tabs right and

Ctrl_D tabs left. noautoindent or noai turns off autoindent feature.

– shiftwidth=nn sets the spacing (#characters) between tab stops – number to display line numbers; nonumber remove line

numbers.– wrapmargin=nn, where nn is arbitray positive integer

representing # characters after which wrap-around takes place.– showmode displays the mode type; noshowmode removes the

display.• Note that the parameters can be permanently set in a

user’s startup file .profile With Bourne or Korn shell, or .login with C shell. The parameters may also be set in a .exrc file.