Introduction to UNIX Operating System - PowerPoint PPT Presentation

1 / 69
About This Presentation
Title:

Introduction to UNIX Operating System

Description:

E-mail: wongyos_at_gmail.com, MSN: bankberrer_at_hotmail.com. Tutor Session II: 2 ... df report the summary of disk blocks and inodes free and in use ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 70
Provided by: soni143
Category:

less

Transcript and Presenter's Notes

Title: Introduction to UNIX Operating System


1
Introduction to UNIX Operating System
Tutor Session II
  • Wongyos Keardsri (PBank)Department of Computer
    EngineeringFaculty of Engineering, Chulalongkorn
    UniversityBangkok, ThailandMobile Phone
    089-5993490E-mail wongyos_at_gmail.com, MSN
    bankberrer_at_hotmail.com

2
Tutor Outline
  • History of UNIX
  • Unix Structure
  • UNIX Shell
  • UNIX File System
  • Getting Started
  • Logging in / Exiting
  • Environment Variables
  • Unix Command Line Structure
  • System Resource Commands
  • Directory Navigation and Control
  • File Maintenance Commands
  • Display Commands
  • Special Unix Features
  • Text Processing
  • Other Useful Commands
  • vi Editor

3
Tutor Outline
  • History of UNIX
  • Unix Structure
  • UNIX Shell
  • UNIX File System
  • Getting Started
  • Logging in / Exiting
  • Environment Variables
  • Unix Command Line Structure
  • System Resource Commands
  • Directory Navigation and Control
  • File Maintenance Commands
  • Display Commands
  • Special Unix Features
  • Text Processing
  • Other Useful Commands
  • vi Editor

4
History of UNIX
  • Unix (officially trademarked as UNIX) is a
    computer operating system
  • In 1965, Bell Laboratories joins with MIT and
    General Electric developed the new operating
    system named Multics
  • In 1969, Some of the Bell Labs programmersdesigne
    d and implemented the first version of the Unix
    File System on a PDP-7
  • Given the name UNIX by Brian Kernighan

5
History of UNIX
(Cont)
  • UNIX developer team (Bell Labs programmers)
  • Ken Thompson
  • Dennis Ritchie
  • Rudd Canaday
  • Doug McIlroy
  • Languages written in UNIX
  • BCPL (Multics)
  • B (Unix)
  • C (Unix) ? After Unix version 2.0

6
Tutor Outline
  • History of UNIX
  • Unix Structure
  • UNIX Shell
  • UNIX File System
  • Getting Started
  • Logging in / Exiting
  • Environment Variables
  • Unix Command Line Structure
  • System Resource Commands
  • Directory Navigation and Control
  • File Maintenance Commands
  • Display Commands
  • Special Unix Features
  • Text Processing
  • Other Useful Commands
  • vi Editor

7
Unix Structure
  • Unix features
  • Multi-user and time-sharing
  • Multi-tasking
  • Multi-level (Hierarchical file system)
  • Multi-processor
  • Simple user interface
  • Simple utilities
  • Free Unix-like operating systems
  • Linux
  • BSD

8
Unix Structure
(Cont)
  • Several hundred utility programs
  • User commands
  • The Unix system kernel and The shells
  • System calls
  • C library functions
  • Device network interface
  • File format
  • Games and demos
  • System maintenance

9
Unix Structure
(Cont)
  • Unix System Structure

Kernel - controls hardware - handles
input/output - manages file system -
manages memory - schedules processes
Hardware
System Calls
Shell - accepts and executes user commands
command interpreter
ProgramsCommands
10
Unix Structure
(Cont)
  • UNIX shell
  • Bourne shell (sh) -- Written by Steve Bourne,
    while at Bell Labs. First distributed with
    Version 7 Unix.
  • Bourne-Again shell (bash) -- Written as part of
    the GNU project to provide a superset of Bourne
    Shell functionality.
  • Korn shell (ksh) -- Written by David Korn, while
    at Bell Labs.
  • Z shell (zsh) -- considered as the most complete
    shell
  • C shell (csh) -- Written by Bill Joy, while at
    the University of California, Berkeley. First
    distributed with BSD, circa 1979.

