Fourth Sem Solved Lab Manual

download Fourth Sem Solved Lab Manual

of 48

Transcript of Fourth Sem Solved Lab Manual

  • 8/10/2019 Fourth Sem Solved Lab Manual

    1/48

  • 8/10/2019 Fourth Sem Solved Lab Manual

    2/48

    www.ignousolvedassignments.com

    SECTION-1

    MCS-041: I"#$o%&c#io" #o '"i(

    SESSION 1:

    1) E(plo$e All 'NI Co a"%/ gi e" i" # i/ a"&al.

    2

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    3/48

    www.ignousolvedassignments.com

    File/ l/ --- lists your files.

    l/ -l --- lists your files in 'long format', which contains lots of usefulinformation, e.g. the exact size of the file, who owns the file and whohas the right to look at it, and when it was last modified.l/ -a --- lists all files, including the ones whose filenames begin in adot, which you do not always want to see.There are many more options, for example to list files by size, bydate, recursively etc.

    o$e ile"a e --- shows the first part of a file, just as much as will fiton one screen. ust hit the space bar to see more or to !uit. "oucan use pa##e$" to search for a pattern.

    e ac/ ile"a e --- is an editor that lets you create and edit a file.ile"a e1 ile"a e2 --- moves a file #i.e. gives it a different name, or

    moves it into a different directory #see below$. cp ile"a e1 ile"a e2 --- copies a file $ ile"a e --- removes a file. %t is wise to use the option rm -i, which

    will ask you for confirmation before actually deleting anything. "oucan make this your default by making an alias in your .cshrc file.

    %i ile"a e1 ile"a e2 --- compares files, and shows where theydiffer

    5c ile"a e --- tells you how many lines, words, and charactersthere are in a file

    c o% op#io"/ ile"a e --- lets you change the read, write, andexecute permissions on your files. The default is that only you canlook at them and change them, but you may sometimes want tochange these permissions. &or example, c o% o6$ ile"a e willmake the file readable for everyone, and c o% o-$ ile"a e willmake it unreadable for others again. ote that for someone to be ableto actually look at the file the directories it is in need to be at leastexecutable.

    &ile (ompressiono g7ip ile"a e --- compresses files, so that they take up much

    less space. )sually text files compress to about half theiroriginal size, but it depends very much on the size of the fileand the nature of the contents. There are other tools for thispurpose, too #e.g. co p$e// $, but gzip usually gives the

    3

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    4/48

    www.ignousolvedassignments.com

    highest compression rate. *zip produces files with the ending'.gz' appended to the original filename.

    o g&"7ip filename --- uncompresses files compressed by gzip.o g7ca# filename --- lets you look at a gzipped file without

    actually having to gunzip it #same as g&"7ip -c $. "ou can evenprint it directly, using g7ca# filename 8 lp$

    printingo lp$ filename --- print. )se the -+ option to specify the printer

    name if you want to use a printer other than your default printer.

    &or example, if you want to print double-sided, use 'lpr -+valkyr-d', or if you're at ( %, you may want to use 'lpr -+cord /-d'.ee 'help printers' for more information about printers and their

    locations.o lp --- check out the printer !ueue, e.g. to get the number

    needed for removal, or to see how many other files will beprinted before yours will come out

    o lp$ jobnumber --- remove something from the printer !ueue.

    "ou can find the job number by using lp!. Theoretically you alsohave to specify a printer name, but this isn't necessary as longas you use your default printer in the department.

    o ge"/c$ip# --- converts plain text files into postscript for printing,and gives you some options for formatting. (onsider making analias like alia/ ecop 9ge"/c$ip# -2 -$ ;< 8 lp$ - -P al=>$9 toprint two pages on one piece of paper.

    o dvips filename --- print .dvi files #i.e. files produced by aTe0$.

    "ou can use dviselect to print only selected pages.1irectories, like folders on a 2acintosh, are used to group files together in ahierarchical structure.

    =%i$ dirname --- make a new directory c% dirname --- change directory. "ou basically 'go' to another

    directory, and you will see the files in that directory when you do 'ls'."ou always start out in your 'home directory', and you can get backthere by typing 'cd' without arguments. 'cd ..' will get you one level upfrom your current position. "ou don't have to walk along step by step -

    4

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    5/48

    www.ignousolvedassignments.com

    you can make big leaps or avoid walking around by specifyingpathnames.

    p5% --- tells you where you currently are.

    Fi"%i"g # i"g/ --- find files anywhere on the system. This can be extremely useful

    if you've forgotten in which directory you put a file, but do rememberthe name. %n fact, if you use -p you don't even need the full name,

    just the beginning. This can also be useful for finding other things onthe system, e.g. documentation.

    g$ep string filename(s) --- looks for the string in the files. This canbe useful a lot of purposes, e.g. finding the right file among many,

    figuring out which is the right version of something, and even doingserious corpus work. grep comes in several varieties # g$ep , eg$ep ,and g$ep$ and has a lot of very flexible options. (heck out the manpages if this sounds good to you.

    5$i#e username --- lets you exchange one-line messages withanother user

    el --- lets you send e-mail messages to people around the world

    #and, of course, read them$. %t's not the only mailer you can use, butthe one we recommend. ee the elm page, and find out about thedepartmental mailing lists #which you can also find in3user3linguistics3helpfile$.

    A,o >o&$ !elec#$o"ic) /el 5 oa i --- returns your username. ounds useless, but isn't. "ou

    may need to find out who it is who forgot to log out somewhere, andmake sure 4you4 have logged out.

    i"ge$ 5 .plan filesof course you can finger yourself, too. That can be useful e.g. as a!uick check whether you got new mail. Try to create a useful .plan filesoon. ook at other people's .plan files for ideas. The file needs to bereadable for everyone in order to be visible through 'finger'. 1o'chmod a6r .plan' if necessary. "ou should realize that this informationis accessible from anywhere in the world, not just to other people onturing.

    5

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    6/48

  • 8/10/2019 Fourth Sem Solved Lab Manual

    7/48

    www.ignousolvedassignments.com

    To create a directory, use the mkdir command. &or example, to create adirectory named tudent within the current working directory8

    ? =%i$ S#&%e"#

    3) C$ea#e a S&,%i$ec#o$> i" # e %i$ec#o$> c$ea#e%."ou may create a subdirectory within any directory where you have writepermission. &or example, to create a directorycalled3 tudent3 ubdirectory , assuming that directory 3 tudent alreadyexist8

    ? =%i$ S#&%e"# S&,%i$ec#o$>1

    4) C a"ge >o&$ c&$$e"# %i$ec#o$> #o # e /&,%i$ec#o$>.To change the current working directory to the subdirectory, use the the cdcommand #this stands for :change directory:$. ;ssuming that the currentworking 1irectory is tudent, to change to the subdirectory ubdirectory 8

    ? c% S&,%i$ec#o$>1

    *) +i/pla> Cale"%e$ o$ # e c&$$e"# Mo"# .

    To display (alender for the current month use the (; command.

    ? CAL

    @) e# a %i$ec#o$> li/#i"g o # e pa$e"# %i$ec#o$>.

    To get the 1irectory listing of the parent directory, use the commandls - list contents of directory.*oto the parent directory and use ls command.

    ? l/

    ) o5 a"> &/e$/ 5e$e logge% o"#o >o&$ />/#e .

    7

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    8/48

    www.ignousolvedassignments.com

    To see all the other users that are currently connected to system simply usethe following command who. This will simply print out a list of all the usersconnected #just their usernames however, not their real names$, theterminal they're connected to, when they connected and where theyconnected from.

    ? 5 oload average?which is how many processes are contending for the (+). This is shownas three numbers8 the first is for minute ago, the second / minutes ago,the third /. ;ll you really need to know is that small numbers are goodhere.

    ;fter this w will show a header that says what the columns are for,username, tty, when that user logged in, how long they've been idle, the

    (+) and the +(+) and finally what the process is. (+) is the total (+)time used by all the processes attached to that terminal, the +(+) time is

    just for the current process running in the foreground. @uite often these twonumbers will be the same. Anowing exactly what these numbers mean orhow to use them isn't really essential knowledge, but can prove useful orinteresting.

    D) +i/pla> >o&$ "a e i" o$ o a ,a""e$.The ,a""e$ (ommand displays a large ; (%% art version of input text. %t iscommonly included in ) %0 and )nix-like operating systems. There are twocommon varieties8 one, which prints text horizontally for display to aterminal, and another which prints text in much larger letters for output to aline printer.

    ? ,a""e$ S#&%e"#? ,a""e$ 5D0 a

    ). +i/pla> # e "a e o %e ice "a e o" >o&$ #e$ i"al.To display the device name of the terminal, use the tty command8

    8

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    9/48

    www.ignousolvedassignments.com

    The tty utility writes to the standard output the name of the terminal that isopen as standard input.

    ? ##>

    10). Mo e #o $oo# %i$ec#o$>.To move to root directory use (1 command.? c%

    SESSION 2:

    11). C a"ge >o&$ %i$ec#o$> #o # e %i$ec#o$> e(e$ci/e/. C$ea#e a ilecalle% e(a ple1 &/i"g # e ca# co a"% co"#ai"i"g # e ollo5i"g #e(#:

    Bater, water everywhere ;nd all the boards did shrinkCBater, water everywhere,

    o drop to drink.

    ;ssuming that there is a directory called exercises,To change to directory exercises from the current working directory, use the(1 command8

    ? c% e(e$ci/e/

    To c$ea#e a ile i" # e %i$ec#o$> e(e$ci/e/:

    ? ca# e(a ple1. a#e$G 5a#e$ e e$>5 e$e

    A"% all # e ,oa$%/ %i% / $i"=Ha#e$G 5a#e$ e e$>5 e$eG

    No %$op #o %$i"=.+

    Be careful not to type ^D when you have the shell prompt, because thismight log you out.

    9

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    10/48

    www.ignousolvedassignments.com

    12) '/e MAN co a"% #o o,#ai" &$# e$ i" o$ a#io" o" # e i"ge$co a"%.

    The man command displays information from the reference manuals. %tdisplays complete manual pages that you select by name , or one-linesummaries selected either by keyword #-k$, or by the name of anassociated file #-f$. %f no manual page is located, man prints an errormessage.

    ? a" co a"% "a e

    ? a" i"ge$

    Fi"ge$ - %i/pla> i" o$ a#io" a,o local a"% $e o#e &/e$/

    13) Li/# all # e p$oce//e/ # a# a$e p$e/e"#l> $&""i"g.

    To find out information about the processes running on the system use thep/ command.

    ? p/ ;nd you will see a list that probably just includes your shell #tcsh$. Bhilethis is fairly useful in and of itself you'll often find that you're logged in to twoor three TT"s at once doing various things, and so you'll need to find outmore than just the processes running on that login.To see a list of all your running processes use8

    ? p/ -' J'SEK

    This will show you information about your processes with much moreinformation including the )%1, +%1, ++%1, TT" and the command line andall its arguments used to start the command.

    %f you wanted to know this about another user you could simply use8

    ? p/ - & &/e$"a e

    where >username? is the name of a user whose processes you want to see.

    10

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    11/48

    www.ignousolvedassignments.com

    astly if you want ps to show you information about all the processesrunning on the system then you need to -e flag8

    ? p/ -e

    2ost of time this isn't really needed, but sometimes you will want to be ableto find out information like this. %t should also be noted that the -e flag canbe combined with the -f flag, to show all the processes on the machine andfull information about them.

    14) Li/# #e(# ile/ i" >o&$ c&$$e"# %i$ec#o$>.

    To find and list text files in the all the directories, use the &% 1 command8

    ? i"% o e -"a e

  • 8/10/2019 Fourth Sem Solved Lab Manual

    12/48

    www.ignousolvedassignments.com

    as being present even though the file has just been deleted. )nlike find,locate cannot track down files on the basis of their permissions, size and soon.

    ;nother option to find and list text files in the current directory is8

    ? l/ p 8 g$ep ile < 8 g$ep #e(#

    ? l/ -l o a"> #e(# ile.

    To copy any text file to another text file use the cp command8

    cp file1 file2 is the command which makes a copy of ile1 in the currentworking directory and calls it ile2.

    &irst (1 to your current directory8

    ? c% S#&%e"#

    Then, copy the text file,

    ? cp &"i( e(a ple/ cop>.#(#.

    # ote8 1on't forget the dot # .$ at the end. Hemember, in ) %0, the dotmeans the current directory.$

    G G

    ? cp ile1 ile2.

    1@) Ke"a e o"e o >o&$ #e(# ile/ i" # e c&$$e"# %i$ec#o$>.

    To rename file in current directory use 2I move command8

    ? ile.#(# ile"a e.#(# &"=.#(# "e5 ile

    1 ) +ele#e a" &""ee%e% cop> o a ile.

    To delete a file use the rm remove command8

    ? $ ile.#(#

    12

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    13/48

    www.ignousolvedassignments.com

    1D) P$i"# o a"> ile o" pape$.

    To print a file in ) %0 uses the lpr command8

    ? lp$ ile"a e.#(#

    lpr lpr !ueues the specified file for printing. %f no file is specified, it readsfrom the standard input. Fptions that may be specified include printer,number of copies, processing and post-processing option.

    lpq The lpq program lists the job in the print !ueue.

    lprm The command lprm may be used to remove a print job from !ueue.The command options include the printer and job-id or user-name. %fthe user-name is specified all jobs for that user will be de!ueued.

    lpc The command lpc is normally used interactively. %t allows the super-user to start3stop the daemons, enable3disable !ueuing or printing

    jobs, and monitor the status of a printer. The subcommand help printsa short list of the commands that may be entered.

    1 ) Se"% e//age #o a"o# e$ &/e$ o" >o&$ 'NI />/#e G a"% ge# # e#o $epl>.

    The mail command enables the user to send and receive electronic mailmessages to and from users on both the )nix system and remote users.To send a message to a user on your system, type8

    ? ail username

    The cursor will move to the next line, and you will get a ubject8 prompt."ou can now type in the subject of your message, and then pressJHGT)H E. The cursor will go to the start of the next line and there will beno prompt. "ou now type in the text of your message. Terminate each linewith JHGT)H E. Bhen you have finished the text of the message, type anend-of-file character #usually K1$, or a full-stop character.There are several commands you can type while entering mail8QCTKL R will cancel the message, and leave the text in a file named

    dead.letter.e invokes a text editor to edit your message.

    13

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    14/48

    www.ignousolvedassignments.com

    invokes a screen editor to edit your message. reads the contents of the message you have just read, into your

    message text.$ file reads contents of file into your message text.

    20) C$ea#e a / all #e(# ile a"% /e"% i# #o a"o# e$ &/e$.

    To create a text file, use the cat command8 ? ca# S#&%e"#

    To send this file to another user user 8? ail &/e$1 Q S#&%e"#

    )se the re-direction to output stream operation.SESSION 3:

    21) e" >o& $ecei e a e//ageG /a e i# #o a ile o# e$ # a" >o&$ail,o(.

    ) %0 uses two mailboxes to hold mail messages/>/#e ail,o( ! &/$ /pool ail )&/e$ ail ,o( !.... ... ,o()

    2ail arrives in the system mailbox, and is saved in your user mail box afteryou have read it. The user mail box is normally located in their L

  • 8/10/2019 Fourth Sem Solved Lab Manual

    15/48

    www.ignousolvedassignments.com

    ending mail to users on other computer systems is simple using mail.imply type the full address of the remote user.

    ? ail S#&%e"# ig"o&.ac.i"

    23) T$> #o o e #o # e o e %i$ec#o$> o /o eo"e el/e i" >o&$ g$o&p.T e$e a$e /e e$al 5a>/ #o %o # i/G a"% >o& a> i"% # a# >o& a$e "o#pe$ i##e% #o e"#e$ ce$#ai" %i$ec#o$ie/. See 5 a# ile/ # e> a eG a"%5 a# # e ile pe$ i//io"/ a$e.

    To move to the home directory of someone else in the group8

    ? c% &/e$1

    To list the files in the directory and their permissions8

    ? l/ l%g

    24) T$> #o cop> a ile $o a"o# e$ &/e$9/ %i$ec#o$> #o >o&$ o5".

    7efore trying to copy the file, see the permissions that have been set for afile, use the ls command with -l option

    ? l/ l

    %f the Mr permission is set in the groupNs option of the permission set, andthen the file can be copied.

    ;ssuming Mr to be set,To copy a file from another users directory to home directory of currentuser8

    &irst locate the userNs directory.? i"ge$ %i$ec#o$>1

    Be learn that the user directory is 3user 3directories3directory

    To copy file named file from the user directory, do8 ? cp &/e$1 %i$ec#o$ie/ %i$ec#o$>1 ilecop>1

    15

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/mailto:[email protected]:[email protected]://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    16/48

  • 8/10/2019 Fourth Sem Solved Lab Manual

    17/48

    www.ignousolvedassignments.com

    The first character shows the file type. %t is -#dash$ for a standard file and d for a directory.The next 9 characters are actually P sets of Pcharacters each. These P sets show thepermissions for the owner, the group and others.Bithin each set, permissions are alwaysdescribed in the same order8 read # $ $, write #5 $and execute # ( $. %f the relevant letter #r, w or x$appears, permission exists. %f a - #dash$ appearsin its place, that kind of permission is denied.

    et's look at the permissions for another file8

    %n this example, the owner may read the file,write to it #change it$ and execute the file.2embers of the group may read and executethe file, but not write to it. Fther users may onlyexecute the file, not read it or write to it.

    Gxecute access permits the execution of binary files which containexecutable programs. 7oth read and execute access are re!uired toexecute a shell script.

    +e a&l# pe$ i//io"/ o$ "e5 ile/ a"% %i$ec#o$ie/1efault permissions are automatically set for files and directories as youcreate them. The default permission for new files is -rw------- and that fornew directories is drwx------.

    C a"gi"g ile pe$ i//io"/The command chmod #short for c ange o% e$ is used to changepermissions for a file.c o% g65 ile1

    17

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    18/48

    www.ignousolvedassignments.com

    This may be understood as follows8Cla// Ac#io" Pe$ i//io"u user

    #owner$6 add permission r read

    g *roup - removepermission

    w write

    o Fthers Q set permission x executea all

    where class, action and permission can be chosen from the table of optionsat the right above.

    2ore than one class and more than one type of permission can be set atthe same time using chmod. &or example,c o% &6(GoV$5 ile1adds the execute permission for the owner #u$ and sets the permission forothers to read and write explicitly #no matter what permissions others hadbefore$.%f you do not specify a class, the new permission is applied to all threeclasses. &or example,

    c o% 6( ile

    adds execute permission for the owner, group and others.To change the permission of all files in a directory, use the wildcard symbol:4:.&or example, the following command would add read permission forothers to all files in the current directory8c o% o6$ # e $e e$e"ce a#e$ial a"% lea e &/# # e #e(#iel%.

    (ut command is typically used to extract a certain range of characters from

    a line, usually from a file.S>"#a(: ? c [-,\ [-c\ [- li/#\ [-"\ [-% %eli \ [-/\ [ ile\-,

    7ytesC a list following -b specifies a range of bytes which will be returned,e.g. &lags which may be used include

    cut -b - would return the first bytes of a line. 7 %f used inconjunction with -n, no multi-byte characters will be split. 7. -b willonly work on input lines of less than ODP bytes

    -c(haractersC a list following -c specifies a range of characters whichwill be returned, e.g. cut -c - would return the first characters ofa line-

    pecifies a field list, separated by a delimiterli/#

    ; comma separated or blank separated list of integer denoted fields,

    incrementally ordered. The - indicator may be supplied as shorthand

    25

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://en.wikipedia.org/wiki/Bytehttp://en.wikipedia.org/w/index.php?title=Multi-byte&action=edithttp://en.wikipedia.org/wiki/Bytehttp://en.wikipedia.org/w/index.php?title=Multi-byte&action=edithttp://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    26/48

    www.ignousolvedassignments.com

    to allow inclusion of ranges of fields e.g. !" for ranges SM or #! asshorthand for field / to the end, etc.-")sed in combination with -b suppresses splits of multi-byte characters-%1elimiterC the character immediately following the -d option is the fielddelimiter for use in conjunction with the -f optionC the default delimiteris tab . pace and other characters with special meanings within thecontext of the shell in use must be en!uoted or escaped asnecessary.-/

    )sed to bypass lines, which contain no field delimiters when -f isspecified, unless otherwise indicated.ile

    The file used #and accompanying path if necessary$ to process asinput. %f no file is specified then standard input will be used

    33) '/e #$ #o /#$ip a5a> a"> #ag/ # a# a$e ac#&all> i" # e #e(#!e.g.G

    a##ac e% #o # e 5o$%/)G /o # a# >o& a$e le # 5i# &/# # e 5o$%/.The tr command #translate characters$ is one of the true )nix filters. %tcopies its standard input to its standard output, while replacing the firstcharacter specified on the command line with the second character specified.

    etNs consider the text file to be example .txt,J ec o QB Q B # i/ i/ # e #ag o$ ,ol% #e(#Ca# e(a ple1.#(# 8 #$ Qa-7 a-7

    Op: B B # i/ i/ # e #ag o$ ,ol% #e(#

    34) Se# a ile #o ,e $ea%-o"l> 5i# # e c o% ! $o c a"ge o%e)co a"%. I"#e$p$e# # e ile pe$ i//io"/ %i/pla>e% ,> # e l/ lco a"%.(onsider file to be present,To set the file to be read-only to all,

    ? c o% a6$ ile1

    To see the permissions of the file, use the ls Ml command. To see thepermissions of the entire directory use the ls Mld command.

    26

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    27/48

    www.ignousolvedassignments.com

    3*) +ele#e o"e o$ o$e %i$ec#o$ie/ 5i# # e $ %i$ co a"%. See 5 a#appe"/ i # e %i$ec#o$> i/ "o# e p#>. E(pe$i e"# !ca$e &ll>;;) 5i# # e

    $ $ co a"% #o %ele#e # e %i$ec#o$> a"% i#/ co"#e"#.&irst letNs go to home directory of user tudent8 cd V tudent

    et us create a directory 3 tudent31irectoryD? =%i$ S#&%e"# +i$ec#o$>2

    %f the 1irectory D is not empty, then we get an error message8+i$ec#o$>2: +i$ec#o$> "o# e p#> .

    To remove the directory and all its files and contents8?$ $ +i$ec#o$>2

    3@) E(pe$i e"# 5i# # e $e-%i$ec#i"g co a"% op !e.g.G l/ l ile1). T$> X Y i"/#ea% o X Y 5i# a" e(i/#i"g #e(# ile a/ # e op.

    To :redirect: output -- to take what the system would have displayed on thescreen and put it in a file instead.Fn issuing the ls Ml command, we can redirect the output to file , as8

    ? l/ l ile1Bhen you redirect output to a file that already exists, any previous contentsare deleted before the command is completed. To prevent the accidentaloverwriting of files, first issue the command8

    /e# "oclo,,e$ then use = ls Ml E file%f file already exists then we will get an error8&ile 8 file exists.

  • 8/10/2019 Fourth Sem Solved Lab Manual

    28/48

    www.ignousolvedassignments.com

    %a#e ; File1

    3 ) See 5 e# e$ &ppe$-ca/e e$/io"/ o a"> o # e/e co a"%/ 5ill5o$= a/ 5ell a/ # e lo5e$-ca/e e$/io"/.

    'NI i/

  • 8/10/2019 Fourth Sem Solved Lab Manual

    29/48

    www.ignousolvedassignments.com

    3 ) Pipe # e op o # e 5 o co a"% #o # e /o$# co a"% .

    ) %0 /o$# command to sort data either alphabetically or numerically # -" option$ in ascending or descending order # -$ -- sort in reverse option$

    By default sort sorts the file in ascending order using the entire lineas a sorting key .The /o$# command can be used in pipes or have its output redirected asdesired.

    To pipe the output of the 5 o command to the input of the /o$# command8

    ?5 o 8 /o$# ile1

    40) Sea$c o$ >o&$ logi" "a e i" 5 o ile ! ile1) &/i"g # e g$epco a"%.

    The g$ep command search for the pattern specified by the +atternparameter and writes each matching line to standard output. The g$ep command displays the name of the file containing the matched line if youspecify more than one name in the %ile parameter. (haracters with specialmeaning to the shell #L, 4, X, ^, K, #,$, _$ must be in !uotation marks when theyappear in the &attern parameter.

    To find a word within some text, display all lines matching :pattern :,

    g$ep pattern1 ile

    ? 5 o 8 g$ep S#&%e"#

    SESSION: *

    41) Co pa$e #5o #e(# ile/ 5i# # e %i co a"%.

    29

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    30/48

    www.ignousolvedassignments.com

    The diff command is used to display two files and prints the lines that aredifferent. %t prints a message that uses ed -like notation # a for append, c forchange, and d for delete$ to describe how a set of lines has changed. Thisis followed by the lines themselves. The J character precedes lines fromthe first file and E precedes lines from the second file. The diff commanddisplays the only line that differs between the two files.

    et's create an example to explain the output produced by diff . ook at thecontents of three sample files8

    #e/#1 #e/#2 #e/#3apples apples oranges

    oranges oranges walnutswalnuts grapes chestnuts

    Bhen you run diff on test1 and test2 , the following output is produced8

    L %i #e/#1 #e/#23c3Q 5al"/--

    g$ape/

    42) Co&"# # e "& ,e$ o li"e/ 5o$%/ a"% c a$ac#e$/ i" a ile 5i# a 5cco a"%.

    The :wc: command stands for :word count:. %t counts the number ofcharacters, words, and lines that are contained in a text stream.

    5c e#c pa//5%

    This command tells you the number of characters, words, and lines in the3etc3passwd file.

    5c -l e#c pa//5%

    This command tells you the number of lines #only$ in the 3etc3passwd file.

    30

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    31/48

    www.ignousolvedassignments.com

    5c -5 M>S#o$>

    This command counts the number of words in the file named 2y tory#which can be useful if you're paid by the wordW$.

    5 o 8 5c -l

    This command counts the number of users logged into your computersystem. The output of the who command is piped into the wc command,which counts the number of lines in the who output.

    p/ -e 8 5c -l

    This command counts the number of processes running on your computersystem.

    43) +i/pla> >o& c&$$e"# e" i$o" e"# a$ia,le/ 5i# # e ollo5i"gco a"%: /e# o$ e" .

    tandard ) %0 variables are split into two categories, environmentvariables and shell variables. %n broad terms, shell variables apply only tothe current instance of the shell and are used to set short-term workingconditionsC environment variables have a farther reaching significance, andthose set at login are valid for the duration of the session. 7y convention,environment variables have )++GH (; G and shell variables have lowercase names.

    G I%HF 2G T variables are set using the /e#e" command,

    displayed using the p$i"#e" or e" commands, and unset using the&"/e#e" command.

    To show all values of these variables, type

    ? p$i"#e" 8 le//

    The current environment variable settings can be displayed using thesetenv command with no arguments.

    31

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    32/48

  • 8/10/2019 Fourth Sem Solved Lab Manual

    33/48

    www.ignousolvedassignments.com

    it will, for finger re!uests originating outside the local host, firmly deny the existence of that user. &or this to work, the finger program,must be able to

    see the .nofinger file. This generally means that the home directory containing the file must have the other-users-execute bit set #o6x$.

    = finger MsTo see other users8 = finger username`domainTo see details in less3more than one page = fingerusername`domain less3more

    4@) I >o& 5i/ G e(pe$i e"# 5i# # e /e"%i"g a"% $ecei i"g ail &/i"g# e pi"e e ail p$og$a .

    +ine is an easy to use, character based mail client. %t supports full screenediting of messages, binary attachments #such as *%& or Z%+ files$, andother advanced message system features that were not possible usingolder electronic mail clients.

    &eatures of pine8 &ull creen (apabilities afety for ew )sers M confirmation of actions. Fn- ine

  • 8/10/2019 Fourth Sem Solved Lab Manual

    34/48

    www.ignousolvedassignments.com

    P. To compose mail, )se the compose command C - COMPOSEMESSA E to compose a message. ;fter composing, to send themail, use C#$l6 to send your message. (an you see the choiceSe"% in the menu bar at the bottom of the screen.

    S. To see the mails you have received use the L - LIST FOL+EKS command from the main menu to see your folders and choose the% 7F0 folder. )se N - Ne(#M/g to read the next message or P -P$e M/g to read previous message.

    /. To reply use the K - Kepl> command, and to forward mail use the F -Fo$5a$% command.

    . "ou can use the + - +ele#e command to delete your unwanted mails.R. %f you want to print #or read the message you want to print, then

    choose the command O - OT EK CM+S , then choose command ? -P$i"#. ;t the bottom you will see the message P$i"# e//age n &/i"g a##ac e%-#o-a"/i Z , where n is the message number.

    ;nswer it with [ e/\ . ; pop-up print setup screen will appear, andclick O_ button. "our mail content will then be printed from your localprinter.

    . "ou can exit pine by using ` - `'IT command when you are in themain menu.

    4 ) +ele#e all ile/ i" # e c&$$e"# %i$ec#o$> 5 o/e "a e e"%/ i" X.,a=Y

    The command rm is used to delete files from a directory. %t is used as8X =Y$ filename

    Bhere filename can be in the current directory

    To remove all the files with the . bak extension8 X =Y$

  • 8/10/2019 Fourth Sem Solved Lab Manual

    35/48

    www.ignousolvedassignments.com

    To display set of lines in ) %0 we use an Gx editor.Gditors available on )nix include8e% basic line editore( line editor

    i screen editore ac/ screen editorGx is an enhanced and more friendly version of ed. Ii is a screen-basedversion of ex.The command ex is used to invoke the editor. The format of this commandis8= ex XfilenameYThe p command #for 'print'$ used to display lines in the file. The format ofthis command is88Xline-range Y p%f no range is supplied the current line is displayed.+ressing JHGT)H E is e!uivalent to moving on to and displaying the nextline. Bith small files it is possible to display the entire file by pressingJHGT)H E until the end of the file is reached.

    ine HangesHanges of lines that can be given to edit commands include8

    ;bsolute line number refers to line , refers to lines to

    Helative line numbers-D refers to D lines before the current line6P refers to P lines after the current line-D,6P refers to a range from D lines before the current line to P lines afterthe current line

    pecial symbolsL refers to the last line in the file e.g. Lp to display last line, ,Lp to displayentire file. refers to the current line e.g. .,Lp to display from the current line to the endTo display lines O- S of any file which contains D/ lines, do

    = O, S p

    4 ) Co&"# o5 a"> li"e/ co"#ai" # e 5o$% /cie"ce i" a 5o$% ile/cie"ce.#(#.

    35

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    36/48

    www.ignousolvedassignments.com

    &irst find the word using the grep command and then pie it using the wccommand

    = grep science science.txt ^ wc Ml

    *0) Li/# # e /#a#i/#ic/ o # e la$ge/# ile!o"l> # e la$ge/# ile) i" # ec&$$e"# %i$ec#o$>.

    Fne line script to find the largest file in the current directory is8

    find . -type f -print ^ xargs ls -ladtr ^ cut -cPS- ^ sort -n -r ^ head J E

    ote8a$ The above code should be executed in one line#i.e. ignore word wrap$

    b$ %nsert -xdev before the -print if you areinterested only in the filesystem you are inand not others mounted under the directoryyou are in.

    SESSION: @

    *1) _ill a"> p$oce// 5i# elp o # e PI+ a"% $&" a"> p$oce// a# # e,ac=g$o&"%.

    %n order to kill a process there are D ways8&irst use ps to view what processes are running,

    =ill pid where :pid: is the process %1 number listed under the +%1column when you use p/ .

    ometimes this doesn't work and you have to use a more aggressiveversion of kill. =ill - pid will get the operating system to kill theprocess immediately. This can be dangerous if the process has

    control of a lock mechanisms, but your process will stop. %f you findyourself completely stuck, terminals have frozen upon you and you

    36

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    37/48

    www.ignousolvedassignments.com

    just don't know what to do, you can log in again and use =ill - -1 .This command will kill all of your processes including your current login. The next time you log in, everything that was running or waslocked up will have terminated.

    To run the process in background8 uspend the process using (trl6Z, This suspends execution of the

    process, and gives you a command line. To move the suspended process to the background, type ,g . The

    process then resumes execution, exactly as if you had typed whenstarting the process.

    To later bring a background process back into the foreground, use the

    g command. This command takes an argument specifying whichbackground process to place in the foreground. This is the jobnumber displayed when the process was placed in the background. %fyou cannot remember the job number of the process you wish tobring back to the foreground, the o,/ command will list all the jobsyou are currently running and their numbers.

    e.g8

    )sing ps to view what processes are running, this will give you the followingoutput8

    PI+ TT TIME COMMAN+O R console OO8O/ shO P ttyOD O8DO 3bin3local3usr3zshO D ttyOD O8DD psO O ttyOO D8O/ 3net3pppd

    To kill the process O P

    = Aill O PTo move process O O to background8

    = bg O O

    *2) Selec# a #e(# File a"% %o&,le Space # e li"e/.)se the G1 command to double space the lines in a text file.? /e% ile"a e

    *3) Li/# all &/e$/ $o e#c pa//5% i" # e alp a,e#icall> /o$#e% o$%e$.

    37

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    38/48

    www.ignousolvedassignments.com

    To list all users on a )nix system, even the ones who are not logged in,look at the 3etc3password file.To see in detail, about all the users do8 L cat 3etc3passwdto just see the )nix user names, use the command J ca# e#c pa//5% 8c -%: - 18/o$#

    *4) C$ea#e a ile 5i# %&plica#e $eco$%/ a"% %ele#e %&plica#e $eco$%/o$ # a# ile.

    To delete duplicate files8Fn a single line #you can copy-paste this directly to a shell$8

    F)T&Qrem-duplicates.shC echo : W 3bin3sh: E LF)T&C find :L`: -type f-printO ^ xargs -O -n md/sum ^ sort --keyQ ,PD ^ uni! -w PD -d --all-repeatedQseparate sed -r 's3KXO-9a-fY4# $433Cs3#XKa-z;-ZO-9.3 -Y$3___ 3gCs36$3 rm _ 3' EE LF)T&C chmod a6x LF)T&C ls -l LF)T&

    S ell Sc$ip# :

    F)T&Qrem-duplicates.shCecho : W 3bin3sh: E LF)T&Cfind :L`: -type f -printO ^ xargs -O -n md/sum ^ sort --keyQ ,PD ^ uni! -w PD -d --all-repeatedQseparate ^ sed -r 's3KXO-9a-fY4# $433Cs3#XKa-z;-ZO-9.3 -Y$3___ 3gCs3#.6$3 rm _ 3' EELF)T&Cchmod a6x LF)T&C ls -l LF)T&

    Gxplanation8. write output script header

    D. list all files recursively under current directoryP. escape all the potentially dangerous characters with xargsS. calculate 21/ sums/. find duplicate sums

    . strip off 21/ sums and leave only file namesR. escape strange characters from the filenames

    . write out commented-out delete commands

    38

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    39/48

    www.ignousolvedassignments.com

    9. make the output script writable and l/ -l it

    To create a duplicate copy of the file8

    J cp ile"a e1 ile"a e2

    To remove the duplicate copy8

    **) '/e # e Xg$epY co a"% #o /ea$c # e ile e(a ple1 o$ # eocc&$a"ce/ o # e /#$i"g X5a#e$Y

    J g$ep 5a#e$ e(a ple1

    *@) $i#e g$ep co a"%/ #o %o # e ollo5i"g ac#i i#e/: To select the lines from the file that has exactly two characters. To select the lines from a file that start with upper case letters. To select the lines from a file that has one or more blank spaces. To select the lines from a file that end with a period. To select the lines in a file and direct them to another file which has

    digits as one of the characters in that line.

    39

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    40/48

    www.ignousolvedassignments.com

    PAKT-I: MCS-043: +BMS La,

    Ta,le C$ea#io":

    !! reate tablecreate table TG;(

  • 8/10/2019 Fourth Sem Solved Lab Manual

    41/48

    www.ignousolvedassignments.com

    maxextents unlimited $C!! reate/0ecreate primary, unique and foreign key constraintsalter table TG;(

  • 8/10/2019 Fourth Sem Solved Lab Manual

    42/48

    www.ignousolvedassignments.com

    !! reate/0ecreate primary, unique and foreign key constraintsalter table ( ; add constraint ( ; +A primary key #( ; F$ using index

    tablespace " TG2 pctfree O initrans D maxtrans D// storage # initial SA minextents maxextents unlimited $Calter table ( ; add constraint ( ; &A foreign key #T F$ references TG;(

  • 8/10/2019 Fourth Sem Solved Lab Manual

    43/48

    www.ignousolvedassignments.com

    2% %2%T )27GH, 2;0 %2%T )27GH, *H;1G I;H(

  • 8/10/2019 Fourth Sem Solved Lab Manual

    44/48

    www.ignousolvedassignments.com

    min limit, max limit, grade

    E(e$ci/e 1:

    a$elect 4

    from teacherwhere birthdate Q #select max #birthdate$ from teacher$C

    b$elect 4

    from teacherwhere title Q #select title from teacher where upper#f name$QN ;%1GG+NC

    c$elect 4

    from teacherwhere join date E N O-jul- 99/Nand salary in #select salary from teacher where joining date J N O-jul- 99/NC

    e$elect t.4

    from teacher t, payscale swhere t.salary between s.min limitand s.max limitand s.grade Q N7NC

    44

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    45/48

    www.ignousolvedassignments.com

    f$elect t.4

    from teacher t , payscale swhere exists #select 4 from class c where t.t no Q c.t no$and #t.salary between s.min limit and s.max limit$ and t.gradeQ(NC

    g$elect 4

    from teacherwhere supervisor QN"G NC

    h$ elect t.4, s.4from teacher t, payscale swhere #t.salary between s.min limit and s.max limit$and #s.grade (N or s.grade QN7N$ and #t.f name like = = =N$C

    i$elect t.4, c.4

    from teacher t, class cwhere t.t noQc.t noand c.class no between and /C

    j$ elect 4from teacherwhere to char#to date#birthdate,N22N$$ Q to char#to date#sysdate,N22N$$C

    E(e$ci/e 2:

    a$(reate view supervisor detailsasselect t no, supervisior from teacherC

    b$(reate index class index on class#t no$ C

    45

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    46/48

    www.ignousolvedassignments.com

    c$alter view supervisor detailsasselect 4 from teacher where supervisiorQN"G NC

    d$select 4from teacherwhere to char#joiningdate,'yyyy'$6 / E to char#sysdate,'yyyy'$C

    e$create T*T viewasselect 4 from teacher t where t.salary EQ DOOO and t.titleQNT*TNC

    f$drop view T*T C

    g$create index teacher index on teacher#f name$C

    h$drop index class index C

    i$create view teacher infoasselect t no, f name, salary, gradefrom teacher t, payscale swhere t.salary between s.min limit and s.max limit and s.grade Q N7NC

    j$ create view as select 4 from teacher where #to char#to date#birthdate,NyyyyN$$ -to char#to date#system,NyyyyN$$$ E SOC

    46

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 8/10/2019 Fourth Sem Solved Lab Manual

    47/48

  • 8/10/2019 Fourth Sem Solved Lab Manual

    48/48

    www.ignousolvedassignments.com

    end G0P(C

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/