76
Review of: Chapters One - Four

Review of: Chapters One - Four

Embed Size (px)

DESCRIPTION

Review of: Chapters One - Four. History of Unix OS. The Unix OS was developed (based on Multics & CTSS operating systems) by Ken Thompson at the AT&T Bell Laboratories in 1969. He wanted to create an multi-user operating system to run “space wars” game. - PowerPoint PPT Presentation

Citation preview

Page 1: Review of: Chapters One - Four

Review of: Chapters One - Four

Page 2: Review of: Chapters One - Four

2

History of Unix OS

The Unix OS was developed (based on Multics & CTSS operating systems) by Ken Thompson at the AT&T Bell Laboratories in 1969. He wanted to create an multi-user operating system to run “space wars” game.Ken’s philosophy was to create an operating system with commands or “utilities” that would do one thing well very well (i.e. UNIX).

Page 3: Review of: Chapters One - Four

3

History of Unix OS

The first versions of UNIX were written in “machine-dependent” program (such as PDP-7).Ken Thompson approached Dennis Ritchie developer of C program), and in 1973 they compiled UNIX in C programming language to make operating system “portable” to other computers systems.

Page 4: Review of: Chapters One - Four

4

History of Unix OS

The Unix OS is a multi-user OS allowing more that more person to directly communicate with the computer.Although the OS can only work on one task at a time, a small piece of time (time slice) is dedicated to each task or user - this is referred to as “time-sharing”.Time sharing gives the illusion that the CPU is giving all the users its full attention

Page 5: Review of: Chapters One - Four

5

History of LinuxLinux operating system developed by Finnish programming student named Linus Torvalds

Linus wanted to develop Unix-like OS just to experiment with the new 386 MHz personal computer

Page 6: Review of: Chapters One - Four

6

Introducing the UNIXOperating System

UNIX can be used on systems functioning as: Dedicated servers or client workstations

in a server-based network Client/server workstations connected to

a peer-to-peer network Stand-alone workstations not connected

to a network

Page 7: Review of: Chapters One - Four

7

Introducing the UNIXOperating System

UNIX is a multi-user system Allows many users access and share the

resources of a server computer

UNIX is a multitasking system Allows user to execute more than one program

at a time

UNIX is a portable operating system Used in many computing environments

Page 8: Review of: Chapters One - Four

8

UNIX Concepts

Shell The interface between user and OS

Hierarchical Structure Directory and subdirectory organization

Layered components Layers of software surround the computer’s

inner core

Page 9: Review of: Chapters One - Four

9

Linux and UNIX

Linux is UNIX-like Not written from traditional UNIX code

Linux is original code Includes POSIX standards

Other Linux information Created by Linus Torvalds Offers all the complexity of UNIX Linux can coexist with other OSs

Page 10: Review of: Chapters One - Four

10

Connecting to a UNIX System

Remotely through Telnet/Secure Shell

Through network client software

As peer on peer-to-peer network

On a stand-alone PC

Through a dumb terminal

Page 11: Review of: Chapters One - Four

11

Connecting to UNIX

Telnet terminal emulation software Easy and unsecure

Secure Shell Terminal emulation software Session encrypted end-to-end Bundled with secure ftp and copy

X-Windows

Page 12: Review of: Chapters One - Four

12

Logging in to UNIX

Log in by entering username and password when UNIX system booted or connected toEnter at prompt (command-line mode) or into login box (GUI mode)You’re at the Shell prompt -- Now commands can be issued at the command prompt

Page 13: Review of: Chapters One - Four

13

Your ShellShells interpret commands and act as first-class programming languages

A default shell is associated with your account when created – Bash is the default shell in Linux (cat /etc/shells)

A short list of some UNIX shells: Bourne (original Unix shell) Cshell (similar to C programming language) Korn (backwards-compatible upgd to

bourne) Bash (combo of Bourne, C and Korn shells)

Page 14: Review of: Chapters One - Four

14

Entering CommandsTo interact with UNIX, a command is entered at the command prompt

UNIX is case-sensitive and most commands are typed in lower case

