24
LINUX A  ss  ig  nm  e  nt EX-1 1. Log on a Linux machine Enter your login (user name) and  password at relevant  prom  pts. 2. Enter these commands at the UNI prompt! and try to interpret the output. "s# $uestions and don%t &e a'raid to experiment (as a normal user you cannot do much harm)  echo hello world ello world   passwd  date  hostname  arch  uname a  dmesg * more (you may need to press $ to $uit)  u  ptime  who am i  who  id  last  ' inger  w  top (you may need to press $ to $uit)  echo +,ELL  echo -con!pre-sent!' er-s!ed  man /automatic door/  man ls (you may need to press $ to $uit)  man who (you may need to press $ to $uit)  who can tell me why i got divor ced  lost  clear  cal 2000  cal 132 (do you notice anything unusual4)

linux assignment 12 7.odt

Embed Size (px)

Citation preview

Page 1: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 1/24

LINUX A ss ig nm e n t

EX-1

1. Log on a Linux machine Enter your login (user name) and  password at relevant

 prom pts.

2. Enter these commands at the UNI prompt! and try to interpret the output. "s#

$uestions and don%t &e a'raid to experiment (as a normal user you cannot do much

harm)

⟩  echo hello world

ello world

⟩   passwd

⟩  date

⟩  hostname

⟩  arch

⟩  uname a

⟩  dmesg * more (you may need to press $ to $uit)

⟩  u ptime

⟩  who am i

⟩  who

⟩  id⟩  last

⟩  ' inger 

⟩  w

⟩  top (you may need to press $ to $uit)

⟩  echo +,ELL

⟩  echo -con!pre-sent!' er-s!ed

⟩  man /automatic door/

⟩  man ls (you may need to press $ to $uit)

⟩  man who (you may need to press $ to $uit)

⟩  who can tell me why i got divor ced

⟩  lost

⟩  clear 

⟩  cal 2000

⟩  cal 132 (do you notice anything unusual4)

Page 2: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 2/24

⟩   &c l (type $uit or press 5trld to $uit)

⟩  echo 367 *  &c l

⟩  yes please (you may need to press 5trlc to $uit)

⟩  time sleep 3

⟩  histor y

Page 3: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 3/24

EX-2

8ry the 'ollowing command

se$uence

⟩  cd

⟩   pwd

⟩  ls al

⟩  cd .

⟩   pwd (where did that get you4)

⟩  cd ..

⟩   pwd

⟩  ls al

⟩  cd ..

⟩   pwd

⟩  ls al

⟩  cd ..

⟩   pwd (what happens now)

⟩  cd 9etc

⟩  ls al *more

⟩  cat  passwd

⟩  cd

⟩   pwd

Page 4: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 4/24

Page 5: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 5/24

Page 6: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 6/24

3. 5hange to the home directory o' another user directly! using cd

>username.

?. 5hange &ac# into your home director y.

"nswer cd 9home9te@as

7. Aa#e su&directories called wor# and  play.

Page 7: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 7/24

Answer: mkdir work play

8. =elete the su&directory called wor# .

. 5opy the 'ile 9etc9passwd into your home director y.

Answer: cp –r /etc/passwd /ome/te!as

Page 8: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 8/24

10. Aove it into the su&directory play.

Answer: m" –r /ome/te!as/etc /ome/te!as/play

11. 5hange into su&directory play and create a sym&olic lin# called

terminal that points to your tty device. :hat happens i' you try to ma#e a

Page 9: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 9/24

hard lin# to the tty device4

"nswer

12. :hat is the di''erence  &etween listing the contents o' directory play

with ls l and ls L4

Answer: ls -l sows yo# #ge amo#nts o$ in$ormation like permissions% owners%

si&e% and wen last modi$ied' And ls -L list te $ile or directory te link re$erences

rater tan te link itsel$'

1B. 5reate a 'ile called hello.txt that contains the words /hello world/. 5an

you use /cp/ using /ter minal/  as the source 'ile to achieve the same e' ' ect4"nswer

17. 5opy hello.txt to terminal. :hat ha ppens4

"nswer content o' hello.txt 'ile will &e shown on to the terminal window.

  cp ello't(t /de"/#sr/tty2

15. Imagine you were wor#ing on a system and someone accidentally deleted

Page 10: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 10/24

the ls command (9&in9ls). ow could you get a list o' the 'iles in the