11
Unix Structure
(Cont)
  • Unix File System

/
Root
bin
etc
lib
usr
home
dev
tmp
sh
date
ls
passwd
group
libc.so
tty
null
bank
u48unn
hello.c
cpcu
bin
Hierarchical file system
12
Unix Structure
(Cont)
  • Directory etc, usr, home, bank, cpcu
  • File libc.so, hello.c
  • Path /home/bank/cpcu
  • Two special directory entries
  • . the current directory
  • .. the parent of the current directory

13
Tutor Outline
  • History of UNIX
  • Unix Structure
  • UNIX Shell
  • UNIX File System
  • Getting Started
  • Logging in / Exiting
  • Environment Variables
  • Unix Command Line Structure
  • System Resource Commands
  • Directory Navigation and Control
  • File Maintenance Commands
  • Display Commands
  • Special Unix Features
  • Text Processing
  • Other Useful Commands
  • vi Editor

14
Getting Started
  • Logging in
  • After connecting with a Unix system, a user is
    prompted for a login username, then a password.
  • Unix is case sensitive should be typed exactly as
    issued
  • Example

login rootpassword
Show an example
15
Getting Started
(Cont)
  • Exiting
  • D indicates end of data stream can log a
    user off.
  • C interrupt
  • logout leave the system
  • exit leave the shell
  • Terminal Type
  • vt100 Most computers
  • sun Sun workstation
  • xterms or xterm X-Terminal

Show an example
16
Getting Started
(Cont)
  • Environment Variables
  • DISPLAY The graphical display to use,
    e.g.nyssa0.0
  • EDITOR The path to your default editor, e.g.
    /usr/bin/vi
  • GROUP Your login group, e.g. staff
  • HOME Path to your home directory, e.g.
    /home/frank
  • HOST The hostname of your system, e.g. nyssa
  • LOGNAME The name you login with, e.g. frank
  • PATH Paths to be searched for commands, e.g.
    /usr/bin/usr/ucb/usr/local/bin

17
Getting Started
(Cont)
  • Environment Variables (Cont)
  • PS1 The primary prompt string, Bourne shell
    only (defaults to )
  • PS2 The secondary prompt string, Bourne
    shell only (defaults to gt)
  • SHELL The login shell youre using, e.g.
    /usr/bin/csh
  • TERM Your terminal type, e.g. xterm
  • USER Your username, e.g. frank

18
Getting Started
(Cont)
  • Set a global environment variable
  • C shell
  • setenv NAME value
  • Bourne shell
  • NAMEvalue export NAME
  • List global environmental variables with the env
    or printenv commands.
  • Unset with the unsetenv (C shell) or unset
    (Bourne shell) commands.

19
Getting Started
(Cont)
  • Set a local shell variable
  • C shell
  • set namevalue
  • Bourne shell
  • namevalue
  • Display environment variables
  • echo NAME
  • Change the shell
  • /bin/sh /bin/csh /bin/ksh
    /usr/pkg/bin/bash

Show an example
20
Getting Started
(Cont)
  • C Shell History Substitution
  • history recall previous commands
  • !! repeat last command
  • !n repeat command number n
  • !-n repeat command n from last
  • !str repeat command that started with
    string str
  • !?str? repeat command with str anywhere on
    the line
  • !?str? select the first argument that had str
    in it

Show an example
21
Getting Started
(Cont)
  • Control Key
  • S pause display
  • Q restart display
  • C cancel operation
  • U cancel line
  • D signal end of file
  • V treat following control character as
    normal character

22
Tutor Outline
  • History of UNIX
  • Unix Structure
  • UNIX Shell
  • UNIX File System
  • Getting Started
  • Logging in / Exiting
  • Environment Variables
  • Unix Command Line Structure
  • System Resource Commands
  • Directory Navigation and Control
  • File Maintenance Commands
  • Display Commands
  • Special Unix Features
  • Text Processing
  • Other Useful Commands
  • vi Editor