Two categories of commands User-level: perform tasks System administration: system

management

Page 15: Review of: Chapters One - Four

15

Entering Commands

The date command Displays the system date, which the

system administrator maintains

The cal command Shows the system calendar

The who command Shows who is using the system and their

current location

Page 16: Review of: Chapters One - Four

16

Entering CommandsCommand-line editing Certain keystrokes perform command-

line editing (shell dependent)

Multiple command entry More than one command on one line

by separating with a semicolon(;)

The clear command Clears the current screen

Page 17: Review of: Chapters One - Four

17

Entering CommandsCommand-line history Use up and down arrow keys to

scroll through command history

The whatis command Displays a brief description of a

command for help purposes Note the numbers in ()’s – that is the

man section

Page 18: Review of: Chapters One - Four

18

Logging Out of UNIX

Logging out ends your current process and indicates to UNIX that you are finished

Logging out is shell dependent Bourne, Korn, Bash – exit or Ctrl-D C shell – logout command

Page 19: Review of: Chapters One - Four

19

Understanding the Role of the UNIX System Administrator

System administrator manages the UNIX system Adds users and deletes old accounts Called root (also called the superuser) Unlimited permission to alter system (in other

words very dangerous) Prompt ends with # (pound) symbol Normal user prompt $ (dollar) % (percent)

symbol

Page 20: Review of: Chapters One - Four

20

Changing PasswordsFor security purposes, changing passwords is necessary Use the passwd command UNIX allows new password if:

The new password differs by at least three characters It has six or more characters, including at least two

letters and one number It is different from the user name

passwd To change current user’s password passwd <username> To change specified

user

Page 21: Review of: Chapters One - Four

21

Viewing Files with cat, more, less, head, and tail Commands

Use cat, more, less and tail to view file contents: cat displays a whole file at one time more displays a file one screen at a time,

allowing scroll down less displays a file one screen at a time,

allowing scroll down and up tail displays the end of a file head displays the beginning of a file

Page 22: Review of: Chapters One - Four

22

Viewing Files with cat, more, less, head, and tail Commands

Use head and tail to view the first few or last few lines of a file head displays the first few lines tail displays the last few lines

Page 23: Review of: Chapters One - Four

23

Redirecting Output

The greater than sign (>) is called a redirection symbol

Create a new file or overwrite an existing file by attaching (>) to a command that produces output

To append to an existing file, use two redirection symbols (>>)

Page 24: Review of: Chapters One - Four

24

Understanding the UNIX File System

A file is the basic component for data storage UNIX considers everything it interacts with a file

A file system is UNIX’s way of organizing files on mass storage (disk) devices A physical file system is a section of the hard disk

that has been formatted to hold files

The file system is organized in a hierarchical structure similar to an inverted tree

Page 25: Review of: Chapters One - Four

25

Page 26: Review of: Chapters One - Four

26

Understanding the Standard Tree Structure

The structure starts at the root level Root is the name of the file at this basic level

and it is denoted by the slash character (/)

A directory is a file that can contain other files and directories

A subdirectory is a directory within a directory The subdirectory is considered the child of the

parent directory

Page 27: Review of: Chapters One - Four

27

Using UNIX Partitions

The section of the disk that holds a file system is called a partition

When installing UNIX, one of the first tasks is deciding how to partition a storage device, or hard disk

Hard disks may have many partitions

UNIX partitions are given names

Windows Linux SolarisC: (1st Drive, 1st Part) hda1 c0d0s0C: (1st Drive, 2st Part) hda2 c0d0s1

C: (2nd Drive, 1st Part)

hdb1 c0d1s0

Page 28: Review of: Chapters One - Four

28

Using UNIX Partitions

Storage devices are called peripheral devices

Peripheral devices connect to the computer through electronic interfaces IDE - Integrated Drive Electronics SCSI - Small Computer System Interface (sda1)

Page 29: Review of: Chapters One - Four

29

Exploring the Root File System

UNIX must mount a file system before any programs can access files on it

To mount a file system is to connect it to the directory tree structure

