Introduction to UNIX - PowerPoint PPT Presentation

1 / 68
About This Presentation
Title:

Introduction to UNIX

Description:

UNIX is a multi-user, multitasking operating system with built-in ... Linux uses the freeware Bash shell as its default ... tcsh (a freeware shell derived ... – PowerPoint PPT presentation

Number of Views:257
Avg rating:3.0/5.0
Slides: 69
Provided by: nath108
Category:

less

Transcript and Presenter's Notes

Title: Introduction to UNIX


1
Introduction to UNIX
  • Thara Angskun

2
Introducing the UNIX Operating System
  • UNIX is a multi-user, multitasking operating
    system with built-in networking functions
  • It can be used on systems functioning as
  • Dedicated serves in a server-based network
  • Client workstations connected to a server-based
    network
  • Client/server workstations connected to a
    peer-to-peer network
  • Standalone workstations not connected to a network

3
Introducing the UNIX Operating System Continued
  • UNIX is a multi-user system, which lets many
    people simultaneously access and share the
    resources of a server computer
  • A multitasking system lets one user execute more
    than one program at a time
  • UNIX is also a portable operating system

4
Introducing the UNIX Operating System Continued
  • Its portability means it can be used in a variety
    of computing environments
  • UNIX runs on a wider variety of computers than
    any other operating system
  • It also runs on the Internet, regulating popular
    programs such as File Transfer Protocol (FTP), an
    Internet protocol used for sending files and
    Telnet, an Internet terminal emulation program

5
A Brief History of UNIX
  • A group of programmers at Bell Labs originally
    developed UNIX in the early 1970s
  • Bell Labs distributed UNIX in its source code
    form, so anyone who used UNIX could customize it
    as needed
  • Eventually, two standard version of UNIX
    evolved
  • ATT produced System V
  • University of California at Berkeley developed BSD

6
UNIX Concepts
  • Microsoft DOS and Microsoft Windows adopted
    original UNIX design concepts, such as the idea
    of a shell--an interface between the user and the
    operating system--and the hierarchical structure
    of directories and subdirectories
  • The kernel is the base operating system, which
    interacts directly with the hardware and services
    the user programs

7
Layers of a UNIX System
8
UNIX Concepts Continued
  • The kernel is only accessible through kernel
    mode, which is reserved for the system
    administrator
  • This prevents unauthorized commands from invading
    the foundation layer or the hardware that
    supports the entire UNIX structure
  • User mode provides access to higher layers where
    all application software resides

9
Linux and UNIX
  • Linux is a UNIX-like operating system
  • Linus Torvalds, who released it to the public,
    free of charge, in 1991, originally created
    Linux
  • Linux offers all the complexity of UNIX at no
    cost
  • You can install Linux on your PC where it can
    coexist with other operating systems, and test
    your UNIX skills

10
Introducing UNIX Shells
  • The shell is a UNIX program that interprets the
    commands you enter from the keyboard
  • UNIX provides several shells, including the
    Bourne shell, the Korn shell, and the C shell
  • Steve Bourne at ATT Bell Laboratories developed
    the Bourne shell as the first UNIX command
    processor

11
Introducing UNIX Shells Continued
  • The Korn shell includes many extensions, such as
    a history feature that lets you use a keyboard
    shortcut to retrieve commands you previously
    entered
  • The C shell is designed for C programmers use
  • Linux uses the freeware Bash shell as its default
    command interpreter

12
Shells Relationship to the User and the Hardware
13
Choosing Your Shell
  • You choose a shell when the system administrator
    sets up your user account
  • Most users choose the Bash shell, although you
    can choose any of these
  • Bourne
  • Korn
  • C shell
  • Bash
  • tcsh (a freeware shell derived from the C shell)
  • zsh (a freeware shell derived from the Korn shell)

14
Switching from Shell to Shell
  • After you choose your shell, the system
    administrator stores your choice in your account
    record, and it becomes your assigned shell
  • UNIX uses this shell any time you log on
  • However, you can switch from one shell to another
    by typing the shells name (such as tcsch, bash,
    or zsh) on your command line

15
Entering Commands
  • UNIX is case-sensitive, that is, it distinguishes
    between uppercase and lowercase letters, so that
    John differs from john
  • You type most UNIX commands in lowercase
  • You must know a commands syntax to enter I
    properly
  • Syntax refers to a commands format and wording,
    as well as the options and arguments you can use
    to extend and modify its functions

16
Command-line Editing
  • Shells support certain keystrokes for performing
    command-line editing
  • For example, Bash (which is the default Linux
    shell) supports the left and right arrow keys,
    which move the cursor on the command line
  • Not all shells support command-line editing in
    the same manner

17
Multiple Command Entry
  • You may type more than one command on the command
    line by separating each command with a
    semicolon()
  • When you press Enter, UNIX executes the commands
    in the order you entered them

18
Command-line Editing Continued
  • The clear Command
  • You can use the clear command to clear your
    screen it has no options or arguments
  • The Command-line History
  • You can access the command history with the up
    and down arrow keys
  • Pressing the up arrow key once recalls the most
    recently used command
  • Each time you press the up arrow key, you recall
    an older command

19
Redirecting Output
  • In UNIX, the greater than sign () is called the
    redirection symbol
  • You can use the redirection symbol to create a
    new file or overwrite an existing file by
    attaching it to a command that produces output
  • You can also use the redirection symbol with the
    cal command to save a calendar in a text file
  • You can also use the cat command to create files
    from information you type at the keyboard

20
The man Program
  • For reference, UNIX includes an online manual
    that contains all commands, including their
    options and arguments
  • The man program in UNIX displays this online
    manual, called the man pages, for command-line
    assistance

21
Man Pages List the Following Items
  • Name the name of the command and a short
    statement describing its purpose
  • Synopsis a syntax diagram showing the usage of
    the command
  • Description a more detailed description of the
    command than the name item gives
  • Options a list of command options and their
    purposes
  • See Also other commands or man pages that
    provide related information
  • Bugs a list of the commands known bugs

22
Manual Page
23
Elementary Command
  • man, whatis , apropos
  • pwd, ls, cd, mkdir, rmdir, mv, rm, chattr
  • chmod, chown
  • time, date, cal, sleep
  • cat, more, less, head, tail
  • tr, look, grep, sed,
  • sort, cut,crypt, tar, find, locate
  • hostname, uname, who, w, finger,echo

24
Elementary Command
  • tee, script
  • ps,kill,killall,

25
User Interaction with the Shell
  • User logs in
  • shell shows the prompt
  • User types a command
  • shell executes the appropriate program
  • User interacts with the program
  • User logs off

26
Command Interpretation Cycle
  • 1. Display the prompt
  • 2. Receive and parse (analyze the syntax of) the
    next command
  • 3. Perform input processing, transforming the
    command
  • 4. Carry out or initiate the requested
    operations
  • 5. Wait for initiated operations to finish
  • 6. go to step 1

27
Metacharacters - Special Characters (1)
  • ? Matches any single character
  • Matches any string, including the empty
    string
  • list Matches any one of the characters
    specified in the list
  • !list Matches any one of the characters not
    specified in the list

28
Metacharacters - Special Characters (2)
  • Executing the commands
  • Sequencing the commands
  • Grouping the commands ( )
  • Background processing
  • Chaining the commands

29
Command Execution
  • Once a executable file has been found, the shell
    creates a separate process to run the program
    following three steps
  • 1. A new (child) process is created that is a
    copy of the shell.
  • 2. The child process is overlaid with the
    executable file, then the command name together
    with any arguments are passed to it.

30
Command Execution (cont)
  • 3. a. The interactive shell waits for the child
    process to terminate before returning to receive
    the next command, unless the command line
    includes a trailing ampersand ().
  • b. If the command line ends with , the shell
    returns without waiting, and the commands is run
    in the background.

31
Introduction of UNIX shell Programming Language
  • Shell Script (Shell Procedure)
  • A program written in shell programming language
    is known as a shell script or shell procedure.

32
Introduction of UNIX shell Programming Language
  • Shell Programming Language
  • The shell programming language is a command
    language with a lot of features common to many
    computer programming languages, including the
    structured language constructs sequence,
    selection, and iteration.
  • Command Languages
  • Command languages are interpreted language.

33
The First UNIX Shell Program - foo1
  • foo1 display of users currently logged in
  • A at the beginning of a line indicated that
    the line is a
  • remark line and is for documentation.
  • who wc -l

34
Executing a Script
  • Invoking Scripts with sh
  • To use the sh command.
  • sh won01
  • Making Files Executable
  • To make the script file an executable file.
  • chmod ux won01
  • won01

35
sh Command
  • sh Command
  • The sh command invokes a new copy of the shell.
    You can run your script files using sh command.

36
sh Command
  • Options of sh Command
  • -n Read commands, but does not execute them.
  • -v Prints the input to the shell as the shell
    reads it.
  • -x Prints command lines and their arguments as
    they are executed. This option is used mostly
    for debugging.

37
Scripts in shells
  • You can place any command or sequence of commands
    in a file, make the file executable, and then
    execute its contents simply typing its name at
    the shell prompt.
  • Most UNIX systems include more than one shell.
    Use the man command to see how a particular
    command is used in your version of the shell.

38
Scripts in shells
  • You can change your current shell by typing sh,
    ksh, or csh to invoke any of the three shells,
    Bourne shell, Korn shell, or C shell. This does
    not change your login shell. Typing exit
    terminates the current shell and you are back to
    your login shell.

39
Escape Characters
  • \b
  • \c
  • \n
  • \r
  • \t
  • \0n

40
echo and Escape Characters
  • echo and escape characters
  • The echo command recognizes escape characters.
    Escape characters all start with the backslash (
    \ ), and you can use them as part of the echo
    command argument string.
  • echo \07\07Warning
  • echo \nHello\n

41
The dot Command(.)
  • The dot command ( . ) is a build-in shell command
    that lets you execute a program in the current
    shell and prevents the shell from creating the
    child process.
  • Example
  • . bye

42
read Command (kb_read, read_test)
  • The read command can be used to read the user
    input and save it in a user-defined variable.
  • The features of read command
  • - When read is executed, the shell waits until
    the user enters a line of text.
  • - The variables are listed after the read on
    the command line.

43
read Command (kb_read, read_test)
  • The read command reads one line from the input
    device. The first input word is stored in the
    first variable, the second word in the second
    variable, and so on. If input string contains
    more words than the number of the variables, the
    left-over words are stored in the last variable.

44
Comments - shell Programming
  • symbol
  • The shell recognizes as the comment
    symbol therefore, characters after the are
    ignored.

45
Variables - shell Programming Basic (2)
  • variablevalue
  • Spaces are not permitted on either side of the
    equal sign.
  • unset variable
  • Embedded White Space
  • If you value string contains embedded white
    space, then you must place it between quotation
    marks.
  • variableThe Main Menu

46
shell Positional Variable
  • 0
  • 1,2,...9
  • _at_
  • ?

47
if-then and if-then-else
  • The if-then Construct
  • if condition
  • then
  • true-command(s)
  • fi

48
if-then and if-then-else
  • The if-then-else Construct
  • if condition
  • then
  • true-commands
  • else
  • false-command(s)
  • fi

49
if-then-elif
  • if condition1
  • then
  • commands_1
  • elif condition2
  • then
  • commands_2
  • else
  • commands_n
  • fi

50
test Command
  • The test Command
  • The test command is a built-in shell command
    that evaluates the expression given to it as an
    argument and return true if the expression is
    true, if otherwise, false.
  • Invoking test with Brackets
  • You can use square brackets ( ) instead of
    the word test.

51
test Command
  • Example
  • if test variable value
  • if variable value
  • Two statements have the same function.

52
Logical Operators
  • Logical Expression
  • test expression_1 logical operator
    expression_2

53
Logical Operators
  • Logical and Operator ( -a )
  • Logical or Operator ( -o )
  • Logical not operator ( ! )

54
Numeric Test Operators
  • test number1 numeric test operator number2
  • -eq Is number 1 equal to number2 ?
  • -ne Is number1 not equal to number2 ?
  • -gt Is number 1 great than number2 ?
  • -ge Is number1 great than or equal to number2 ?
  • -lt Is number 1 less than number2 ?
  • -le Is number1 less than or equal to number2 ?

55
String Test Operators
  • string1 string2 Does string1 match
    string2?
  • ! string1 ! string2 Does string1 not match
    string2?
  • -n -n string Does string
    contain characters (nonzero length)?
  • -z -z string Is string an empty
    string
  • (zero length?

56
File Test Operators
  • -r filename
  • -w filename
  • -s filename
  • -f filename
  • -d filename

57
shell Variable Evaluation Operators
  • variable
  • variable
  • variable-string
  • variablestring
  • variablestring
  • (variable?string

58
Arithmetic Operations
  • Arithmetic Operator
  • The Bourne shell does NOT include a simple
    built-in operator for arithmetic operations.

59
The expr Command
  • The expr Command
  • - In the Bourne shell (sh), you can use the expr
    command to evaluate expressions.

60
Arithmetic Operators of expr
  • Arithmetic Operators
  • Addition operator
  • - Subtraction operator
  • / Division operator
  • Multiplication operator
  • Remainder operator

61
Arithmetic Operators of expr
  • Example
  • x10
  • xexpr x 1
  • echo x
  • 11

62
Relational Operators of expr
  • Relational Operators of expr
  • equal to
  • ! not equal to
  • greater than
  • greater than or equal to

63
For Loop
  • The Basic Format of For Loop
  • for variable
  • in list-of-value
  • do
  • command(s)
  • done

64
The While Loop
  • The Format of While Loop
  • while condition
  • do
  • command(s)
  • done

65
The Until Loop
  • The Format of the Until Loop
  • until condition
  • do
  • command(s)
  • done

66
Debugging Shell Programs
  • Debugging Shell Programs
  • We can use the sh command with one ot its
    options to make the debugging of the script files
    easier.

67
Debugging Shell Programs
  • Options of sh Command
  • -n Read commands, but does not execute them.
  • -v Prints the input to the shell as the shell
    reads it.
  • -x Prints command lines and their arguments as
    they are executed. This option is used mostly
    for debugging.

68
THE END
Write a Comment
User Comments (0)
About PowerShow.com