Chap 2 Basics of UNIX

download Chap 2 Basics of UNIX

of 27

Transcript of Chap 2 Basics of UNIX

  • 8/3/2019 Chap 2 Basics of UNIX

    1/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 14/ 399

    BASICS OF UNIX

    STARTING TO USE UNIX

    All UNIX systems are administered andmaintained by a SYSTEM MANAGER or a

    SYSTEM ADMINISTRATOR(SA).

    USER ACCOUNT

    Every user is given a password- a secret

    code he must type in every time heuses the system

    A unique identity which identifies him tothe system - called USERID

    Once a user is given a userid and apassword in the system, he has anACCOUNT on that system

    1

  • 8/3/2019 Chap 2 Basics of UNIX

    2/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 15/ 399

    User Account contd...

    Account keeps track of most activitiesperformed by the user

    An Account has certain predefinedlimits also, like how much diskstorage space is allowed for files

    USERID

    Normally chosen by SystemAdministrator

    Used by UNIX to identify user

    For example, any data files created byuser A will be owned by his UserID

    NOT secret

    2

  • 8/3/2019 Chap 2 Basics of UNIX

    3/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 16/ 399

    THE PASSWORD

    IS secret

    Encrypted by the system, nobody canread it

    If forgotten, only SA can give out afresh password

    LOGGING IN AND OUT

    Terminal needs correct connections tocomputer running UNIX

    User is online when connected

    When connection is lost, he goesoffline

    3

  • 8/3/2019 Chap 2 Basics of UNIX

    4/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 17/ 399

    Logging In And Out cond...

    Terminal may be

    - local which is directly cabled (hard-wired) to the computer

    - remotely connected via modemsand telephone lines

    LOGGING IN

    The process user goes through to starthis work is called logging In

    Consists of typing UserID and the

    password

    When the UNIX terminal is ready touse, it displays :

    4

  • 8/3/2019 Chap 2 Basics of UNIX

    5/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 18/ 399

    login : _

    Logging In contd...

    User types in his UserID, and pressesReturn

    login : Amit

    Backspace or Delete key allowed insome systems to correct errors

    On others, press the Return key any-way and wait for message whichinforms login was incorrect, and tryagain

    5

  • 8/3/2019 Chap 2 Basics of UNIX

    6/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 19/ 399

    Logging In contd...

    Once the UserID has been entered,UNIX prompts for password:

    Password : _

    Type password and press Return

    As password is typed, UNIX does notecho it on screen

    This helps in security and the feature is

    known as echo suppression

    6

  • 8/3/2019 Chap 2 Basics of UNIX

    7/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 20/ 399

    THE SHELL PROMPT

    After successful login, a prompt isdisplayed

    User gives series of commands to do

    his work

    Shell reads and interprets commands

    Each shell displays a different prompt:

    Bourne Shell $ (default, authorStephen Bourne)

    Korn Shell $

    C Shell % (bsd UNIX support)

    Superuser # (SystemAdministrator)

    7

  • 8/3/2019 Chap 2 Basics of UNIX

    8/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 21/ 399

    LOGGING OUT

    User can terminate session by pressingCtrl + D

    Sends end-of-file signal to UNIX

    Tells the shell no more data coming

    Shell terminates

    UNIX logs the user out

    Screen returns to the login prompt

    login : _

    8

  • 8/3/2019 Chap 2 Basics of UNIX

    9/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 22/ 399

    NOTES

    Each command in UNIX needs to beterminated by a Return key-press toexecute it

    UNIX DOES distinguish between upperand lower case letters

    If a UserID is given as amit, typing Amitat the login prompt will result in an

    incorrect login attempt

    UNIX, by default, uses lowercase

    9

  • 8/3/2019 Chap 2 Basics of UNIX

    10/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 23/ 399

    SHELL COMMANDS

    UNIX can be simple to complex,common to very, very rare

    A command is brief set of letters,

    followed by options or arguments

    General command format:

    command options expression filename

    Arguments

    Options modify behavior of command

    Marked with leading hyphen

    Example:

    $ ls -a10

  • 8/3/2019 Chap 2 Basics of UNIX

    11/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 24/ 399

    Shell Commands contd...

    Expression is group of charactersused as input to command

    Filename is name of file whichcommand refers to in some way

    All arguments are not mandatory inevery command

    Checking Date

    System date in UNIX checked throughthe date command

    UNIX uses 24 hour clock and givesthe time upto the second

    11

  • 8/3/2019 Chap 2 Basics of UNIX

    12/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 25/ 399

    $ dateThu Jan 08 14:07:43 IST 1998$ _

    Output

    Checking Date contd...

    Who Is There?

    The Who command displays:

    - A list of all active users in system

    - Terminals they are logged into

    - Date and time they last logged on

    12

  • 8/3/2019 Chap 2 Basics of UNIX

    13/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 26/ 399

    $ whostheer tty01 Jan 08 14:01anasua tty02 Jan 08 14:50indira tty04 Jan 08 15:06amit tty09 Jan 08 15:10

    User Names

    Terminal

    Month of login

    Date of login

    Time of login

    The Who Command contd...

    Argument can be added to the whocommand

    am i - If user shares his terminal withother users, and previous user has not

    logged out, who am i used to check whohas abandoned the terminal

    $ who am istheer tty01 Jan 08 14:01

    13

  • 8/3/2019 Chap 2 Basics of UNIX

    14/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 27/ 399

    MULTIPLE COMMANDS

    UNIX allows two or more commands tobe entered on the same line

    Put a semi-colon between each

    command, then press Enter after thefinal command

    $ date; whoThu Jan 08 15:12:43 IST 1998

    stheer tty01 Jan 08 14:01anasua tty02 Jan 08 14:50indira tty04 Jan 08 15:06amit tty09 Jan 08 15:10

    $ _

    14

  • 8/3/2019 Chap 2 Basics of UNIX

    15/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 28/ 399

    Non Existent Command !!

    When non-existent command isentered

    - UNIX gives a message saying the

    command is not found

    - It then returns to the shell prompt

    $ what is the datewhat is the date: not found

    $ who aam I

    who aam I : not found

    15

  • 8/3/2019 Chap 2 Basics of UNIX

    16/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 29/ 399

    Display On The Screen

    echo command displays a string onthe screen

    $ echo this is fun!!this is fun!!$_

    16

  • 8/3/2019 Chap 2 Basics of UNIX

    17/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 30/ 399

    Changing The Password

    When a users UNIX account is set up,the SA assigns a UserID and apassword

    Password can be later changed byuser by passwd command

    UNIX asks for old password first (why?)

    Then passwd prompts for newpassword

    17

  • 8/3/2019 Chap 2 Basics of UNIX

    18/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 31/ 399

    SETTING PASSWORDS

    Some systems need all passwords tomeet certain specifications, like thelength of the password should be aminimum of 8 characters

    If new password does not meetrequired criteria, you are so informedand asked to enter a new choice

    Finally, passwd asks you to reenter thenew password to ensure match with firstpassword

    No password, either old or new, is

    displayed on the screen as they aretyped

    The passwords are stored in a filecalled the /etc/password file

    18

  • 8/3/2019 Chap 2 Basics of UNIX

    19/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 32/ 399

    Setting Passwords contd...

    SCO UNIX and some other UNIXsystems offer automatic generation ofpronounceable but obscure passwordslike klibrufar !!

    SA can delete relevant entry frompassword file to allow user to enter hislogin if he forgets his password

    $ passwd

    Changing password for stheer

    Old password : mineonly

    New password : annieta1

    R-enter new password : annieta1

    $ _ NotEchoed O

    Screen

    19

  • 8/3/2019 Chap 2 Basics of UNIX

    20/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 33/ 399

    LOGIN PROFILES

    SA provides global actions, or defaultsettings that affect all users.

    They are placed in a file called the

    global login profile

    Shell executes commands in this filewhenever a user logs in

    User can modify some or all of thesedefaults either temporarily orpermanently for all sessions

    He runs commands of his choose to

    modify his environment during a givensession

    These changes last till he logs out

    20

  • 8/3/2019 Chap 2 Basics of UNIX

    21/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 34/ 399

    Login Profiles contd...

    Or, he can place these modifications inhis home directory (covered in the nextsession) in his personal login profile

    This gives the user a permanent startupenvironment each time he logs in

    Having a global profile for everyone,followed by personalized profiles for

    each user gives a lot of flexibility

    Similar to AUTOEXEC.BAT files in DOS,it is run automatically when user logs in

    Bourne shell looks for a file called profileunder directory etc

    If found, all commands in it are executed

    21

  • 8/3/2019 Chap 2 Basics of UNIX

    22/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 35/ 399

    Login Profiles contd...

    Next, it looks for a file called .profile(the users personal login profile) inthe users home directory

    If found, it executes it

    Then shell prompt appears on screen

    User 1 User 2

    Global Login Profile

    User Login

    Profile For User 2User 3 - has

    NO user

    login profile

    executed every time

    user1/2/3 logs on

    User Login

    Profile For User 1

    executedwhen user1logs in

    executedwhen user2

    logs in22

  • 8/3/2019 Chap 2 Basics of UNIX

    23/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 36/ 399

    SHELL VARIABLES

    Shell variables are like variables used inconventional programming languages

    Shell variables allow user to provide a

    name or variable identifier for someentity (example, PATH or doc)

    Variable names with capital letters areusually reserved for standard variables

    with pre-determined UNIX meanings

    Contents of all shell variables can beseen with the set command

    23

  • 8/3/2019 Chap 2 Basics of UNIX

    24/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 37/ 399

    Shell Variables contd...

    $ setHOME = /usr/stheer

    IFS=

    MAIL=/usr/mail/stheer

    PATH=:/bin:/usr/bin

    PS1=$

    PS2=>

    TERM=ansi$

    bin : binary object filesTERM :terminal type,

    normally ansi or vt100

    24

  • 8/3/2019 Chap 2 Basics of UNIX

    25/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 38/ 399

    $ PS1=Enter your command :Enter your command : _

    The promptchanges toEnter your command :

    THE PRIMARY PROMPT

    PS1 stores the primary prompt symbol($, by default)

    Setting PS1 to any character string will

    change the primary prompt

    No spaces are allowed before or afterthe assignment operator =

    The single forward quotes when settingPS1 ensures that spaces within thenew prompt string are transferred to PS1

    Any variable name, prefixed with a $displays content of variable rather than

    the variable name itself25

  • 8/3/2019 Chap 2 Basics of UNIX

    26/27BASICS OF UNIX -FOILS ON THE UNIX OS & SHELL PROG. 39/ 399

    The Primary Prompt contd...

    Enter your command:echo PS1PS1

    Enter your command : echo $PS1Enter your command : Content Of Primary Prompt

    PS1 is displayed

    THE SECONDARY PROMPT (PS2)

    Used when UNIX thinks you havestarted a new line without finishing acommand

    New lines can also be included in a

    quoted string

    After pressing Enter at end of first line,shell displays its secondary promptand waits for more input

    26

  • 8/3/2019 Chap 2 Basics of UNIX

    27/27

    The Secondary Prompt cond...

    After final quote and newline, shellunderstands command is complete,and executes it

    By default, PS2 stores the character >

    Example:

    Enter your command : PS1=$

    $ echo Friends, Romans, Countrymen > lend me your ears !!

    Friends, Romans, Countrymenlend me your ears !!$ echo $PS2>$ PS2=More Input :

    $ echo $PS2More Input :$ echo Friends, Romans, Countrymen

    More Input : lend me your ears !!

    The secondary prompt, >by default, waiting for the

    final quotes

    Changing the secondaryprompt to More Input

    :.

    The secondary prompt,now changed to MoreInput:, waiting for the