23
Unix Command Line Structure
  • Unix Command Line Structure
  • Unix manual / Help
  • man command_name
  • man -k keyword
  • man -k key words

command options arguments
Show an example
24
Unix Command Line Structure
(Cont)
  • System Resource Commands
  • date report the current date and time
  • cal report the calendar
  • df report the summary of disk blocks and inodes
    free and in use
  • du report amount of disk space in use
  • hostname/uname display or set (super-user only)
    the name of the current machine
  • kill send a signal to the process with the
    process id number (pid) or job control number
    (n). The default signal is to kill the process.

Show an example
25
Unix Command Line Structure
(Cont)
  • System Resource Commands (Cont)
  • passwd set or change your password
  • ps show status of active processes
  • script saves everything that appears on the
    screen to file until exit is executed
  • stty set or display terminal control options
  • whereis report the binary, source, and man
    page locations for the command named
  • which reports the path to the command or the
    shell alias in use

Show an example
26
Unix Command Line Structure
(Cont)
  • System Resource Commands (Cont)
  • who or w report who is logged in and what
    processes are running
  • whoami report current user name
  • finger report who is logged in
  • ifconfig report network interfaces
  • su switch user
  • write send a message to another user

Show an example
27
Unix Command Line Structure
(Cont)
  • Directory Navigation and Control
  • cd directorychange directory
  • ls options directory or filelist directory
    contents or file permissions
  • mkdir options directorymake a directory
  • pwdprint working (current) directory
  • rmdir options directoryremove a directory

Show an example
28
Unix Command Line Structure
(Cont)
  • List file and directory contents
  • drwxr-xr-x 3 root wheel 512 Jul 4 2348
    2110313
  • drwxr-xr-x 4 root wheel 512 Aug 28 2005
    344-441
  • drwxr-xr-x 3 root wheel 512 Aug 28 2005
    344-482
  • -rw-r--r-- 1 root wheel 905 Jul 9 0209 file
  • -rw-r--r-- 1 root wheel 105 Jul 9 0005
    hello.java

Permission mode
Owner
Filename
Size
Modified/Createddate
Group
Number of link
Type field
29
Unix Command Line Structure
(Cont)
  • Permission
  • Type field (first character)
  • Access permissions (characters 2-10)
  • First 3 user/owner
  • Second 3 group
  • Last 3 others
  • Permission mode
  • r read permission
  • w write permission
  • x execute permission
  • - no permission

drwxr-xr-x
30
Unix Command Line Structure
(Cont)
  • Permission number
  • 7 111 rwx
  • 6 110 rw-
  • 5 101 r-x
  • 4 100 r--
  • 3 011 -wx
  • 2 010 -w-
  • 1 001 --x
  • 0 000 ---

31
Unix Command Line Structure
(Cont)
  • File Maintenance Commands
  • chgrp options group filechange the group of
    the file
  • chmod options filechange file or directory
    access permissions
  • chown options owner filechange the ownership
    of a file can only be done by the superuser
  • cp options file1 file2copy file1 into file2
    file2 shouldn't already exist. This command
    creates or overwrites file2.

Show an example
32
Unix Command Line Structure
(Cont)
  • File Maintenance Commands (Cont)
  • mv options file1 file2move file1 into file2
  • rm options fileremove (delete) a file or
    directory (-r recursively deletes the directory
    and its contents) (-i prompts before removing
    files)

Show an example
33
Unix Command Line Structure
(Cont)
  • Display Commands
  • cat options fileconcatenate (list) a file
  • echo text stringecho the text string to stdout
  • head -number filedisplay the first 10 (or
    number of) lines of a file
  • more (or less or pg ) options filepage through
    a text file
  • tail options filedisplay the last few lines
    (or parts) of a file

