You are on page 1of 7

MCA 406-Linux Shell Programming LAB

Question #1 1. Create three dire tories named !xam1, Exam2 and !xam" under #our home dire tor# $. Mo%e to dire tor# !xam1. ". Create t&o dire tories named !xam11 and !xam1$ under the !xam1 dire tor# 4. Mo%e to dire tor# !xam$ using onl# one ommand 'dire tl# (rom !xam). *. Create three dire tories alled !xam$1, Exam22 and Exam23 under the dire tor# !xam$ 'use onl# one ommand) 6. Create a dire tor# alled !xam"1 under the !xam" dire tor# &ithout mo%ing (rom the !xam$ dire tor#. +. Mo%e to !xam$ ,ire tor# -. .sing /01 reate a (ile named test1 that ontains atleast ten lines. 2. Count the num3er o( &ords 1 lines and hara ters in this (ile 10. Ma4e a o5# o( test1 and all it test1.bk.store it under the same dire tor# &here test1 is stored. 11. Che 4 the 5ermission o( test1 1$. Store 6.708 %s. L07.89 in a %aria3le alled :S. 1". Print the ontents o( :S in su h a &a# that .708 %s should 5rint in oneline L07.8 should 5rint in another line 14. .se the a55ro5riate ommand or S#stem %aria3le to determine #our login shell. 1*. .se the ;et ;5ass&d (ile to %eri(# the result o( ste5 14. 16. .se the a55ro5riate ommand to determine #our urrent shell. 0s it the same as #our login shell< 1+. dis5la# the last 4 lines o( ;et ;5ass&d using 5ro5er ommands. 1-. Mo%e to #our home dire tor#. 12. =e ursi%el# lists all o( the dire tories #ou reated and dra& the dire tor# stru ture on 5a5er. Question #$ 1. Che 4 &hi h grou5 or grou5s #ou 3elong to. $. .se the unmas4 ommand to set the de(ault 5ermission to 3e +00 (or dire tories. >hat is the de(ault 5ermission (or (iles a(ter this ommand< ". Create a dire tor# named !xamSe ond under #our home dire tor#. 4. Che 4 the de(ault 5ermission o( this dire tor#. 0s it +00< *. Create a dire tor# under !xamSe ond dire tor# '&ithout mo%ing (rom #our home dire tor#) and name it !xamSe ond1 dire tor#.