The root file system is mounted by the kernel when the system starts

Page 30: Review of: Chapters One - Four

30

The root directory contains sub-directories that contain files: /bin contains binaries, or executables

needed to start the system and perform system tasks

/boot contains files needed by the bootstrap loader as well as kernel images

/dev contains system device reference files

(Next slide is wrong. Should /dev)

Exploring the Root File System

Page 31: Review of: Chapters One - Four

31

Page 32: Review of: Chapters One - Four

32

Exploring the Root File System

Root subdirectories continued: /etc contains configuration files that the

system uses when the computer starts /lib contains kernel modules, security

information, and the shared library images

/mnt contains mount points for temporary mounts by the system administrator

/proc is a virtual file system allocated in memory only

Page 33: Review of: Chapters One - Four

33

Exploring the Root File System

Root subdirectories continued: /root is the home directory of the root

user, or the system administrator /sbin contains essential network

programs used only by the system administrator

/tmp is a temporary place to store data during processing cycles

/var contains subdirectories which have sizes that often change, such as error logs

Page 34: Review of: Chapters One - Four

34

Using the Mount Command

Users can access mounted file systems which they have permission (covered later) to access

Additional file systems can be mounted at any time using the mount command

To ensure system security, only the root user uses the mount command

Page 35: Review of: Chapters One - Four

35

Paths and Pathnames

To specify a file or directory, use its pathname, which follows the branches of the file system to the desired file A forward slash ( / ) separates each

directory name The UNIX command prompt may indicate

your location within the file system Use the UNIX pwd command to display

the current path name

Page 36: Review of: Chapters One - Four

36

Bash Prompt Syntax

Command Displays

PS1=“\t” 02:16:15

PS1=“\t\\” 02:16:30\

PS1="\\s-\\v\\\ $" bash-2.05b $

PS1=“[\u@\h \W]\$” [userid@host dir]$

To see your PS1 variable type and enter: echo $PS1

To read more look at the man page for bash man bash

Page 37: Review of: Chapters One - Four

37

Navigating the File System

To navigate the UNIX directory structure, use the cd (change directory) command

UNIX refers to a path as either: Absolute - begins at the root level and

lists all subdirectories to the destination file

Relative - begins at your current working directory and proceeds from there

Page 38: Review of: Chapters One - Four

38

Managing Directories and Filesmkdir (make directory) command Create a new directory

rmdir (make directory) command Delete an empty directory

cp (copy) command Copy files from one director to another

rm (remove) command Delete files

Page 39: Review of: Chapters One - Four

39

Setting File Permissions

Page 40: Review of: Chapters One - Four

40

Setting File Permissions

File Permissionsr Owner has read

w Owner has write

x Owner has execute

r Group has read

- Group does not have write

x Group has execute

r Others have read

- Others do not have write

x Others have execute

Page 41: Review of: Chapters One - Four

41

Setting File Permissions

chmod command To set file permissions Settings are read (r), write (w), execute

(x) The three types of users are owners,

groups, and others

Setting permissions to directories Use execute (x) to grant access

Page 42: Review of: Chapters One - Four

vi editor

