Unix Lab Handbook

Embed Size (px)

Citation preview

  • 8/10/2019 Unix Lab Handbook

    1/13

    SESSION-1

    1. Logon to your Unix Login account

    2. Change the Password of your account (use passwd command)

    3. Oser!e the directory where you are p"aced (use pwd )

    #. List the contents of your home directory

    $. List out the hidden fi"es

    %. Create a directory structure as e"ow under your home directory

    &. Create fi"es india1 and india2 under india ' de"hi1 and de"hi2 under de"hi and "iewise under a"" otherdirectories.

    . Change the directory from home to anga"ore.

    *. Copy fi"e anga"ore1 from anga"ore to arachi.

    1+. Change directory to india from anga"ore.

    11. ,o!e fi"e de"hi1 to mumai.12. List the contents of mumai from current directory which is india.

    13. Copy a"" fi"es anga"ore1 and anga"ore2 from anga"ore to "ahore with a sing"e command.

    1#. -iew the contents of "ahore from india.

    1$. i!e the command "s /" and oser!e the output.

    1%. i!e the command cat india1 and then the command "s 0" again.oser!e the output and chec whether

    there is a change in the time co"umn.

    Page 1 of 13

  • 8/10/2019 Unix Lab Handbook

    2/13

    SESSION-2

    1. Create a fi"e 455 and store the names of your friends' their addresses and phone numers.

    4ach "ine shou"d contain a friend6s detai".

    2. isp"ay the numer of "ines' words and characters in the fi"e.

    3. isp"ay on"y the numer of "ines in the fi"e.#. -iew the fi"e one page at a time.

    $. Create a directory ca""ed 7riends and copy this fi"e into the directory.

    %. isp"ay a anner that reads 8e"come 7riends.

    &. Create 2 fi"es with the names of your fa!ourite criceters and try out cmp' comm and diff on them.

    . isp"ay the time when you "ogged on to the system.*. isp"ay the names of a"" those who are "ogged on to the system and store the resu"t in a fi"e

    89OL:5;.

    1+. -iew the ca"endar for the pre!ious ' current and next months of the current year with a sing"e

    command.

    11. isp"ay the date in the format ;4 :5 dd/mmm/yyyy ( 4x. ;4 :5 12/dec/2+++ )

    12. 5tore the detai"s of a"" those "ogged on to the same fi"e 89OL:5; with the existing detai"s.

    13. Use man and chec out the other options with date.1#. isp"ay the numer of fi"es present in your current directory

    1$. isp"ay the "isting of a"" fi"enames starting with < fo""owed y any digit and ending with 5.;here can

    e any numer of characters etween the digit and 5.

    Page 2 of 13

  • 8/10/2019 Unix Lab Handbook

    3/13

    SESSION-3

    Create a fi"e :;4,5 ha!ing the fo""owing data. 7ie"ds are item code/description/rate/=O9/order

    p"aced (n for no and y for yes)

    i++%/rexin/1++/1++/y

    i++2/screws/12/23/n

    i++1/o"ts/123/12+/n

    i++$/ruer/1+/1+/y

    i++3/p"astic/1+/1++/n

    i++#/nuts/2++/1++/y

    i++2/screws/12/23/n

    i++1/o"t/123/12+/n

    1. isp"ay items for which order is not p"aced.2. isp"ay the description and order p"aced fie"ds for a"" the items.

    3. isp"ay the description and order p"aced fie"ds for items for which order is p"aced.

    #. rrange the fi"e in the order of description.

    $. isp"ay dup"icate "ines if any in the fi"e :;4,5

    %. isp"ay "ines that contain on"y 1+ in them&. isp"ay a"" the items with item numer disp"ayed with on"y one >ero (ex. i++1 as i+1)

    . isp"ay a"" "ines where =O9 is "ess than $+

    *. isp"ay the "ast 2 "ines of the fi"e :;4,5

    1+. 5ort the fi"e in the order of rate and store it in a fi"e ;4

    11. Change the fie"d seperator from / to ? in the fi"e ;4

    12. isp"ay rate and description of item (in that order ) from fi"e ;4

    13. isp"ay the count of "ines that ha!e @screwsA in them.

    1#. isp"ay the "ines that donot contain @o"tsA in them.

    Create a fi"e ca""ed 5;O45 which has the fo""owing data ?

    i++%?ammonia?1++?1++?123?n

    i++#?rexin?23?12?12?y

    i++2?screws?2++?1++?1&$?y

    i++1?nuts?1+?1++?1&$?ni++3?o"ts?123?12+?12+?n

    i++$?ruer?1+?1+?1+?y

    i++2?screws?2++?1++?1&$?y

    i++&?o"t?123?12+?12+?n

    ;he fie"ds are item numer' description' =O9' OL' O=' status(y of those items for which an order has

    een p"aced. B denotes that no order has een p"aced for that item.)

    1. rrange the fi"e in the order of item numer.

    2. isp"ay the item numer' description and the reorder uantity.3. isp"ay the item numer' description and the reorder uantity on"y for those items for which an

    order is p"aced.

    #. #. isp"ay on"y the description (in the ascending a"phaetica" order) and store the sorted resu"t in

    $. a fi"e ca""ed sorted.

    %. 5ort the fi"e in the order of =O9 and disp"ay item numer and =O9 in that order.&. isp"ay the dup"icate "ines in the fi"es.

    Page 3 of 13

  • 8/10/2019 Unix Lab Handbook

    4/13

    . isp"ay the first 3 "ines of the fi"e sorted.

    *. isp"ay on"y the item numers that too with on"y one +. i.e. :++1 shou"d e disp"ayed as :+1.

    1+. isp"ay the numer of "ines that contains a 1++ in it.

    11. isp"ay on"y those records for which the =O9 fie"d is "ess than 1++.

    12. isp"ay the detai"s in the order description?item numer?OL?=O9.13. 5ort the fi"e in the order of =O9 within escription which shou"d e in the descending

    1#. "phaetica" order and store it in a fi"e which has your name. Using the same command "ine'1$. isp"ay the first # "ines on the screen a"so.

    1%. isp"ay the entire records in the fi"e ut the fie"d separator shou"d e a hyphen(/) instead of

    1&. co"ons (?).

    1. isp"ay those records which does not contain 1+ in it.

    1*. isp"ay the records as

    item numer description =O9

    Bote that the fie"d separator has to e a ta character.

    Uti"ise the rest of the time to fami"iarise with the !i editor.

    Page # of 13

  • 8/10/2019 Unix Lab Handbook

    5/13

    SESSION-4

    1. Open !i editor and create a fi"e 5;U containing the fo""owing data

    s++2?aash?unix?*?&

    s++#?>eenat?c?3#?*+

    s++$?>aira?!?$%?2

    s++1?puDa?orac"e?*+?%32. 5a!e the fi"e.

    3. Copy "ine numer 1 e"ow "ine numer #.

    #. o!e the "ine 1 add the text 5;U4B; 4;:L5

    $. ,o!e "ine 2 e"ow the "ine containing code s++#.

    %. Copy "ines 1'2 E 3 at the end of existing "ines.&. 5earch for the pattern puDa (using editor command) in the fi"e and de"ete it.

    . 5a!e the fi"e and uit editor.

    *. 5ort the fi"e 5;U(in the acground) on student code and store the resu"t in the same fi"e.

    1+. i!e the ps command and oser!e the output.

    11. i!e the command "s 0" and oser!e the permissions for the fi"e 5;U.

    12. i!e execute permissions for a"" the category of users for fi"e 5;U' and oser!e the same with "s /".

    13. i!e write permissions for group and others for fi"e 5;U(use octa" notation )' and oser!e the samewith "s /".

    1#. emo!e the write permission for the user (owner) for 5;U and try modifying the fi"e.

    1$. Create a directory named : .emo!e execute permissions for : for the user(owner)

    1%. Change the directory to :. :s it possi"e .:f no ' what is the so"ution.

    1&. Create a student data fi"e in !i which contains the detai"s of a"" your friends (a minimum of 2$

    records). 4ach record shou"d contain the fo""owing detai"s ? 5tudent Bumer' 5tudent Bame' Fatch

    Bumer' ,ars :n 4xam1' ,ars :n 4xam2. ;he fie"d separator shou"d e a co"on.

    1. i!e the command to sort the ao!e mentioned fi"e in the order of Fatch Code in the acground.

    ,ae sure that the sorted data gets stored in the same fi"e.

    1*. isp"ay a "ong "isting of your home directory. 5tore the detai"s in a fi"e ca""ed "ist y gi!ing a

    2+. command in the same "ine.

    21. Chec whether the sorting is sti"" going on' in the acground. :f so' terminate it.22. isp"ay on"y the fi"ename and the si>e of a"" the ordinary fi"es in your home directory.

    23. epeat the ao!e command y taing the input from the fi"e "ist instead of direct"y taing it

    2#. from the :s command.

    2$. isp"ay the names of a"" fi"es which has a rwx permission for the group.

    2%. isp"ay the names of on"y those fi"es that are executa"e.

    2&. isp"ay the numer of ordinary fi"es in your directory.

    2. Chec what are the processes that are running now.

    2*. :ssue the command to terminate the entry with the name sh.

    3+. 5end a message to another user asing for his f"oppy disette.

    31. Chec whether you ha!e a mai".

    32. Uti"ise some time in getting accustomed to the interna" commands of mai".

    33. isp"ay the contents of student data fi"e without any co"ons.3#. isp"ay the contents of student fi"e in the a"phaetica" order of 5tudent Bame (On"y the Fatch

    3$. Code and 5tudent Bame has to e disp"ayed).

    Page $ of 13

  • 8/10/2019 Unix Lab Handbook

    6/13

    SESSION-5

    : 8rite she"" scripts for the fo""owing

    1) ccept a word and a fi"ename. Chec whether the pattern exists in the fi"ename. :f it exists

    disp"ay 7i"e Gfi"ename H contains the pattern GpatternH e"se disp"ay error message that the pattern

    GpatternH does not exist in the fi"e Gfi"enameH.

    2) ccept 2 fi"enames. :f the fi"es are simi"ar disp"ay a message Foth the fi"es are simi"ar . Prompt

    the user for the name of fi"e to de"ete among these 2 and de"ete the named fi"e. fter de"etion a

    message 7i"e Gfi"enameH successfu""y de"eted shou"d e disp"ayed.

    3) isp"ay a directory "isting as fo""ows for a"" the fi"enames in the named directory and fina""y the

    tota" numer of fi"es

    irectory name is GdirnameH

    7i"ename permissions si>e

    / / /

    ;ota" fi"es is Gtota"H

    #) ccept the fo""owing data ' !a"idate them and store in a fi"e Student

    5tudent code

    5tudent name

    Fatch code

    ,ars1

    ,ars2

    ,ars3

    Validations:

    i) 5tudent code shou"d e uniue. :t can contain on"y a"phaets and digits.

    ii) 5tudent name can contain on"y a"phaets and space.

    iii) Fatch code can contain on"y a"phaets and digits.i!) ,ars can contain on"y digits and has to e greater than >ero.

    !) Bone of the fie"ds can e "eft "an.

    $) ccept 1+ numers from the user and disp"ay the sma""est and "argest of them.

    :: 8rite she"" scripts for the fo""owing ?1) ccept a pattern and a fi"e name. Chec whether the pattern is existing in the fi"e. :f

    found'disp"ay @;he pattern GpatternH exists in the fi"e Gfi"enameH. :f it is not found' disp"ay the

    error message as @;he pattern GpatternH is not found in the fi"e Gfi"enameHA.

    2) ;o disp"ay the fo""owing information ?

    Iour Login irectory is GLogin irectory BameHIour wi"" get the primary prompt as GPrimary PromptH

    Bow the date and time is GdateH

    Iou can execute fi"es in the directories GpathH.

    3) ccept the name of a fi"e' a sudirectory name (which this she"" script has to create) and the

    directory under which this specified sudirectory has to e created. Create the new sudirectory

    Page % of 13

  • 8/10/2019 Unix Lab Handbook

    7/13

    at the specified p"ace and mo!e the named fi"e from your home directory to this new"y created

    directory.

    #) ;o disp"ay a directory "isting as fo""ows ?

    Iour 9ome irectory is Ghome directory nameH

    7i"ename1 5i>e ate ;ime7i"ename2 5i>e ate ;ime

    7i"ename3 5i>e ate ;ime

    ?

    ;ota" numer of fi"es ? Gtota" numerH

    $) ccept a fi"ename as the command "ine argument. -a"idate for the numer of arguments. :f it is

    not eua" to one' disp"ay

    Usage ? count Gfi"enameH

    and terminate execution.

    Chec whether the fi"e is existing and it is an ordinary fi"e. :f there is an error' disp"ay

    a suita"e message and terminate execution.

    :f there are no errors' disp"ay the output as ?;he statistics of the fi"e Gfi"enameH are as fo""ows ?

    Gno. of "inesH numer of "ines.

    Gno. of wordsH numer of words.

    Gno. of charactersH numer of characters.

    Page & of 13

  • 8/10/2019 Unix Lab Handbook

    8/13

    SESSION-6

    : 8rite she"" scripts for the fo""owing

    1) ccept a string. isp"ay its "ength and a"so disp"ay the string in the re!erse order.

    (4x. india as aidni )2) ccept a string from the user and chec whether it is a pa"indrome or not and disp"ay appropriate

    message. (Pa"indrome is a word that reads the same from "eft as we"" as from right. 4x. noon )

    3) ccept a numer from the user and disp"ay its factoria"

    #) enerate a fionacci series +'1'1'2'3'$''1$'JJJJ' accept the numer of e"ements from the

    user.$) ccept a fi"ename as a command "ine parameter .Chec if it has read and write permissions for

    group. :f the permissions exist disp"ay a message that permissions exist otherwise set the

    permissions for the gi!en fi"e.:f no arguments are passed the script has to disp"ay appropriate

    error message or an usage he"p.

    :: 8rite she"" scripts for accepting the fo""owing information and storing it in a fi"e.

    Cassette Bo.,o!ie Bame

    Language

    Price

    ate of re"ease.

    ;he user shou"d e gi!en the faci"ity to enter as many records as he wants.

    2. 8rite a she"" to accept the detai"s for 484LL L:FI. ;he detai"s to e stored are ?

    Foo Bo

    Bame of the oo

    uthor

    Pu"ishers Bame

    PriceIear of re"ease

    5uDect Code

    -a"idations

    Foo Bo. shou"d not e existing in the fi"e.

    Bame of the oo' author and the pu"ishers name entered cannot e "an.

    Iear of re"ease shou"d e "ess than 1**%.

    Price entered cannot e >ero.

    5uDect Code can on"y e either UB:K or C.

    ;he user shou"d e a"e to repeated"y enter the data unti" it is !a"id. 9e shou"d a"so e a"e to

    enter mu"tip"e records.

    3. 8rite a she"" script which wi"" do the fo""owing? ;he first parameter has to e a directory name. :tshou"d e fo""owed y fi"enames. ;here can e more than 1+ fi"enames. ;hese specified fi"es

    shou"d e copied to the directory name passed as the first parameter. ;he script shou"d a"so

    chec whether the directory is a"ready existing. :f not it has to e created. ;he program shou"d

    a"so chec for the existence of indi!idua" fi"es whether they are existing and are reada"e.

    Page of 13

  • 8/10/2019 Unix Lab Handbook

    9/13

    #. 8rite a she"" procedure to de"ete the specified record from the "irary fi"e. :t shou"d accept a oo

    numer' chec whether it is existing. :f so' disp"ay the current detai"s' as for confirmation and

    then de"ete it from the fi"e.

    $. 8rite a she"" procedure to update the price fie"d in the "irary fi"e. ;he script shou"d accept a !a"idoo numer. ;he script shou"d add 1++ to the existing price of the oo and update the fi"e.

    Page * of 13

  • 8/10/2019 Unix Lab Handbook

    10/13

    SESSION-7

    1. ;he fi"e 4,PLOI44 contains the emp"oyee code' emp"oyee name' designation and sa"ary of the

    emp"oyees

    +++1/satya/c"er/3+++

    +++2/nisha/manager/1+++++++3/suman/executi!e/%+++

    +++#/!idya/g.m/12+++

    +++$/sandhya/exec/1++++

    +++%/pawan/m.d/12+++

    +++&/ashwin/exec/#++++++/madhu/director/2+++

    +++*/madhoo/manager/&+++

    ++1+/sang"i/executi!e/13+++

    2. 8rite an aw script to print a"" the emp"oyee names and their sa"ary.

    3. Print a"" the records in a formatted manner as e"ow.

    +++1 satya c"er 3++++++2 nisha manager 1++++

    #. Print a"" the records where the sa"ary is greater than %+++.

    $. Print a"" the records where sa"ary is greater than %+++ and designation is director.

    %. Print a"" the records that contain madhu or madhoo in them.

    &. Print the "ongest record in the fi"e.

    . Print the records with record"ine numers.

    *. ;o the ao!e script add a heading 4,PLOI44 4;:L5 and the tota" numer of emp"oyees in the

    end.

    1+. ,ae changes to the ao!e script such that a"" the detai"s are centered across the output screen

    11. ccept a word and disp"ay its "ength. 8rite a she"" script for the ao!e.

    12. 8rite a she"" script for accepting a word from the user and disp"ay the re!erse of the word.

    4xamp"e ? :f the user enters @;UL4C M2A' disp"ay it as @2M C4LU;A.13. 8rite a script for the fo""owing ?

    ccept a .c fi"ename and an executa"e fi"e name as command "ine arguments. cti!ate the !i

    editor to createedit the specified .c fi"e. Once when the user comes out of !i' the script shou"d

    compi"e the .c fi"e to gi!e an executa"e fi"e of the specified name. Command to compi"e a .c

    fi"e is

    cc /o Gexecuta"e fi"eH G.c fi"enameH

    "" errors shou"d e redirected to a fi"e named err"ist.

    :f there are errors' disp"ay the error "isting one page at a time after disp"aying the message @;he

    fo""owing are the errors encountered in the fi"e G.c fi"enameHA. ;hen open !i to edit the .c fi"e.

    :f there are no errors' run the executa"e fi"e after gi!ing executa"e permission for it. Once

    8hen the user finishes running the fi"e' as a uestion @o you want to continue (IB) NA and

    accept an answer from the user. epends on the users wish' either continue execution orterminate it.

    1#. ccept a fi"ename. ssign a read and write permission to others for that fi"e' on"y if it is not

    ha!ing these permissions at present. ;he ao!e mentioned tass shou"d e achie!ed with the

    he"p of a she"" script.

    1$. 8rite she"" scripts for the fo""owing ?

    Page 1+ of 13

  • 8/10/2019 Unix Lab Handbook

    11/13

    (a) Locate the fi"es under your home directory that ha!e not een modified for the "ast one wee.Copy a""

    those fi"es to a sudirectory ca""ed @O"diesA. :f the sudirectory is not existing' create it. Fefore

    copying indi!idua" fi"es' as the user @o you want to copy Gfi"enameH to O"dies or de"ete it

    (C) NA. :f the user enters @CA (Capita" or sma"" "etter)' copy the fi"e. :f the user enters @A or @dA'de"ete the fi"e.

    () ;he script shou"d disp"ay the name of indi!idua" fi"es in your directory one after the other in

    the fo""owing format ?

    Gfi"enameH Copy,o!ee"eteLin (C,L) N.

    ;he user shou"d e a"e to enter either C' , or as per hisher wish. epends on the option

    entered y the user' the action has to e taen.

    :n the case of C' , and L' as for a destination directory. Once when the directory name is

    accepted' chec whether the directory is a"ready existing. :f it is not existing' as the user

    @Gdirectory nameH not found / 8ant to create (IB) NA. :f the user enters @IA or @yA' prompt for

    the name of the parent directory under which the new directory has to e created. Continueaccepting the name of the parent directory unti" the user enters a !a"id directory name that

    is existing. ;hen create the directory and proceed with Copy' ,o!e or Lin. :f the option

    entered y the use is for de"etion i.e. ()' de"ete the fi"e after getting a confirmation from the

    user.

    (c) Create a student fi"e which contains the fo""owing data ?

    atch code ? student code ? a!erage mars ? status

    ccept Fatch Code' 5tudent Code' ,ars in exam 1 and ,ars in exam 2. Ca"cu"ate the

    a!erage mars. 7ind out status as passed or fai"ed depending on whether the student got

    ao!e $+ or not. ;he she"" shou"d continue execution ti"" the user responds y saying @BA tothe uestion @,ore (IB)A prompted y your she"" script.

    :ncorporate as much !a"idations as possi"e.

    Once when the program terminates' it shou"d disp"ay

    ;his program started running at Gstarting timeH.

    nd finished its execution at Gending timeH.

    (d) ;he script shou"d disp"ay the fo""owing information ?

    ;he free dis space a!ai"a"e on the fi"e system is GnumerH. and the space used y the

    current directory and its su/directories is GnumerH.

    Page 11 of 13

  • 8/10/2019 Unix Lab Handbook

    12/13

    SESSION-8

    Contents of the fi"e P9OB4 are

    5mith' ;erry' &/&*

    Fo' 8i""s' 2/3#$#

    5te!e' 8augh' 3/$*&Frown' 5parrow' #/$$#

    Frown' 9edge' &/3#$%

    Louis' Chris' #/%233

    : 8rite sed commands for the fo""owing

    1) isp"ay the "ines 2'# and % from the fi"e.

    2) isp"ay the "ines ha!ing @FrownA in them.

    3) Print on"y the e!en numered "ines from the fi"e.

    #) Print on"y the odd numered "ines from the fi"e.

    $) 5ustitute terry with erry.

    %) 5ustitute rown with enson in the "ine containing hedge.&) isp"ay the firstnames with the text 7:5;B,4 efore them.

    ) e"ete a"" the "an "ines in the fi"e.

    *) :nterchange the phone numers such that code fo""ows the numer ( ex. %233/# )

    1+) 5tore the "ines ha!ing & in them in a fi"e 54-4B.

    ;he fo""owing input fi"e emp"oyee.dat contains the names' designation' asic' 9 and a""owances for

    the emp"oyees of same organisation.

    amesh 55 2+++ 1+++ 1+++

    Mrishna P5 3+++ 1$++ 1$++

    amaswamy 55 22++ 11++ 1+++

    Choudhary 5 1$++ &$+ &$+enua 55 12++ &++ 12++

    e!athi 55 1$++ ++ ++

    adha P5 2++ 1$++ 1$++

    Madamari 5 1$++ &$+ &$+

    1. 8rite aw script that wi"" print the emp"oyee name a"ong with the tota" sa"ary.

    2. Print a"" the records in re!erse order of their fie"ds (i.e. fifth fie"d fo""owed y the fourth' then

    the third' then the second and fina""y the first.)

    3. Print each record twice. 7irst with fie"ds in re!erse order (of fie"ds) and suseuent"y in the

    origina" order.

    #. Print the output in the fo""owing manner.

    amesh 55 2+++$. ;he fie"ds of the fi"eetc.passwd are "isted e"ow ?

    7i"e ? etcpasswd

    7ie"ds ? "ogin name?password?user id?group id?user name?home directory?"ogin she""

    $.1 Print out a"" "ogin names where "ogin name with user id "ess than 1++.

    $.2 Print a"" those "ogin names which egin with an UPP4 case a"phaet.

    Page 12 of 13

  • 8/10/2019 Unix Lab Handbook

    13/13

    fi"e atsman contains the fo""owing records.

    Bradman:Australia:6996

    a!as"ar:India:124:1#122

    So$ers:%est Indies:93:8#32

    Border:Australia:1#9:8#75

    'iandad:(a"istan:97:7121o)er:En*land:94:7#23

    Bo+,ott:En*land:1#8:8114

    %. i!e the aw statement for printing the shortest record of the fi"e atsman

    &. i!e the statement to print Dust the first three characters of the name and country fie"ds.

    . Print on"y the "ast digit of the "ast fie"d.

    *. 8rite an aw script to print the "ongest name.

    1+. Print the first fi!e records of the fi"e.

    11. 11.isp"ay the detai"s of the fi"e atsman after sorting it in the numerica" order of the fourth fie"d.

    12. Fy maing use of the atsman fi"e' write an aw script which wi"" store the records re"ated to the

    country @ustra"iaA in a fi"e @usA and that of 4ng"and in @4ngA.

    13. Print each "ine from the fi"e atsman with record numer.

    Page 13 of 13