current directory4

Answer: we can #se dir command as s#pposed we want to sow doc#ment

directory ten

dir /ome/te!as/)oc#ments

1?. ow would you create and then delete a 'ile called /+,)ELL/4 8ry it.Answer: cat * +,.ELL0

rm +,.ELL0

1. ow would you create and then delete a 'ile that &egins with the sym&ol C4

8ry it.Answer: cat * +te!as't(t0

rm +te!as't(t0

18. ow would you create and then delete a 'ile that &egins with the sym&ol

4 8ry it.Answer: cat * +-ell't(t0

  rm -$ '/-ell't(t

19. :hat is the output o' the command echo -con!pre-sent!'er-s!ed4

 Now! 'rom your home directory! copy 9etc9passwd and 9etc9 grou p into your

home directory in one command given that you can only type 9etc once.

Answer: cp /etc/passwd%gro#p3 /ome/te!as

20. ,till in your home dircectory! copy the entire directory play to a directory

called wor#!  preserving the sym&olic lin#.

cp -r$ /ome/te!as/play /ome/te!as/work

21. =elete the wor# directory and its contents with one command. "ccept no

complaints or $ueries.

Answer: rm –r /ome/te!as/work 

22. 5hange into a directory that does not &elong to you and try to delete all the

'iles (avoid 9  proc or 9dev! @ust in caseD)

2B. Experiment with the options on the ls command. :hat do the d! i! and F

options do4

Page 11: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 11/24

Page 12: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 12/24

Page 13: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 13/24

2. :hat would happen i' the system administrator created a sh 'ile in this

way4

:hy is it sometimes necessary 'or a system administrator to use this

' eature using  programs other than sh4Aain user

Answer: 6y tis $eat#res system administrator gi"es ermission #se

to teir sell and so tat oter #ser can operate tat sell and

write script tere wito#t taking permission'

B. =elete sh 'rom your home directory (or at least to do a chmod s sh).

Page 14: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 14/24

,creenhsot B

7. Aodi'y the  permissions on your home directory to ma#e it completely private.

5hec# that your  partner can%t access your directory. Now put the

 permissions &ac# to how they were.

Answer: cmod 788 /ome/te!as

ten log in to anote #ser % k ere'

9is #ser cant access ome directory o$ te main #ser'

7!7<2

3. 8ype umas# 000 and then create a 'ile called world.txt containing the

words /hello world/. Loo# at the  permissions on the 'ile. :hat%s

happened4 Now ty pe umas# 022 and create a 'ile called world2.txt.

:hen might this 'eature &e use' ul4

,creen shot

Page 15: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 15/24

"nswer when main use want to change permission to all 'ile created under

that command.

?. 5reate a 'ile called /hello.txt/ in your home directory using the command

cat u

Jhello.txt. "s# your  partner to change into your home directory and runtail ' hello.txt.  Now type several lines into hello.txt. :hat appears on

your  partner%s screen4

It canges wit relati"e to canges in main #ser'so% as main #ser

types somting at e same time partner #ser sows tat'

. Use 'ind to display the names o' all 'iles in the 9home su&directory tree.

5an you do this without displaying errors 'or 'iles you can%t read4

;es

Using $ind <'t(t

8. Use 'ind to display the names o' all 'iles in the system that are &igger than

1AK.$ind -si&e 1=>?

9. Use 'ind and 'ile to display all 'iles in the 9home su&directory tree! as

well as a guess at what sort o' a 'ile they are. =o this in two di''erentways.

10. Use grep to isolate the line in 9etc9passwd that contains your login details.

"nswer

11. Use 'ind and grep and sort to display a sorted list o' all 'iles in the

Page 16: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 16/24

9home su&directory tree that contain the word hello somewhere

inside them.

"nswer

12. Use locate to 'ind all 'ilenames that contain the word emacs. 5an you

com &ine this with grep to avoid displaying all 'ilenames containing the

word li &4

"nswer

13. 5reate a 'ile containing some lines that you thin# would match the

regular expression (LM0N-1!3MaO"O N6+)*none and some lines that

you thin# would not match. Use egrep to see i' your intuition is

correct.

17. "rchive the contents o' your home directory (including any

su&directories) using tar and cpio. 5ompress the tar archive with compress!

and the cpio archive with gOip. Now extract their contents.

Answer: tar -c"w$ $ile'tar /ome

Page 17: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 17/24

13. Pn Linux systems! the 'ile 9dev9urandom is a constantly generated

random stream o' characters. 5an you use this 'ile with od to  printout a

random decimal num &er4

16. 8ype mount (with no  parameters) and try to interpret the out put.

"nswer

Page 18: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 18/24

"rchive the contents o' your home directory using tar. 5ompress the tar 'ile with gOip.  Now

uncompress and unarchive the .tar.gO 'ile using cat! tar and gOip on one command line.

1. Use 'ind to compile a list o' all directories in the system! redirecting the out putso  that the list o' directories ends up in a 'ile called directories.txt and the list o'error messages ends up in a 'ile called errors.txt.

2. 8ry the command sleep 3. :hat does this command do4

"nswer 8his command delays o' 3 seconds to the terminal.

B. un the command in the  &ac#ground using Q.Answer: sleep 1@

7. un sleep 13 in the 'oreground! suspend it with 5trlO and then put it into the

 &ac#ground with &g. 8ype @o&s. 8ype ps. Kring the @o& &ac# into the ' oreground

with ' g."nswer

3. un sleep 13 in the  &ac#ground using Q! and then use #ill to terminate the

 process &y its @o& num&er. epeat! except this time #ill the process &y s peci' ying

its RI=.

"nswer

Page 19: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 19/24

?. un sleep 13 in the  &ac#ground using Q! and then use #ill to suspend the

 process. Use &g to continue running the  process.

"nswer

. ,tartup a num&er o' sleep ?0 processes in the  &ac#ground! and terminate them

all at the same time using the p#ill command.

"nswer

8. Use ps! w and top to show all processes that are executing.

Page 20: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 20/24

Page 21: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 21/24

10. 5om&ine ps 'ae with grep to show all processes that you are executing! withthe exception o' the ps 'ae and grep commands.

Answer: ps -$ae B te!as

11. ,tart a sleep B00 process running in the  &ac#ground. Log o'' the server! and log

 &ac# in again. List all the processes that you are running. :hat happened to your

sleep process4 Now repeat! except this time start &y running nohup sleep B00.

12. Aultiple @o&s can &e issued 'rom the same command line using the operators ;!

QQ and **. 8ry com&ining the commands cat nonexistent and echo hello using

each o' these operators. everse the order o' the commands and try again. :hat

are the rules a&out when the commands will &e executed413. :hat does the xargs command do4 5an you com&ine it with 'ind and grep to

'ind yet another way o' searching all 'iles in the 9home su&directory tree 'or the

word hello4

Answer: 6#ild and e(ec#te command lines $rom standard inp#t'  

$ind /ome B (args grep ello

Page 22: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 22/24

14. :hat does the cut command do4 5an you use it together with w to  produce a

list o' login names and 5RU times corresponding to each active process4 5an you

now (all on the same command line) use sort and head or tail to 'ind the user

whose process is using the most 5RU4

Page 23: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 23/24

1. Edit your copy o' the document using vi.

2. So to the end o' the document and type in the 'ollowing  paragra ph

Toined the li&rary. Sot 5are o' the ,#in! Prigin o' the ,pecies! and a &oo# &y a

woman my mother is always going on a&out. It is called Rride and Rre@udice!  &y

a woman called Tane "usten. I could tell the li&rarian was impressed. Rerha psshe is an intellectual li#e me. ,he didnt loo# at my spot! so perhaps it is getting

smaller .

3. 5orrect the three spelling errors in the 'irst three lines o' the 'irst  paragraph (oneerror per line) and remove the extra /Seogra phy/  in the Brd line o' the ' irst

 paragra ph.

4. "dd the words /" &out timeD/  to the end o' the second paragraph.

=o with shi't 6 <<<<<<<< to go to the end o' pargraph

Page 24: linux assignment 12 7.odt

8/14/2019 linux assignment 12 7.odt

http://slidepdf.com/reader/full/linux-assignment-12-7odt 24/24

5. =elete the sentence /8ime 'lies li#e an arrow &ut ' r u i t 'lies li#e a &anana/ 

and re'orm the  paragra ph.

"nswer &y putting cursor on %8% which is @ust a'ter the some space and then

us command das in command mode.

6. eplace all occurrences o' /is/ with /was/.

. ,wap the two  paragra phs.

8. ,ave the 'ile and $uit.:wC