+. Che 4 the 5ermission o( this dire tor#. 0s it +00< -. Mo%e to the !xamSe ond1 dire tor#. 2. Create a (ile named h&41 under this dire tor# and add some in(ormation to the (ile. 10. Sa%e this (ile. 11. Che 4 the 5ermission o( this (ile. 0s it +00 or 600< 1$. ,o users in #our grou5 ha%e an# a ess to this (ile< ,o other users 'outside o( #our grou5) ha%e an# a ess to this (ile< 1". .se the &ho ommand and redire t the result to a (ile alled (ile1. .se the more ommand to use see the ontents o( (ile 1. 14. .se the date and &ho ommands in se?uen e 'in one line) su h that the out5ut o( date &ill dis5la# on the s reen and the out5ut o( &ho &ill 3e redire ted to a (ile alled (ile$. .se the more ommand to he 4 the ontents o( (ile$. 0t should 3e same as (ile1 unless someone logged in or logged o(( 3et&een the &ho ommands. 1*. >ithout using an editor1 reate a one-line (ile1 alled (ile11 using the e ho ommand 'use out5ut redire tion). @his is one o( the &a# &e an reate a short (ile ?ui 4l#. 16. Che 4 the ontents o( (ile1 using the more ommand 1+. Mo%e to #our home dire tor# 1-. =e ursi%el# lists all o( the dire tories #ou reated and dra& the dire tor# stru ture on 5a5er. Question #" 1. =e uri%el# lists the dire tories under #our home dire tor# 'the ones reated in session 1). $. Mo%e to the .708 dire tor#. ". Che 4 #our urrent dire tor# 4. .sing /01 reate a (ile named hw4 that ontains short ans&ers to at least (i%e re%ie& ?uestions in this ha5ter. *. Sa%e the (ile 'it should 3e sa%ed under the .708 dire tor#). 6. Mo%e to #our home dire tor#. +. Print the ontent o( hw4 (rom #our home dire tor#. -. Ma4e a o5# o( hw4 and all it hw4.bk.store it under the same dire tor# &here hw4 is stored. 2. (rom #our home dire tor#1 he 4 to see i( 3oth (iles 'hw4 and hw4.bk) exit. 10. Mo%e to the .708 dire tor# 11. Che 4 #our urrent &or4ing dire tor#. 1$. Ma4e a hard lin4 to the hw4 (ile. @he lin4 should 3e under the .708 su3dire tor# and 3e alled hw4HL. 1". Ma4e a so(t lin4 to hw4 called hw4SL and store it under the .708 dire tor#. 14. Che 4 the inode o( hw4, hw4.bk, hw4SL.Are all the same< Are all di((erent< !x5lain ho& #ou determined the ans&er. 1*. .se the ls ommand to (ind the (ile t#5es o( hw4, hw4.bk, hw4HL, and hw4SL.!x5lain #our o3ser%ation.

Question #4 1. Create a 3a 4u5 dire tor# in #our home dire tor# alled backups. $. .se the (ind ommand to (ind the 5athnames o( all the (iles ' hw4, hw4.bk, hw4HL, and hw4SL ) that #ou reated in session $.All o( them should 3e (ound using onl# one (ind ommand. @he ommand must also o5# all o( them to the backups directory. ". Che 4 the num3er o( lin4s and inode num3er o( hw4, hw4.bk, hw3HL, and hw4SL.Ma4e note o( the results. 4. ,elete the original hw4 (ile &ithout mo%ing (rom #our home dire tor#. *. Che 4 the existen e o( hw4, hw4.bk, hw3HL, and hw4SL. 6. Che 4 the ontents o( hw4, hw4.bk, hw3HL, and hw4SL. +. =estore the (ile hw4 3# ma4ing a o5# o( hw4.bk -. Aou ma# ha%e noti ed that #our so(t lin4 'hw4SL) ontains gar3age. ,elete this (ile. 2. Ma4e a ne& so(t lin4 to hw4 and store it as hw4SL under the same dire tor# as it &as. 10. List re ursi%el# all o( #our (iles and dire tories to on(irm all o5erations. 11. ,ra& the (ile and dire tor# stru ture o( #our home dire tor#. Question #* 1. >ild ards to dis5la# all o( the (iles #ou ha%e reated under the H s dire tor# &ithout mo%ing (rom #our home dire tor#. $. =ename hw4.bk to hw4.bak. ". Create a short (riendl# letter1 alled !riend .", using %i and store it under the !riendly dire tor#. 4. Create a short (ormal letter1 alled !ormal ."1 using %i and store it under the !ormal dire tor#. Bi%e a title to !ormal." letter. *. Co5# the (ile !ormal. " and all the ne& o5# !ormal.2. 6. Change onl# the title o( !ormal.2 #using %i) and store it. +. .sing &ild ards 5rint the ontents o( !ormal." and !ormal.2. -. Ma4e a dire tor# alled bus Letters under #our home dire tor#. 2. Mo%e the !ormal dire tor# '&ith all o( its ontents) under the bus Letters dire tor#. 10. Ma4e a re ursi%e list o( #our dire tor# stru ture. 11. ,ra& the ne& dire tor# stru ture on 5a5er. Question #6 1. Che 4 &hi h grou5 or grou5s #ou 3elong to. $. .se the unmas4 ommand to set the de(ault 5ermission to 3e +00 (or dire tories. >hat is the de(ault 5ermission (or (iles a(ter this ommand< ". Create a dire tor# named CCAP@!=D4 under #our home dire tor#.

4. Che 4 the de(ault 5ermission o( this dire tor#. 0s it +00< *. Create a dire tor# under CCAP@!=D4 dire tor# '&ithout mo%ing (rom #our home dire tor#) and name it sessionDi dire tor#. +. Che 4 the 5ermission o( this dire tor#. 0s it +00< -. Mo%e to the sessionDi dire tor#. 2. Create a (ile named h&41 under this dire tor# and add some in(ormation to the (ile. 10. Sa%e this (ile. 11. Che 4 the 5ermission o( this (ile. 0s it +00 or 600< >h#< !x5lain the di((eren e 3et&een the 5ermissions (or (iles and dire tories. 1$. ,o users in #our grou5 ha%e an# a ess to this (ile< ,o other users 'outside o( #our grou5) ha%e an# a ess to this (ile< 1". Change the 5ermissions to allo& users in #our grou5 onl# to o5# this (ile to their o&n dire tories. 0s there a need to hange the 5ermission o( an# dire tories< 0s #es1 ma4e the ne essar# hanges. 14. As4 a user in #our grou5 to o5# this (ile into his or her home dire tor#. >as the o5# su ess(ul< 0( not1 (ind the reason and ta4e the a55ro5riate a tions to orre t it. @hen ha%e #our user-grou5 (riend tr# again. Question #+ 1.Che 4 &hi h grou5 or grou5s #ou 3elong to . $. Che 4 #our de(ault mas4. ".Create a dire tor# alled garbage under #our home dire tor#. 4. Che 4 the 5ermission o( this dire tor#.Ma4e a note o( it. *.Change #our de(ault mas4 so that the de(ault 5ermission is 664.>hat is the de(ault 5ermission (or dire tories a(ter #ou ma4e this hange< 6.Che 4 the 5ermission (or the garbage dire tor#.Cas it 3een hanged a(ter setting the de(ault mas4<>h# or &h# not< +. ,elete this dire tor#. -.Create a dire tor# alled session_II under the chapter_4 dire tor#. 2. Che 4 the 5ermission o( this dire tor# and ma4e a note o( it. 10. =emo%e the x 5ermission (or the user (rom this dire tor#. 11. Mo%e to session_II dire tor#.Aou should ha%e a 5ro3lem.,o #ou 4no& &hat the 5ro3lem is<Eix the 5ro3lem. 1$. Create a (ile named hw_4_2 under this dire tor# and t#5e ans&ers to ?uestion 11. 1". Sa%e this (ile. 14. Che 4 the 5ermissions o( this (ile.Can users in #our grou5 o5# this (ile<Can the# hange this (ile< Can users outside #our grou5 o5# this (ile<Can the# hange this (ile<0s this (ile exe uta3le< 1*. Change the 5ermissions o( this (ile so that e%er# user an read 1modi(#13ut not exe ute this (ile. 16. Print this (ile. Question #1. $. ". 4. .se the a55ro5riate ommand to determine #our login shell. .se the ;et ;5ass&d (ile to %eri(# the result o( ste5 $. .se the a55ro5riate ommand to determine #our urrent shell. 0s it the same as #our login shell< Create a su3shell shell that is not the same shell as #our login shell. ' i( #our login shell is 4orn1 reate a 3ash or C shell. *. Che 4 the urrent shell again. ,oes it mat h &ith #our login shell<

6. +. -. 2.

Create another shell &hi h is the same t#5e as #our login shell. Che 4 the urrent shell again. ,oes it mat h &ith 5re%ious one< !xit (rom the su3shell shell and mo%e to #our login shell. Che 4 the urrent shall again. 0s it the same as the login shell<

Question #2 1. .se the &ho ommand and redire t the result to a (ile alled (ile1. .se the more ommand to use see the ontents o( (ile 1. $. .se the date and &ho ommands in se?uen e 'in one line) su h that the out5ut o( date &ill dis5la# on the s reen and the out5ut o( &ho &ill 3e redire ted to a (ile alled (ile$. .se the more ommand to he 4 the ontents o( (ile$. 0t should 3e same as (ile1 unless someone logged in or logged o(( 3et&een the &ho ommands. ". Set %i to 3e #our ommand line editor. 4. .se #our ommand line editor to re all the line #ou t#5ed in ste5$ edit the line so that the out5ut o( 3oth ommands 'date and &ho) are redire ted to a (ile alled (ile". .se the more ommand to dis5la# the result. *. .se the ommand line editor to re all the line #ou t#5ed in ste5$ !dit the line so that the out5ut o( the (irst ommand 'date) is redire ted to a (ile alled (ile41 &hile the result o( the &ho ommand dis5la#s on the monitor &ithout hanging the relati%e 5ositions o( the date and &ho ommands. .se the more ommand to %eri(# the result. 6. Ma4e a du5li ate o( (ile" and all it (ile".3a4 +. .se ommand-line editor to re all the line reated at ste5 6 . !dit the line so that the &ord 6date9 &ill 3e miss5elled as 63ate9. !xe ute the edited ommand and a55end the result to (ile". .se more to om5are (ile" and (ile".3a4 -. .sing ommand-line editing1 re all the line reated in ste5 2. !dit it so that the errors also go to (ile" &ithout re5la ing the (iles ontents. Che 4 the ontents o( (ile" (or %eri(i ation 2. .se ommand-line editing1 re all the line reated in ste5 10 !dit it so that the out5ut goes to (ile4 and errors go to (ile* Question #10 1. >ithout using an editor1 reate a one-line (ile1 alled (ile11 using the e ho ommand 'use out5ut redire tion). @his is one o( the &a# &e an reate a short (ile ?ui 4l#. $. Che 4 the ontents o( (ile1 using the more ommand ". 7o&1 &ithout using an editor1 reate a t&o line (ile1 (ile$1 using the e ho ommand. .se dou3le ?uotes (or the argument o( the e ho ommand. Put the o5ening ?uote in the (irst line and the losing ?uotes in the se ond line1 3ut do not lose it until the end o( the se ond line. 0n #our o&n &ords1 ex5lain &hat #ou Fust did and &h# it &or4s. 4. Che 4 the ontents o( (ile$ using the more ommand *. Store 6.708 %s. others9 in a %aria3le alled (a ts. 6. 7o& use the (ollo&ing ommandG e ho 6@his is a (a t H(a ts in our (ile9. >hat is 5rinted and &h#< +. 7o& use the (ollo&ing ommand

Question #11 1. 7o& use the (ollo&ing ommandG e ho 6@his is a (a t IH(a ts in #our li(e9 >hat &ould 3e 5rinted and &h#< $. @r# to use a ommand to 5rint the (ollo&ing message 'in luding the ?uetes) using the %alue o( %aria3le (a tsG 6@his is a (a t 6.708 %s. :thers 6 in #our li(e9 ". Store the &ord 6PA=!7@9 in a %aria3le alled (irstJ 4. Print the %alue o( the %aria3le (irst 'using e ho ommand). *. Create a su3shell shell using the same t#5e o( shell as #our login shell 'Korn or Bash or C). 6 . Print the %alue o( %aria3le (irst in the su3shell. >hat &as 5rinted< 0( 6PA=!7@9 &as not Printed ex5lain &h# . +. Store the &ord 6S.BSC!LL9 in a %aria3le alled se ond -. Print the %alue o( the %aria3le se ond. 2. !xit (rom the su3shell shell and mo%e to #our login shell. 10. Print the %alue o( (irst . >hat &as 5rinted< Co& do #ou ex5lain the result. 11. Print the %alue o( se ond. >hat &as 5rinted< Co& do #ou ex5lain this result<

Question #1$ 1..se the at ommand to reate (ile ontaining the (ollo&ing data . all it Ch6S1E1. 14$* L.A7 14.$* 4"$1 B!:=B! $1.11 6+-1 A77A 16.++ 14*1 B!7 $1.++ $$++ @.A7 1-.++ $. .se the at ommand to dis5la# the (ile and he 4 (or a ura #. ". .se the %i ommand to orre t an# errors in the (ile. 4..se sort ommand to sort the (ile Ch6S1E1 a ording to (irst (ield . Call the sorted (ile Ch6S1E1'same name). *.Print the (ile Ch6S1E1. 6..se the ut and 5aste ommands to s&a5 (ields $ and " o( Ch6S1E1. all it as Ch6S1E1'same name). +.Print the ne& (ile Ch6S1E1.

Question #1" 1..se tail ommand to reate and sa%e the (ollo&ing (ile.Call it Ch6S$E1. PASS!S ALL ,A@A E=:M 07P.@ @: :.@P.@

PASS!S :7LA SP!C0E0!, C:L.M7S PASS!S 7.MB!= :E SP!C0E0!, L07!S A@ B!B07707B C:MB07!S C:L.M7S A==A7B!S ,A@A 07 S!Q.!7C! PASS!S 7.MB!= :E SP!C0E0!, L07!S A@ @C! !7, :E ,A@A @=A7SLA@!S :7! := M:=! CCA=AC@!=S ,!L!@!S ,.PL0CA@! L07!S C:.7@S CCA=AC@!=S 1 >:=,S 1 := L07!S ABC,!EBC0LKLM7:PQ=S@./>8AM $..se at ommand to %ie& its ontents. ".use %i to orre t an# errors. 4.!n r#5t this (ile using the (ollo&ing ste5sG a. =e%erse the (ile line 3# line'the last line 3e omes the (irst 1the line 3e(ore the last line 3e omes the se ond and so on). 3.Call the (ile Ch6S$E1!n r. *..se the at ommand to %ie& its ontents. 6.Print the (ile. +.,e r#5t the (ile're%erse the en r#5tion ste5s). all it Ch6S$E1'original name). Question #14 1. $. ". 4. *. 6. +. .se the at ommand to he 4 its ontent. .se %i to orre t an# errors. Print the (ile. .se a ommand to sho& the num3er o( &or4ers. .se a ommand to sort the (ile 3ased on id. .se one single ommand to sho& the &or4er &ho is 5aid the heighest hourl# rate. .se one single ommand to sho& the &or4er &ho &or4ed more than an#3od# else. @he ommand should sho& onl# the id o( the &or4er.

>rite a Shell Program to 5er(orm the (ollo&ing o5erations 1) Addition $)Su3tra tion ") Multi5li ation 4),i%ision 'CintG /alue should read (rom the Ke#3oard1 (loating 5oint %alues should gi%en as in5ut)

@he length N 3readth o( a re tangle and radius o( a ir le are in5ut through the 4e#3oard. >rite a 5rogram to al ulate area N 5erimeter o( the re tangle1 and the area N ir um(eren e o( the ir le

You might also like