Show an example
34
Tutor Outline
  • History of UNIX
  • Unix Structure
  • UNIX Shell
  • UNIX File System
  • Getting Started
  • Logging in / Exiting
  • Environment Variables
  • Unix Command Line Structure
  • System Resource Commands
  • Directory Navigation and Control
  • File Maintenance Commands
  • Display Commands
  • Special Unix Features
  • Text Processing
  • Other Useful Commands
  • vi Editor

35
Special Unix Features
  • I/O redirection and piping
  • Output redirection to a file
  • Input redirection from a file
  • Piping
  • Output of one command becomes the input of a
    subsequent command
  • There are 3 standard file descriptors
  • stdin 0 Standard input to the program
  • stdout 1 Standard output from the program
  • stderr 2 Standard error output from the
    program

36
Special Unix Features
(Cont)
  • File Redirection
  • gt redirect standard output to file
  • command gt outputfile
  • gtgt append standard output to file
  • command gtgt outputfile
  • lt input redirection from file
  • command lt inputfile
  • pipe output to another command
  • command1 command2

Show an example
37
Special Unix Features
(Cont)
  • File Redirection (csh)
  • gt file redirect stdout and stderr to file
  • gtgt file append stdout and stderr to file
  • command pipe stdout and stderr to command
  • To redirect stdout and stderr to separate files
  • (command gt outfile) gt errfile

Show an example
38
Special Unix Features
(Cont)
  • File Redirection (sh)
  • 2gt file redirect stderr to file
  • gt file 2gt1 direct both stdout and stderr to file
  • gtgt file 2gt1 append both stdout and stderr to
    file
  • 2gt1command pipe stdout and stderr to command
  • To redirect stdout and stderr to two separate
    files
  • command gt outfile 2gt errfile
  • To discard stderr
  • command 2gt /dev/null
  • (/dev/null is a black hole for bits)

Show an example
39
Special Unix Features
(Cont)
  • Wild Cards
  • ? match any single character
  • match any string of zero or more characters
  • abc match anyone of the enclosed characters
  • a-s match any character in the range a through
    s
  • !def (sh) match any characters not one of
    def (csh) the enclosed characters

Show an example
40
Special Unix Features
(Cont)
  • Control Over Command Execution
  • Background (non-interactive)
  • command
  • Sequential
  • command1 command2
  • Subprocess (run as an atomic unit)
  • (command)

Show an example
41
Special Unix Features
(Cont)
  • Control Over Command Execution (Cont)
  • Conditional (program exit status determines
    success or failure)
  • OR command1 command2
  • (run command2 if command1 fails)
  • AND command1 command2
  • (run command2 if command1 succeeds)

Show an example
42
Tutor Outline
  • History of UNIX
  • Unix Structure
  • UNIX Shell
  • UNIX File System
  • Getting Started
  • Logging in / Exiting
  • Environment Variables
  • Unix Command Line Structure
  • System Resource Commands
  • Directory Navigation and Control
  • File Maintenance Commands
  • Display Commands
  • Special Unix Features
  • Text Processing
  • Other Useful Commands
  • vi Editor

43
Text Processing
  • Filter
  • A filter (in Unix) is a program that reads some
    input, performs a simple translation on it, and
    writes some output
  • Examples of Unix filters
  • grep
  • sort
  • wc
  • awk
  • vi
  • sed

44
Text Processing
(Cont)
  • Text Processing Commands
  • awk options filescan for patterns in a file
    and process the results
  • grep options 'search string' filesearch the
    argument (in this case probably a file) for all
    occurrences of the search string, and list them.
  • sed options filestream editor for editing
    files from a script or from the command line

Show an example
45
Text Processing
(Cont)
  • Regular expressions
  • Regular expressions come in three different forms
  • Anchor tie the pattern to a location on the line
  • Character sets match a single character at a
    single position
  • Modifiers specify how many times to repeat the
    previous expression
  • Regular expressions can be combined to form
    longer regular expressions

