You are on page 1of 24

LINUX Assignment EX-1

1. Log on a Linux machine Enter your login (user name) and password at relevant prompts. 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) uptime 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 divorced lost clear cal 2000 cal 1 1232 (do you notice anything unusual4)

&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 history

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

2. 5ontinue to explore the 'ilesystem tree using cd! ls! pwd and cat. Loo# in
9&in! 9usr9&in! 9s&in! 9tmp and 9&oot. :hat do you see4 "nswer( see in assign 1 3. Explore 9dev. 5an you identi'y what devices are availa&le4 :hich are character oriented and which are &loc#oriented4 5an you identi'y your tty (terminal) device (typing who am i might help); who is the owner o' your tty (use ls l)4 "nswer( cd 9 ls 9dev who ls <l

7. Explore 9proc. =isplay the contents o' the 'iles interrupts! devices!
cpuin'o! memin'o and uptime using cat. 5an you see why we say 9proc is a pseudo 'ilesystem which allows access to #ernel data structures4 "nswer(

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


>username.

?. 5hange &ac# into your home directory. "nswer( cd 9home9te@as

7.

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

Answer: 8.

mkdir work play

=elete the su&directory called wor#.

1. 5opy the 'ile 9etc9passwd into your home directory. Answer: cp r /etc/passwd / ome/te!as

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

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 s ows yo# #ge amo#nts o$ in$ormation like permissions% owners% si&e% and w en last modi$ied' And ls -L list t e $ile or directory t e link re$erences rat er t an t e link itsel$'

1B. 5reate a 'ile called hello.txt that contains the words /hello world/. 5an
you use /cp/ using /terminal/ as the source 'ile to achieve the same e''ect4 "nswer(

17. 5opy hello.txt to terminal. :hat happens4


"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

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 s ow doc#ment directory t en 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

12. )ow would you create and then delete a 'ile that &egins with the sym&ol C4
cat * +1te!as't(t0 rm +1te!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!ed.4 Now! 'rom your home directory! copy 9etc9passwd and 9etc9group into your home directory in one command given that you can only type 9etc once. Answer: cp /etc/2passwd%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 9proc or 9dev! @ust in caseD) 8ry it. Answer:

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

EX-4
=escri&e three di''erent ways o' setting the permissions on a 'ile or directory to rrr. 5reate a 'ile and see i' this wor#s. "nswer( total B ways 15 mode chmod u6r g6r o6r 'ile.txt 25 re$erence

chmod Gre'erence H old'ile.txt new'ile.txt


45 octal

chmod 222 new'ile.txt or chmod 222 9home 1.


8eam up with a partner. 5opy 9&in9sh to your home directory. 8ype /chmod 6s sh/. 5hec# the permissions on sh in the directory listing. Now as# your partner to change into your home directory and run the program .9sh. "s# them to run the id command. :hat%s happened4 Iour partner can type exit to return to their shell. "nswer( (1) screen shot( 5opy 9&in9sh to your home directory. 8ype /chmod 6s sh/. 5hec# the permissions on sh in the directory listing and made permission to accessi&le to all users. ,ee &elow!

(2) screen shot ( entering into another user and do changes in home directory o' main user and run the program .9sh. "nd then id. "nd then exit. Now go &ac# to main user.

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 sh4 Aain user Answer: 6y t is $eat#res system administrator gi"es ermission #se to t eir s ell and so t at ot er #ser can operate t at s ell and write script t ere wit o#t taking permission'

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

,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: c mod 788 / ome/te!as t en log in to anot e #ser % k ere' 9 is #ser can:t access ome directory o$ t e 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 type umas# 022 and create a 'ile called world2.txt. :hen might this 'eature &e use'ul4 ,creen shot

"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 run tail ' hello.txt. Now type several lines into hello.txt. :hat appears on your partner%s screen4 It c anges wit relati"e to c anges in main #ser'so% as main #ser types somt ing at e same time partner #ser s ows t at'

2. 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''erent ways.

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

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( (LM01N-1!3.MaO"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

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 output. "nswer(

"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 output
so 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. Eun the command in the &ac#ground using Q. Answer: sleep 1@ A

7. Eun 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. Eun sleep 13 in the &ac#ground using Q! and then use #ill to terminate the
process &y its @o& num&er. Eepeat! except this time #ill the process &y speci'ying its RI=. "nswer(

?. Eun sleep 13 in the &ac#ground using Q! and then use #ill to suspend the
process. Use &g to continue running the process. "nswer( 2. ,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.

9. Use ps ae) to display the process hierarchy. Loo# 'or the init process. ,ee i' you can identi'y important system daemons. 5an you also identi'y your shell and its su&processes4

10. 5om&ine ps 'ae with grep to show all processes that you are executing! with the 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. Eeverse the order o' the commands and try again. :hat are the rules a&out when the commands will &e executed4 13. :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

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

1.

Edit your copy o' the document using vi.

2. So to the end o' the document and type in the 'ollowing paragraph(
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. Rerhaps she is an intellectual li#e me. ,he didnUt 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 (one error per line) and remove the extra /Seography/ in the Brd line o' the 'irst paragraph.

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

5. =elete the sentence /8ime 'lies li#e an arrow &ut ' r u i t 'lies li#e a &anana/ and re'orm the paragraph. "nswer( &y putting cursor on %8% which is @ust a'ter the some space and then us command das in command mode. 6. Eeplace all occurrences o' /is/ with /was/.

2. ,wap the two paragraphs. 8. ,ave the 'ile and $uit. :wC

You might also like