Pronounced: `vee eye‘’

Page 43: Review of: Chapters One - Four

Guide to UNIX Using Linux, 2E

What is vi ?

The visual editor on the Unix.Before this the primary editor used on Unix was line editor User was able to see/edit only one line of the

text at a time

The vi editor is not a text formater you cannot set margins center headings Etc…

Page 44: Review of: Chapters One - Four

Guide to UNIX Using Linux, 2E

Characteristics of vi

The vi editor is a very powerful but at the same time it is crypticIt is hard to learn, specially for windows usersThe best way to learn vi commands is to use them

Page 45: Review of: Chapters One - Four

45

Vim equals Vi

The current iteration of vi for Linux is called vim Vi Improved http://www.vim.org

Page 46: Review of: Chapters One - Four

Guide to UNIX Using Linux, 2E

Starting vi

Type vi filename at the shell promptAfter pressing enter the command prompt disappears and you see tilde(~) characters on all the linesThese tilde characters indicate that the line is blank

Page 47: Review of: Chapters One - Four

Guide to UNIX Using Linux, 2E

Vi modesThere are two modes in vi Command mode Input mode

When you start vi by default it is in command modeHow can you go to command mode from input mode?By pressing the Esc key

Page 48: Review of: Chapters One - Four

Guide to UNIX Using Linux, 2E

How to exit from vi

First go to command mode press Esc There is no harm in

pressing Esc even if you are in command mode. Your terminal may just beep or flash if you press Esc in command mode

There are different ways to exit when you are in the command mode

Page 49: Review of: Chapters One - Four

Guide to UNIX Using Linux, 2E

How to exit from vi

:q <enter> is to exit, if you have not made any changes to the file:q! <enter> is the forced quit, it will discard the changes and quit:wq <enter> is for save and Exit:x <enter> is same as above commandZZ is for save and Exit (Note this command is uppercase)

Page 50: Review of: Chapters One - Four

50

You can move around only when you are in the command modeArrow keys usually works(but may not)The standard keys for moving cursor are: h - for left l - for right j - for down k - for up

Moving Around

Page 51: Review of: Chapters One - Four

51

w - to move one word forwardb - to move one word backward$ - takes you to the end of line<enter> takes the cursor the the beginning of next line

Moving Around

Page 52: Review of: Chapters One - Four

52

- - (minus) moves the cursor to the first character in the current lineH - takes the cursor to the beginning of the current screen(Home position)L - moves to the Lower last lineM - moves to the middle line on the current screen

Moving Around

Page 53: Review of: Chapters One - Four

53

f - (find) is used to move cursor to a particular character For example, fa moves the cursor from

the current position to next occurrence of ‘a’

F - finds in the reverse direction

Moving Around

Page 54: Review of: Chapters One - Four

54

) - moves cursor to the next sentence } - move the cursor to the beginning of next paragraph( - moves the cursor backward to the beginning of the current sentence { - moves the cursor backward to the beginning of the current paragraph% - moves the cursor to the matching parentheses

Moving Around

Page 55: Review of: Chapters One - Four

55

Control-d scrolls the screen down (half screen) Control-u scrolls the screen up (half screen)Control-f scrolls the screen forward (full screen)Contol-b scrolls the screen backward (full screen).

Moving Around

Page 56: Review of: Chapters One - Four

56

To enter the text in vi you should first switch to input mode To switch to input mode there are

several different commands a - Append mode places the insertion

point after the current character i - Insert mode places the insertion

point before the current character

Entering text

Page 57: Review of: Chapters One - Four

57

I - places the insertion point at the beginning of current line

o - is for open mode and places the insertion point after the current line

O - places the insertion point before the current line

R - starts the replace(overwrite) mode

Entering text

Page 58: Review of: Chapters One - Four

58

Editing text

x - deletes the current characterd - is the delete command but pressing only d will not delete nothing you need to press additional keysdw - deletes to end of worddd - deletes the current lined0 - deletes to beginning of lineThere are many more keys to be used with delete command

Page 59: Review of: Chapters One - Four

59

The change command

c - this command deletes the text specified and changes the vi to input mode. Once finished typing you should press <Esc> to go back to command modecw - Change to end of wordcc - Change the current lineThere are many more options

Page 60: Review of: Chapters One - Four

60

Structure of vi command

The vi commands can be used followed by a number such as n<command key(s)> For example dd deletes a line 5dd will

delete five lines.

This applies to almost all vi commands

Page 61: Review of: Chapters One - Four

61

Undo and repeat command

u - undo the changes made by editing commands. (dot or period) repeats the last edit command

Page 62: Review of: Chapters One - Four

62

Copy, cut and paste in vi

yy - (yank) copy current line to buffer nyy - Where n is number of linesp - Paste the yanked lines from buffer to the line belowP - Paste the yanked lines from buffer to the line above

(the paste commands will also work after the dd or ndd command)

Page 63: Review of: Chapters One - Four

63

UNIX Approach toFile Processing

Based on the approach that files should be treated as nothing more than character sequences

Because you can directly access each character, you can perform a range of editing tasks – this offers flexibility in terms of file manipulation

Page 64: Review of: Chapters One - Four

64

Understanding UNIX File Types

Regular files, also known as ordinary files Create information that you maintain and

manipulate, and include ASCII and binary files

Directories System files for maintaining file system structure

Special files Character special files relate to serial I/O devices

Communicates one character at a time Block special files relate to devices such as disks

Communicates using blocks of data

Page 65: Review of: Chapters One - Four

65

Using Input and Error RedirectionYou can use redirection operators to retrieve input from something other than the standard input device and send output to something other than the standard output device

Examples of redirection: Redirect the ls command output to a file, instead

of to the monitor (or screen) Redirect a program that receives input from the

keyboard to receive input from a file instead Redirect error messages to files, instead of to

the screen by default

Page 66: Review of: Chapters One - Four

66

Manipulating Files

When you manipulate files, you work with the files themselves, as well as their contentsCreate files using output redirection cat command - concatenate text via

output redirection touch command - used to create

empty files

Page 67: Review of: Chapters One - Four

67

Manipulating Files

Delete files when you no longer needed rm command - permanently removes a file or

an empty directory The -r option of the rm command will remove

a directory and everything it contains

Copy files as a means of back-up or as a means to assist with new file creation cp command - copies the file(s) specified by

the source path to the location specified by the destination path

Page 68: Review of: Chapters One - Four

68

Manipulating Files

Moving a file in order to change the directory that contains it mv command - removes file from one

directory and places it in another

Finding a file helps you locate it in the directory structure find command - searches for the file

that has the name you specify

Page 69: Review of: Chapters One - Four

69

Manipulating Files

Combining files using output redirection cat command - concatenate text of two

different files via output redirection paste command - joins text of different files

in side by side fashion

Extracting fields of a file using output redirection cut command - removes specific columns or

fields from a file

Page 70: Review of: Chapters One - Four

70

Manipulating Files

Re-arranging the contents of a file sort command - sorts a file’s contents

alphabetically or numerically The sort command offers many options:

You can sort the contents of a file and redirect the output to another file

Utilizing a sort key which provides the option of sorting on a field position within each line

Page 71: Review of: Chapters One - Four

71

Using Script Files

UNIX users create shell script files to contain commands that can be run sequentially as a set – this helps with the issues of command automation and re-use of command actions

UNIX users use the vi editor to create script files, then make the script executable using the chmod command with the x argument

Page 72: Review of: Chapters One - Four

72

Using the Join Command

The join command is used in relational database processingRelational databases consider files as tables and records as rowsRelational databases also consider fields as columns that can be joined to create new recordsThe UNIX join command lets you extract information from files sharing a common field

Page 73: Review of: Chapters One - Four

73

Chapter Summary

UNIX supports regular files, directories, and character and block special filesFile’s structures depend on data being stored and three kinds of regular files are unstructured ASCII characters, records and treesWhen running, UNIX receives input from the standard input device (keyboard) also known as stdin, and sends output to the standard output device (monitor) also known as stdout. Another standard device, stderr, refers to the error file that defaults to the monitor

Page 74: Review of: Chapters One - Four

74

Chapter Summary

The touch command updates a file’s time and date stamps and creates empty filesThe rmdir command removes empty directoriesThe cut command extracts specific columns or fields from a fileTo combine two or more files, use the paste commandUse the sort command to sort a file’s contents alphabetically or numerically

Page 75: Review of: Chapters One - Four

75

Chapter Summary

To automate command processing, include commands in a script file that you can later execute as a programUse the join command to extract data from two files sharing a common field and use this field to join the two filesAwk is a pattern-scanning and processing language useful for creating a formatted report with a professional look

Page 76: Review of: Chapters One - Four

76

Chapter Summary

Most shells provide basic command-line editing capabilities and keep a history of your most recently used commands

You can view the contents of files with view commands such as cat, less, more, head, and tails