46
Text Processing
(Cont)
  • Regular expressions (Cont)
  • . match any single character except newline
  • match zero or more instances of single
    expression preceding it
  • abc match any of the characters enclosed
  • a-d match any character in enclosed range
  • abcmatch any character NOT in the enclosed set
  • exp regular expression must start at the
    beginning of the line

47
Text Processing
(Cont)
  • Regular expressions (Cont)
  • exp regular expression must end at the beginning
    of the line
  • \ treat the next character literally

48
Tutor Outline
  • History of UNIX
  • Unix Structure
  • UNIX Shell
  • UNIX File System
  • Getting Started
  • Logging in / Exiting
  • Environment Variables
  • Unix Command Line Structure
  • System Resource Commands
  • Directory Navigation and Control
  • File Maintenance Commands
  • Display Commands
  • Special Unix Features
  • Text Processing
  • Other Useful Commands
  • vi Editor

49
Other Useful Commands
  • Working With Files
  • cmp options file1 file2compare two files and
    list where differences occur (text or binary
    files)
  • cut options file(s)cut specified
    field(s)/character(s) from lines in file(s)
  • diff options file1 file2compare the two files
    and display the differences (text files only)
  • file options fileclassify the file type

Show an example
50
Other Useful Commands
(Cont)
  • Working With Files (Cont)
  • find directory options actionsfind files
    matching a type or pattern
  • ln options source_filetarget link the
    source_file to the target
  • paste options filepaste field(s) onto the
    lines in file
  • sort options filesort the lines of the file
    according to the options chosen

Show an example
51
Other Useful Commands
(Cont)
  • Working With Files (Cont)
  • strings options filereport any sequence of 4
    or more printable characters ending in ltNLgt or
    ltNULLgt. Usually used to search binary files for
    ASCII strings.
  • tee options filecopy stdout to one or more
    files
  • touch options date filecreate an empty file,
    or update the access time of an existing file

Show an example
52
Other Useful Commands
(Cont)
  • Working With Files (Cont)
  • tr options string1 string2translate the
    characters in string1 from stdin into those in
    string2 in stdout
  • uniq options fileremove repeated lines in a
    file
  • wc options file(s)display word (or character
    or line) count for file(s)

Show an example
53
Other Useful Commands
(Cont)
  • File Archiving, Compression and Conversion
  • compress/uncompress/zcat options
    file.Zcompress or uncompress a file.
    Compressed files are stored with a .Z ending.
  • gzip/gunzip/zcat options file.gzcompress or
    uncompress a file. Compressed files are stored
    with a .gz ending

Show an example
54
Other Useful Commands
(Cont)
  • File Archiving, Compression and Conversion
  • tar keyoptions file(s)tape archiver--refer
    to man pages for details on creating, listing,
    and retrieving from archive files. Tar files can
    be stored on tape or disk.

Show an example
55
Other Useful Commands
(Cont)
  • Remote Connections
  • finger options user_at_hostnamereport
    information about users on local and remote
    machines
  • ftp options hosttransfer file(s) using file
    transfer protocol
  • rcp options hostnameremotely copy files from
    this machine to another machine

Show an example
56
Other Useful Commands
(Cont)
  • Remote Connections
  • rlogin options hostnamelogin remotely to
    another machine
  • rsh options hostnameremote shell to run on
    another machine
  • telnet host portcommunicate with another
    host using telnet protocol

Show an example
57
Tutor Outline
  • History of UNIX
  • Unix Structure
  • UNIX Shell
  • UNIX File System
  • Getting Started
  • Logging in / Exiting
  • Environment Variables
  • Unix Command Line Structure
  • System Resource Commands
  • Directory Navigation and Control
  • File Maintenance Commands
  • Display Commands
  • Special Unix Features
  • Text Processing
  • Other Useful Commands
  • vi Editor

58
Vi Editor
  • UNIX Editors
  • vi
  • emacs
  • pico
  • Vi is a modal editor (2 modes)
  • Insert mode ltigt key
  • Text insertion and deletion
  • Command mode ltescapegt key
  • All commands

59
Vi Editor
vi Quick Reference Guide
  • Cursor Movement Commands
  • (n) indicates a number, and is optional
  • (n)h left (n) space(s)
  • (n)j down (n) space(s)
  • (n)k up (n) space(s)
  • (n)l right (n) space(s)
  • F forward one screen
  • B back one screen
  • D down half screen
  • U up half screen

Show an example
60
Vi Editor
vi Quick Reference Guide (Cont)
  • Cursor Movement Commands (Cont)
  • H beginning of top line of screen
  • M beginning of middle line of screen
  • L beginning of last line of screen
  • G beginning of last line of file
  • (n)G move to beginning of line (n)
  • 0 (zero) beginning of line
  • end of line
  • (n)w forward (n) word(s)

Show an example
61
Vi Editor
vi Quick Reference Guide (Cont)
  • Cursor Movement Commands (Cont)
  • (n)b back (n) word(s)
  • e end of word
  • Inserting Text
  • i insert text before the cursor
  • a append text after the cursor (does not
    overwrite other text)
  • I insert text at the beginning of the line
  • A append text to the end of the line
  • r replace the character under the cursor with
    the next character typed

Show an example
62
Vi Editor
vi Quick Reference Guide (Cont)
  • Inserting Text (Cont)
  • R Overwrite characters until the end of the line
    (or until escape is pressed to change
    command)
  • o (alpha o) open new line after the current line
    to type text
  • O (alpha O) open new line before the current
    line to type text

Show an example
63
Vi Editor
vi Quick Reference Guide (Cont)
  • Deleting Text
  • dd deletes current line
  • (n)dd deletes (n) line(s)
  • (n)dw deletes (n) word(s)
  • D deletes from cursor to end of line
  • x deletes current character
  • (n)x deletes (n) character(s)
  • X deletes previous character

Show an example
64
Vi Editor
vi Quick Reference Guide (Cont)
  • Change Commands
  • (n)cc changes (n) characters on line(s) until
    end of the line (or until escape is pressed)
  • cw changes characters of word until end of the
    word (or until escape is pressed)
  • (n)cw changes characters of the next (n) words
  • c changes text to the end of the line
  • ct(x) changes text to the letter (x)

Show an example
65
Vi Editor
vi Quick Reference Guide (Cont)
  • Change Commands (Cont)
  • C changes remaining text on the current line
    (until stopped by escape key)
  • changes the case of the current character
  • J joins the current line and the next line
  • u undo the last command just done on this line
  • . repeats last change
  • s substitutes text for current character
  • S substitutes text for current line

Show an example
66
Vi Editor
vi Quick Reference Guide (Cont)
  • Change Commands (Cont)
  • s substitutes new word(s) for old
  • lt line nos effectedgt s/old/new/g
  • repeats last substitution (s) command.
  • (n)yy yanks (n) lines to buffer
  • y(n)w yanks (n) words to buffer
  • p puts yanked or deleted text after cursor
  • P puts yanked or deleted text before cursor

Show an example
67
Vi Editor
vi Quick Reference Guide (Cont)
  • File Manipulation
  • w(file) writes changes to file (default is
    current file)
  • wq writes changes to current file and quits
    edit session
  • w!(file) overwrites file (default is current
    file)
  • q quits edit session w/no changes made
  • q! quits edit session and discards changes
  • n edits next file in argument list

Show an example
68
Vi Editor
vi Quick Reference Guide (Cont)
  • File Manipulation (Cont)
  • f(name) changes name of current file to (name)
  • r(file) reads contents of file into current
    edit at the current cursor position (insert a
    file)
  • !(command) shell escape
  • r!(command) inserts result of shell command at
    cursor position
  • ZZ write changes to current file and exit

Show an example
69
End
Question ?
Answer
Write a Comment
User Comments (0)
About PowerShow.com