Top Banner

of 66

unixlabmanual-120422134336-phpapp01

Jun 04, 2018

Download

Documents

Junaid Iqbal
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    1/66

    Systems lab MCCS1.8

    Cycle-1

    1.unix commands:

    a. Text processing and backup utilities:

    1. head : It displays the first few lines of one or more files (page) .

    Syntax: $ head !ilename"

    It displays the first 10 lines of the file.

    Ex: [root@dcalabnixser!er "#$ cat aaa

    i am a good girl

    hello

    hw r

    i am fine

    how is it

    are there any thing

    india is my

    conty

    all are fine

    it is better

    dont do that

    where are

    hello hw r

    is it o%%

    what is that

    than%

    bye

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    2/66

    [root@dcalabnixser!er "#$ head aaa

    i am a good girl

    hello

    hw r

    i am fine

    how is it

    are there any thing

    india is my

    conty

    all are fine

    it is better

    Syntax: $ head #n !ilename"

    Ex: [root@dcalabnixser!er "#$ head &' aaa

    i am a good girl

    hello

    hw r

    syntax: $ cat !ilename" head -n - %t display !irst n lines

    Ex: [root@dcalabnixser!er "#$ cat aaa head &

    i am a good girl

    hello

    hw r

    i am fine

    &. tail : It displays last few records of one or more file

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    3/66

    Syntax: tail !ilename"

    It displays last 10 lines.

    Ex: [root@dcalabnixser!er "#$ tail aaa

    conty

    all are fine

    it is better

    dont do that

    where are

    hello hw r

    is it o%%

    what is that

    than%

    bye

    Syntax: tail #n !ilename"

    Ex: [root@dcalabnixser!er "#$ tail &* aaa

    than%

    bye

    syntax: cat !ilename" tail -n

    Ex: [root@dcalabnixser!er "#$ cat aaa tail &1

    bye

    If u want to redirect to permanent

    Ex: + head &*0 ,filename- tail & - file1 (file1 is newfile)

    Ex: + tail /'0 ,filename- head & - file1 (file1 is newfile)

    '. tr :ranslate characters by characters

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    4/66

    ranslate or delete characters

    Syntax: $ tr (option) !ilename"

    Ex: + [root@dcalabnixser!er sril#$ cat f'

    welcome to first mtech

    *010&11

    [root@dcalabnixser!er sril#$ tr wel 2,f'

    222com2 to first mt2ch

    *010&11

    Duplicate characters avoid with sequential order

    Ex: + tr &s 3r4 , filenameDelete the characters

    Syntax: $ tr -d *r+ !ilename

    [root@dcalabnixser!er sril#$ tr &d e,f5wlcom to adithyacollgof technology

    ,. Sort: sort lines of text files according to the first character

    Syntax: sort (option) !ilename"

    6ptions:

    &b7 &&ignore&leading&blan%s ignore leading blan%s

    &d7 &&dictionary&order consider only blan%s and alphanmeric characters

    &f7 &&ignore&case fold lower case to pper case characters

    &g7 &&general&nmeric&sort compare according to general nmerical !ale

    &i7 &&ignore&nonprinting consider only printable characters

    &87 &&month&sort compare (n%nown) , 9;9

    &n7 &&nmeric&sort compare according to string nmerical !ale

    &r7 &&re!erse re!erse the reslt of comparisons

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    5/66

    Ex : sort stdent

    student !ilename

    01 !i?ay 50 0

    1* anil A0 A

    '* s?an 5 0

    0 hari A0

    ** ra? B 0

    . Cut:Cemo!e sections from each line of files.

    1. Character cutting

    Syntax: $ cut -c !ilename"

    Dirst character of the all lines

    [root@dcalabnixser!er sril#$ ct &c &10 f5

    ome to

    ege

    echnol

    Ex: + ct &c1 ,filename-

    o ct the first >haracter 6f the all records

    Ex: + ct &cB ,filename-

    o ct the Bthcharacter in each line

    Ex: + ct &c7 B ,filename-

    o ct th

    and Bth

    >haracter In each line

    Ex: + ct &c &B ,filename-

    o ct thto Bth>haracters range

    2. Field cutting

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    6/66

    &d field separator

    Syntax: $ cut -d *:+ -!& !ilename"

    >t *ndfield in all records

    Ex: [root@dcalabnixser!er sril#$ cat-bbb

    aaa:fff:hhhh

    ttt:

    ghh:tgyh:y

    ert:hg??%:hhh

    ['#/ topped cat - bbb

    [root@dcalabnixser!er sril#$ ct &d : &f1 bbb

    aaa

    ttt

    ghh

    . /ni0: Cemo!e dplicate lines from a sorted file

    Syntax: $ uni0 (option) !ilename"

    6ptions:&c7 &&cont prefix lines by the nmber of occrrences

    &d7 &&repeated only print dplicate lines

    &=7 &&all&repeated[Fdelimit&method# print all dplicate linesdelimit&methodFGnone(defalt)7prepend7separateH =elimiting is done with blan%lines.

    &f7 &&s%ip&fieldsF< a!oid comparing the first < fields

    &i7 &&ignore&case

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    7/66

    ignore differences in case when comparing

    &s7 &&s%ip&charsF< a!oid comparing the first < characters

    &7 &&nie only print nie lines

    &w7 &&chec%&charsF< compare no more than < characters in lines=isplays only the =plicate records

    Ex: + ni &d ,filename -

    [root@dcalabnixser!er sril#$ cat-ccc

    aaa

    bbb

    aaa

    aaa

    [A#/ topped cat - ccc

    [root@dcalabnixser!er sril#$ ni &d ccc

    aaa

    Ex: + ni &= ,filename-

    Jrint all dplicate Cecords and demeliting is done with blan% lines

    Ex: + ni Kc ,filename-

    Jrefix lines by the

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    8/66

    6ptions:

    &a reat all files as text and compare them line&by&line7 e!en if they do not seem to be text.

    &b Ignore changes in amont of white space.

    &L Ignore changes that ?st insert or delete blan% lines.

    [root@dcalabnixser!er sril#$ cat-lc%y

    apple

    bannana

    orange

    pineapple

    cat

    rat

    [#/ topped cat - lc%y

    [root@dcalabnixser!er sril#$ cat-%eert

    apple

    banana

    oringe

    pineapple

    mat

    pen

    [10#/ topped cat - %eert

    [root@dcalabnixser!er sril#$ diff lc%y %eert

    *7'c*7'

    , bannana

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    9/66

    , orange

    &&&

    - banana

    - oringe

    75c75

    , cat

    , rat

    &&&

    - mat

    - pen

    Comm.:compare two sorted files line by line

    Syntax: comm (23T%24)... 5%671 5%67&

    Ex: [root@dcalabnixser!er sril#$ comm lc%y %eert

    apple

    banana

    bannana

    orange

    oringe

    pineapple

    cat

    mat

    pen

    rat

    . tee : It displays and redirects the same time

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    10/66

    read from standard inpt and write to standard otpt and files

    Ex: + ls &l ,filename-

    + ls &l tee ,filename-

    + ls &&fll&time tee &a ,filename- & appending existing file

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    11/66

    Ex: + find " &type d &name 3ra?4

    It searches the absolte path of the =irectories

    Ex: + find " &type f &name 3file14 exce catGHPQ

    It searches the absolte path of the filename and displays the contents of file.

    Ex: + find " &type f &name 3file14 exce cat GHP exce rmGHPQ

    It searches the absolte path of the filename and displays the content of file7 and remo!es at the

    same time.

    Ex: + find " &type f &perm 5

    It searches the file nder with 5 permission

    Ex: + find " &type f &perm 5 &exce chmod 50 GHPQ

    It searches the filename nder with permission 5 and change the file permissions to 50.

    Ex: + find " &type f siRe 0Q

    It earches the Sero byte files

    Linux: 512 bytes 1 block

    Ex: + find " &type f siRe 100c (Exactly 100 bytes file)

    + find " &type f siRe /100c (abo!e 100 bytes file)

    + find " &type f siRe &100c (below 100 bytes file)

    Ex: + find " &type d siRe Bb

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    12/66

    It searches the Bbytes =irectories

    Ex: + find " &type f &i nm 310B4

    It searches the file with inode nmber

    Ex: + find " type d K inm 310*4

    It searches the directories with inode nmber

    Time

    &a K ;ccess

    &c K >hanged

    &m K 8odified

    Ex: + find " &type f Ka min '0It searches the file before '0 min access

    Ex: + find " &type f Ka time KnNnN/nIt searches the file before few days

    9. rep

    he grep tilities are a family of Tnix tools7 inclding grep7 egrep7 and fgrep7 that performrepetiti!e searching tas%s. he tools in the grep family are !ery similar7 and all are sed forsearching the contents of files for information that matches particlar criteria. Dor most prposes7yoUll want to se fgrep7 since itUs generally the fastest

    he general syntax of the grep commands is:

    yntax: grep [&options# pattern [filename#

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    13/66

    Vo can se fgrep to find all the lines of a file that contain a particlar word. Dor example7 to listall the lines of a file named my file in the crrent directory that contain the word dog7 enter atthe Tnix prompt:Ex: fgrep dog myfile

    his will also retrn lines where dog is embedded in larger words7 sch as dogma ordogged. Vo can se the &w option with the grep command to retrn only lines where dog isinclded as a separate word:

    Ex: grep &w dog myfile

    o search for se!eral words separated by spaces7 enclose the whole search string in otes7 for

    example:

    Ex: fgrep dog named >hec%ers myfile

    he fgrep command is case sensiti!eQ specifying dog will not match =og or =6W. Vo canse the &i option with the grep command to match both pper& and lowercase letters:

    Ex: grep &i dog myfile

    o list the lines of myfile that do not contain dog7 se the &! option:

    Ex: fgrep &! dog myfile

    If yo want to search for lines that contain any of se!eral different words7 yo can create a

    second file (named second file in the following example) that contains those words7 and then se

    the &f option:

    Ex: fgrep &f second file my file

    Vo can also se wildcards to instrct fgrep to search any files that match a particlar pattern.Dor example7 if yo wanted to find lines containing dog in any of the files in yor directorywith names beginning with my7 yo cold enter:

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    14/66

    Ex: fgrep dog my2

    his command wold search files with names sch as my file7 my.hw17 and my stff in thecrrent directory. Each line retrned wold be prefaced with the name of the file where thematch was fond.

    Ly sing pipes andNor redirection7 yo can se the otpt from any of these commands withother Tnix tools7 sch as more7 sort7 and ct. Dor example7 to print the fifth word of e!ery line ofmy file containing dog7 sort the words alphabetically7 and then filter the otpt throgh themore command for easy reading7 yo wold enter at the Tnix prompt:

    Ex: fgrep dog myfile ct &f &d sort more

    If yo want to sa!e the otpt in a file in the crrent directory named new file7 enter:

    Ex: fgrep dog my file ct &f &d sort - new file

    + grep Kn ,file- & o display record nmber

    + grep &i,file- & o ignore record

    + grep Kc ,file- & o cont in how many records expression

    + grep KE ,file- & o search for mltiple expression

    + grep KX ,file- & It gi!e the file name and which the

    reglar expression

    + grep Kr ,file- & o search regressi!ely and present wor%ing

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    15/66

    directory

    + grep Kw ,file- & o search for the exact match for the word

    + grep Ks ,file- & o sppress errors

    + grep 3?ai4 ,file- & It prints the expressi!e record which

    ha!e got the 3?ai4

    + grep Kn 3?ai4 ,file- & It display the record nmber and

    expression what we gi!e 3?ai4

    + grep Kin 3?ay4 ,file- & It ignore and prints the record

    3ay4

    + grep KE 3?ay prem4 ,file- & It search for mltiple

    expressions and prints the record

    + grep Kl 3?ay42 & It displays the filename which the

    3ay4 expression is

    !"

    ;YZ is a simple and elegant pattern scanning and processing langage

    ;YZ is also the most portable scripting langage

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    16/66

    It was created in late A0th of the last centry. he name was composed from the initial letters ofthree original athors ;lfred . ;ho7 Lrian Y. Zernighan7 and Jeter . Yeinberger. It iscommonly sed as a command&line filter in pipes to reformat the otpt of other commands. ItUsthe precrsor and the main inspiration of Jerl. ;lthogh originated in Tnix it is a!ailable and

    widely sed in Yindows en!ironment too.

    ;YZ ta%es two inpts: data file and command file. he command file can be absent andnecessary commands can be passed as agments. ;s Conald J. Xoi aptly noted aw i! "er#under appreciated language$

    he main ad!antage of ;YZ is that nli%e Jerl and other scripting monsters that it is !ery slim

    withot featre creep so characteristic of Jerl and ths it can be !ery efficiently sed with pipes.

    ;lso it has rather simple7 clean syntax and li%e mch hea!ier >X can be sed with > for dal&

    langage implementations.

    aw%Us fa!or compared to perl:

    & aw% is simpler (especially important if deciding which to learn first)& aw% syntax is far more reglar (another ad!antage for the beginner7 e!en withot considering syntax&highlighting editors)& yo may already %now aw% well enogh for the tas% at hand& yo may ha!e only aw% installed& aw% can be smaller7 ths mch ic%er to execte for small programs& aw% !ariables donUt ha!e \+U in front of them :&)& clear perl code is better than nclear aw% codeQ bt

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    17/66

    prede#ined variables in awk

    all predefined !ariables are in pper cases

    D & Inpt field separator

    6D & 6pt field separator

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    18/66

    aw% has got ' sections

    1. LIWI8= '1'B ptsN1 00:00:00 bash '1A ptsN1 00:00:00 ps

    &. kill:Terminating a processZill is sed to terminate the exection of a bac%grond process. he process&id of the

    process to be terminated mst be specified with %ill command. If process id ]0 (Rero)M isspecified7 all processes in the process are signed.

    Syntax: $kill process id"

    6ptions:n where n is larger than 0. he process with pid n will be signaled.

    0 ;ll processes in the crrent process grop are signaled.

    &1 ;ll processes with pid larger than 1 will be signaled.

    Ex: [root@dcalabnixser!er sril#$ %ill & 0

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    26/66

    '.at:at command allows the ser to specify the time when a command is to be exected. hecommand ta%es two argments7 the time at which the command is to be exected7 and thecommand to be exected.

    Syntax: at time(date) (increment)

    Ex: [root@dcalabnixser!er sril#$ [root@dcalabnixser!er sril#$ at 1*.'0pm ?an 1'at- cat f'at- ,E6-?ob ' at *011&01&1' 1*:'0

    ,.nice:Tnix also allows the ser to specify the priority of commands. he nice command is sedto rn a command at a specified schedling priority.

    Syntax: nice (-increment) command (argument)

    Ex: [root@dcalabnixser!er "#$ nice

    nice0

    . >ho:who command shows who is logged on7as well as information abot the system.

    Syntax: $>ho

    Ex: [root@dcalabnixser!er sril#$ whoroot :0 *011&01&1' 0:*5root ptsN1 *011&01&1' 0: (1A*.15.5.*0)

    .>ho am i:=isplays crrent ser.

    Syntax:$>ho am i

    Ex: [root@dcalabnixser!er sril#$ who am iroot ptsN1 *011&01&1' 0: (1A*.15.5.*0)

    .>:w command printf smmaries of system sage7 crrently logged&in sers7 and what they aredoing.

    Syntax: > (option) (user)

    6ptions:& Ignores the sername while figring ot the crrent process and cp times. odemonstrate this7 do a s and do a w and a w &.

    &s Tse the short format. =on9t print the login time7 >JT or J>JT times.&l =isplay information in long format.

    & =isplay !ersion information.

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    27/66

    Ex: [root@dcalabnixser!er sril#$ w10:**:' p 1:0A7 * sers7 load a!erage: 0.107 0.0*7 0.01TEC V DC68 X6WIJT J>JT YO;root :0 & 0:*5 `xdm` 1'.0's 0.11s NsrNbinNgnome&session

    root ptsN1 1A*.15.5.*0 0: 0.00s 0.0As 0.00s wB. 5ile le?el security:Tnix ses an elaborate method of file access permissions to maintain file secrity.

    Dile access permissions: Each file and directory has an

    1. ;n owner: he ser who created the file.*. ; grop: ; grop of sers ha!e access to the file.'. 6thers: 6ther sers of the system.

    he permissions can be granted or denied to these three classes of sers.

    hree types of file access permissions are there7 they are

    read: ; file can be read7 displayed on terminal7 copied and compiled.write: ; file can be read modified and deleted.exected: ; file can be exected as a program.

    hey are represented as

    &rwx&&&&&&drwxr&&r&&&rwx&w&&w&& & Diled & =irectoryw & Yrirer & Ceadx & Exectable

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    28/66

    yntax: chmod mode fileshe mode is the permission to be assigned. 8ode can be specified in two ways

    1.

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    29/66

    &rw&&&x&&& 1 root root 1 an 1* 0A: f5[root@dcalabnixser!er sril#$ chmod &w f5[root@dcalabnixser!er sril#$ ls Kl&r&&&&x&&& 1 root root 1 an 1* 0A: f5

    To =emo?e the Drite and execute permissions to roup and 2thers

    Ex: [root@dcalabnixser!er sril#$ ls &ltotal *drwxrwxrwx * root root 05 an 1* 0:'5 d'[root@dcalabnixser!er sril#$ chmod g&wx7o&wx d'[root@dcalabnixser!er sril#$ ls &ltotal *drwxr&&r&& * root root 05 an 1* 0:'5 d'

    n Achange o>nerB E chgrp Achange groupB: chown changes file ownership and

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    30/66

    reassign the ownership of the file from one ser to another.Syntax: cho>n (option) ne>o>ner !ilename

    6ptions:&c7 &&changes&li%e !erbose bt report only when a change is made

    &h7 &&no&dereference&affect each symbolic lin% instead of any referenced file

    Ex: [root@dcalabnixser!er sril#$ ls &l&&&xr&&rwx 1 root root '1 an 10 1':** f'[root@dcalabnixser!er sril#$ chown mic f'[root@dcalabnixser!er sril#$ ls &l&&&xr&&rwx 1 mic root '1 an 10 1':** f'

    Chgrpalso changes ownership. It changes the grop ownership of the file.Syntax: chgrp (option) groupname !ilename

    6ptions:&c7 &&changes& li%e !erbose bt report only when a change is made

    &h7 &&no&dereference&affect each symbolic lin% instead of any referenced file &&preser!e&rootfail to operate recrsi!ely on 9N9

    &f7 &&silent7 &&iet sppress most error message &C7 &&recrsi!e operate on files and directories recrsi!elyEx: [root@dcalabnixser!er sril#$ ls &l&&&xr&&rwx 1 mic root '1 an 10 1':** f'[root@dcalabnixser!er sril#$ chgrp mic f'[root@dcalabnixser!er sril#$ ls &l&&&xr&&rwx 1 mic mic '1 an 10 1':** f'

    1F.ne>grp :changes grop.Syntax: ne>grp group

    [root@dcalabnixser!er sril#$ newgrp mic

    c.4et>orking commands:

    1. !tp :his command is sed to connect to any other compter on yor networ% rnning ftp.tart it with the following[root@dcalabnixser!er "#$ ftpftpftp- ` Oere in the ftp prompt we ha!e to specify special ftp commands.ype a ` or help toprompt commands.he following table lists the most freently sed commands

    Command =esult

    ascii Tses7 ascii as a file transfer type

    bell Cings the bell when file transfer is

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    31/66

    completed

    Linary Tses binary as file transfer type

    it or bye erminates ftp session

    close Ends ftp connection with remote machine7bt %eeps local ftp program rnning

    cd >hanges directory on remote machineget filename Wets the filename from remote machine

    pwd Xists the crrent wor%ing directory onremote machine

    ftp- open 1A*.15.5.100>onnected to 1A*.15.5.100.**0 dcalabnixser!er DJ ser!er (ersion .50) ready.

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    32/66

    login: mca0''Jassword:Xast login: e 6ct 1 0:0:*0 from 1A*.15.5.'1[mca0''@dcalabnixser!er "#+ pwdNhomeNmca0''

    [mca0''@dcalabnixser!er "#+ exit>onnection closed by foreign host.[mic@dcalabnixser!er "#+ pwdNhomeNmic

    . 5inger :his command displays information abot system sers.

    2ptions:

    &s display the otpt in short form&l display th otpt in long form&m coese finger to search only in login names that match with argment name.Ex: [mic@dcalabnixser!er "#+ finger micXogin: mic

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    33/66

    To Create a 5ile:

    Syntax: $ cat (option) " !ilename"

    he option can be any one of the below

    .no

    6ption Dnction

    1. &! It is sed to display nonprintable characters.

    *. &n It is sed to nmbering lines inotpt.

    '. &b It sed to nmber nonblan%otpt lines.

    . &e It display + at end of each line.

    . &; hows all

    5. &s ne!er more than one singleblan% line

    Ex: [root@dcalabnixser!er "#$cat - file1

    Oello..

    his is my first Dile

    Oa!e a trl/d (a!e)

    To Gie> a already existing 5ile:

    Syntax: $ cat !ilename"

    Ex: [root@dcalabnixser!er "#$cat file1Oello..

    his is my first Dile

    Oa!e a

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    34/66

    his is simple file

    his is a simple file*

    he contents of second file are shown immediately after the first file.

    To append data to an existing !ile

    Syntax: $ cat "" !ilename"

    Ex: [root@dcalabnixser!er "#$cat -- file1Oello..

    his is my first Dile

    Oa!e a ith help o! cat command

    Syntax: $ cat !ilename1 !ilename& ...!ilename AnB "

    Ex[root@dcalabnixser!er "#$cat -f1 -f* -f' -f

    Oello....

    his is file nmber f

    Ye create mltiple files

    d (a!e)

    isplay the record number to the particular !ile

    Syntax: $ cat #n !ilename"

    Ex: [root@dcalabnixser!er "#$ cat &n f1 1 welcome to adithya * college ' of technology

    To ignore the blank =ecords

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    35/66

    Syntax: $ cat #b !ilename"

    Ex: [root@dcalabnixser!er "#$ cat &n f 1 hg?fdh *

    ' sd?fh!idf sd%lf?g!i?[root@dcalabnixser!er "#$ cat &b f 1 hg?fdh

    * sd?fh!idf

    ' sd%lf?g!i?

    Create a Hidden !ile

    Syntax: $ cat (option) !ilename"

    Ex: + cat -.file1[root@dcalabnixser!er "#$ cat -.f

    hai

    hello

    isplay the record >ith single blank line.

    [root@dcalabnixser!er "#$ cat f5

    gdfahf?

    gfhdgh?

    hgdfhdi

    ?hd?f?i%

    [root@dcalabnixser!er "#$ cat &s f5

    gdfahf?

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    36/66

    gfhdgh?

    hgdfhdi

    ?hd?f?i%

    [root@dcalabnixser!er "#$ cat f

    cat: f: ith common strings can be displayed using cat as:

    syntax:$cat !ileI

    Ex: [root@dcalabnixser!er "#$ cat f`

    welcome to adithya

    college

    of technology

    welcome to first mtech

    *010&11

    welcome to first mtech

    *010&11

    hg?fdh

    sd?fh!idf

    sd%lf?g!i?

    gdfahf?

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    37/66

    gfhdgh?

    hgdfhdi

    ?hd?f?i%

    '.CC command: used to compile one or more C source !iles.

    Syntax: $cc !irst.c

    ,. lsAlistB :

    It is a command to list the files and directories in the present wor%ing =irectory

    $ ls - a : It is a command to display all files and =irectories inclding hidden files and

    =irectories.

    $ls J: Xist information abot the Diles (the crrent directory by defalt). ort entries

    alphabetically

    $ls K: It list the all Lac%p files

    $ls L: It list the all lin%ed files and =irectories

    $ls -d: It =isplays the present wor%ing =irectory.

    $ls -i: It =isplays the inode nmbers of files and =irectories

    $ls -s: It =isplays the siRes in bloc%s (Diles _ =irectories)

    $ls -l: It =isplays the long listing files and directories in present wor%ing directory

    6isting directory contents:

    $ ls list a directory$ ls -l list a directory in long (detailed) format

    Dor example:

    $ ls -l

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    38/66

    drwxr&xr&x !i?ay ser 10* n 1B 0:0 Y;IC6

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    39/66

    anaconda&%s.cfg exam.c pser.c strclii.c

    [root@dcalabnixser!er "#$ ls &l

    total 151B

    &rw&r&&r&& 1 root root * 6ct *1 1':5 *

    &rw&r&&r&& 1 root root 10 ;g 1B 1B:5 ;

    &rw&r&&r1 root root 11' ;g 1B 1B: a.c

    &rw&r&&r1 root root A5 6ct *1 1':0 add1.sh

    drwxr&xr&x * root root 05 an 1':*B =es%top

    &rw&r&&r&& 1 root root 1*1 6ct *1 1':1* e*.c

    &rw&r&&r&& 1 root root 11B 6ct *1 1':1A e'.c

    %. MO&' COMMANDS$

    his command is sed to mo!e the files and directories one place to another place

    Syntax: $ m? (option) Source !ileirectory" Target !ileirectory"

    6ptions:

    .no

    6ption Dnction

    1. &b he file1 mo!e to file* withbac%p.

    *. &f he file1 mo!e to file* withforcibly.

    '. &if he file1 mo!e to file* withinteracti!e and forcibly mode.

    hese are basically ' types

    1. Dile to Dile

    *. Dile to =irectory

    '. =irectory to =irectory

    1. 5ile to 5ile

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    40/66

    Syntax: $ m? (option) Source !ile" Target !ile"

    [root@dcalabnixser!er "#$ m! old new

    [root@dcalabnixser!er "#$ cat old

    cat: old: ith backup mode

    Ex: +m! &f file1 =ir14ote: The !ile1 mo?e to ir1 >ith !orcibly mode

    Ex: +m! &if file1 =ir14ote: The !ile1 mo?e to ir1 >ith interacti?e and !orcibly mode.

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    41/66

    '. irectory to irectory

    Syntax: $ m? (option) Source irectory" Target irectory"

    Ex: + [root@dcalabnixser!er sril#$ lsdir1 dir* f1 f* f'[root@dcalabnixser!er sril#$ m! dir1 dir*[root@dcalabnixser!er sril#$ lsdir* f1 f* f' f[root@dcalabnixser!er dir*#$ lsdir1 f* f'Ex: [root@dcalabnixser!er sril#$ cp .Ndir*Ndir1N2 ..Ncp: o!erwrite \..Nf1U` y[root@dcalabnixser!er sril#$ ls &a. .. dir* f1 f* f' f4ote: The content o! ir1 mo?es to ir&

    Ex: + m! &b =ir1 =ir*4ote: The contents o! ir1 mo?e to ir& >ith backup

    Ex: + m! &f =ir1 =ir*4ote: The contents o! ir1 mo?es to ir& >ith !orcibly

    Ex: + m! &if =ir1 =ir*4ote: The contents o! ir1 mo?es to ir& >ith interacti?e and !orcibly mode.

    .CO() COMMANDS$Xi%e m! command7 cp is sed to create new files or mo!e the contentsof file to another location . Tnli%e mo!e7 howe!er7 cp lea!es the original file intact at its

    location.

    Syntax: $cp (option) source !ile" estination !ile"

    6ptions 7

    &a7 &&archi!e

    same as &dC &&preser!eFall

    &&bac%p[F>6

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    42/66

    &f7 &&force if an existing destination file cannot be opened7 remo!e it and try again

    &i7 &&interacti!e prompt before o!erwrite

    &O follow command&line symbolic lin%s

    &l7 &&lin% & lin% files instead of copying

    &X7 &&dereference & always follow symbolic lin%s

    &J7 &&no&dereference

    hese are basically ' types

    1. Dile to a Dile

    *. Dile to a =ictionary

    '. =irectory to =irectory

    5ile to 5ile

    Syntax : $cp source !ile" estination !ile"

    Ex : [root@dcalabnixser!er sril#$ ls

    dir* f1 f* f' f

    [root@dcalabnixser!er sril#$ cp f f

    [root@dcalabnixser!er sril#$ ls

    dir* f1 f* f' f f

    ....new file

    Ex :[root@dcalabnixser!er sril#$ cat f1

    welcome to adithya

    college

    of technology

    [root@dcalabnixser!er sril#$ cat f*

    welcome to first mtech

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    43/66

    *010&11

    [root@dcalabnixser!er sril#$ cp f1 f*

    cp: o!erwrite \f*U` y

    [root@dcalabnixser!er sril#$ cat f*

    welcome to adithya

    college

    of technology

    ... Existing file

    4ote: The content o! ohn !ile o?er>rite >ith ?enkat

    Ex Q +cp &f !en%at %mar4ote : %t is copy the !ile !orcibly ?enkat to kumar >ithout any permission

    Ex : +cp &i !en%at gandhi4ote : %t is copy the !ile interacti?e mode ?enkat to kumar >ith permissions

    &. 5ile to irectory

    Syntax N $ cp source !ile" estination irectory"

    Ex Q [root@dcalabnixser!er dir*#$ ls

    dir1 f* f'

    [root@dcalabnixser!er dir*#$ cd ..

    [root@dcalabnixser!er sril#$ cp f dir*

    [root@dcalabnixser!er sril#$ cd dir*

    [root@dcalabnixser!er dir*#$ ls

    dir1 f* f' f

    Ex : [root@dcalabnixser!er "#$ cp &d f1 sril[root@dcalabnixser!er "#$ cd sril[root@dcalabnixser!er sril#$ lsf14ote : %t copys the !1!ile to srilu irectory >ith backup

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    44/66

    Ex : [root@dcalabnixser!er "#$ cp &bf f1 sril[root@dcalabnixser!er "#$ cd sril[root@dcalabnixser!er sril#$ lsf14ote N %t copys the !1 !ile to srilu irectory >ith !orcibly backup

    Ex : + [root@dcalabnixser!er "#$ cp &ibf f1 sril[root@dcalabnixser!er "#$ cd sril[root@dcalabnixser!er sril#$ lsf14ote : %t copys the !1 !ile to srilu irectory >ith backup interacti?ely and !orcibly

    Ex : [root@dcalabnixser!er sril#$ lsf1[root@dcalabnixser!er sril#$ cd[root@dcalabnixser!er "#$ cp f1 f* f' sril[root@dcalabnixser!er "#$ cd sril[root@dcalabnixser!er sril#$ lsf1 f* f'4ote : %t copies the no o! !ile to irectory

    '. irectory to irectory

    Syntax : $ cp Source irectory" estination irectory"

    Ex : + cp =ra!id WanglyEx : + cp &r 8ody en%at4ote : %t copies the irectory to irectory Aincluding all !iles and irectoriesB

    Ex : + cp &ir ,=irectory 1- ,=irectory *-4ote : %t copies the irectory to irectory Aincluding >ith all !iles and directories >ith

    interacti?e modeB

    Ex : + cp &rf ,=ir 1 - ,=ir *- ,=ir '- ,=estination =irectory-4ote : %t copies the multiple irectories >ith !orcibly and recessi?ely mode

    . rmAremo?ing a !ileB:

    he rm command is sed to delete a file.

    To =emo?e a !ile

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    45/66

    SyntaxN $ rm (option) !ilename"

    6ptions:

    Cemo!e (nlin%) the DIXE(s).

    &f7 &&force ignore nonexistent files7 ne!er prompt

    &i7 &&interacti!e prompt before any remo!al

    &r7 &C7 &&recrsi!e remo!e directories and their contents recrsi!ely

    &!7 &&!erbose

    explain what is being done

    Ly defalt7 rm does not remo!e directories. Tse the &&recrsi!e (&r or &C) option to remo!eeach listed directory7 too7 along with all of its contents.

    Ex: [root@dcalabnixser!er sril#$ lsdir* f1 f* f' f f[root@dcalabnixser!er sril#$ rm frm: remo!e reglar file \fU` y[root@dcalabnixser!er sril#$ lsdir* f1 f* f' f

    To =emo?e Multiple 5iles

    Syntax: $ rm (option) !ilenames "

    Ex: + rm f1 f* f' f

    To remo?e !iles 5orcibly

    Syntax: $ rm (option) !ilename"

    Ex: [root@dcalabnixser!er sril#$ rm &f f[root@dcalabnixser!er sril#$ lsdir* f1 f* f'

    To =emo?e %nteracti?e Mode

    Syntax: $ rm (option) !ilename"

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    46/66

    Ex: [root@dcalabnixser!er sril#$ lsdir* f1 f* f'[root@dcalabnixser!er sril#$ rm &i f'rm: remo!e reglar file \f'U` n[root@dcalabnixser!er sril#$ ls

    dir* f1 f* f'

    To =emo?e irectory

    Syntax: $ rm (option) irectory 4ame"

    To =emo?e all irectories and subdirectories

    Syntax: $ rm -r irectory 4ame"

    Ex: $ [root@dcalabunixserver srilu]# rm -r dir3rm: descend into directory `dir3'? y

    rm: remove directory `dir3/aaa'? y

    rm: descend into directory `dir3/d'? y

    rm: descend into directory `dir3/d/d3'? y

    rm: remove directory `dir3/d/d3/d!'? y

    rm: remove directory `dir3/d/d3'? y

    rm: remove directory `dir3/d'? y

    rm: remove directory `dir3'? y

    [root@dcalabunixserver srilu]# ls

    dir dir! "3 " " "% "&

    To =emo?e irectories 5orcibly

    SyntaxN $ rm -r! irectory 4ame"

    Ex: $ [root@dcalabunixserver srilu]# rm -r" dir!

    [root@dcalabunixserver srilu]# ls

    dir "3 " " "% "&

    . touch: he toch command is sed to pdate the timestamp on the named file. he time stamp

    the last time the file was altered or accessed.

    Syntax: touch (option) !ilename

    6ptions:

    &a change only the access time

    &c7 &&no&create & do not create any files

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    47/66

    &f (ignored)

    &m change only the modification time

    &r7 &&referenceFDIXE& se this file9s times instead of crrent time

    Ex: [root@dcalabnixser!er sril#$ ls

    dir* f1 f* f'

    [root@dcalabnixser!er sril#$ toch f

    [root@dcalabnixser!er sril#$ ls

    dir* f1 f* f' f

    4ote: %! the !ile name issued as an argument does not eistsO touch creates it as an empty !ile.

    Ex: [root@dcalabnixser!er sril#$ ls

    dir* f1 f* f' f

    [root@dcalabnixser!er sril#$ toch &c f5

    [root@dcalabnixser!er sril#$ ls

    dir* f1 f* f' f

    8. >c: wc command to determine the length of a gi!en file. Ly defalt7 the otpt shows thelength in lines7 words7 characters.

    Syntax: $ >c (option) !ilename"

    6ptions:

    &c7 &&bytes print the byte conts

    &m7 &&chars print the character conts

    &l7 &&lines print the newline conts

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    48/66

    &X7 &&max&line&length print the length of the longest line

    &w7 &&words

    print the word conts

    Ex: [root@dcalabnixser!er sril#$ wc f1' 5 1 f1

    no of new line!$

    Ex: [root@dcalabnixser!er sril#$ cat f1welcome to adithyacollegeof technology

    [root@dcalabnixser!er sril#$ wc &l f1' f1

    8. lnAcreating linksB:ln command is sed to create lin%s for files and allowing them to be

    accessed by different names.

    >all the lin% fnction to create a lin% to a file.>all the lin% fnction to create a lin% named DIXE* to an existing DIXE1

    1. Oard lin%*. oft Xin%

    Syntax: ln (option) !ile1 !ile&

    ln (option) !ile directory

    6ptions:

    &b li%e &&bac%p bt does not accept an argment

    &f7 &&force&remo!e existing destination files

    &n7 &&no&dereference&treat destination that is a symlin% to a directory as if it were a normal

    file

    &i7 &&interacti!e&prompt whether to remo!e destinations

    &s7 &&symbolic&ma%e symbolic lin%s instead of hard lin%s

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    49/66

    1. Hard link: Oard lin% can be bild single file systemOard lin% can recogniRed it lin%s same permissions and same siRe7 same i&node nmberIf the data in sorce is loss we can get it from hard lin%i&node nmber is gi!en space allocatedi&node nmbers can recogniRed different logical names

    Syntax : ln source !ile" target !ile"

    Ex: [root@dcalabnixser!er sril#$ ls &l

    total 15

    drwxr&xr&x ' root root 05 an 11 1*: dir*

    &rw&r&&r&& 1 root root 1 an 1* 0A:0 f*

    &rw&r&&r&& 1 root root '1 an 10 1':** f'

    &rw&r&&r&& 1 root root 0 an 1* 0A:0 f

    &rw&r&&r&& 1 root root 1 an 1* 0A: f5

    [root@dcalabnixser!er sril#$ ln f* f1

    [root@dcalabnixser!er sril#$ ls

    dir* f1 f* f' f f5

    [root@dcalabnixser!er sril#$ ln f* fA

    [root@dcalabnixser!er sril#$ ls &l

    total *

    drwxr&xr&x ' root root 05 an 11 1*: dir*

    &rw&r&&r&& ' root root 1 an 1* 0A:0 f1

    &rw&r&&r&& ' root root 1 an 1* 0A:0 f*

    &rw&r&&r&& 1 root root '1 an 10 1':** f'

    &rw&r&&r&& 1 root root 0 an 1* 0A:0 f

    &rw&r&&r&& 1 root root 1 an 1* 0A: f5

    &rw&r&&r&& ' root root 1 an 1* 0A:0 fA

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    50/66

    [root@dcalabnixser!er sril#$ ln f* fB

    [root@dcalabnixser!er sril#$ ls &l

    total *B

    drwxr&xr&x ' root root 05 an 11 1*: dir*

    &rw&r&&r&& root root 1 an 1* 0A:0 f1

    &rw&r&&r&& root root 1 an 1* 0A:0 f*

    &rw&r&&r&& 1 root root '1 an 10 1':** f'

    &rw&r&&r&& 1 root root 0 an 1* 0A:0 f

    &rw&r&&r&& 1 root root 1 an 1* 0A: f5

    &rw&r&&r&& root root 1 an 1* 0A:0 fA

    &rw&r&&r&& root root 1 an 1* 0A:0 fB

    [root@dcalabnixser!er sril#$ ls

    dir* f1 f* f' f f5 fA fB

    [root@dcalabnixser!er sril#$ rm f*

    rm: remo!e reglar file \f*U` y

    [root@dcalabnixser!er sril#$ ls

    dir* f1 f' f f5 fA fB

    &.So!t link:

    It can be bilt across the file systemIf the sorce file is delete we canUt retrie!e from target file

    Syntax : ln -s source !ile" target !ile"

    Ex: [root@dcalabnixser!er sril#$ ln &s f* f

    [root@dcalabnixser!er sril#$ ls &l

    total *B

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    51/66

    drwxr&xr&x ' root root 05 an 11 1*: dir*

    &rw&r&&r&& root root 1 an 1* 0A:0 f1

    &rw&r&&r&& root root 1 an 1* 0A:0 f*

    &rw&r&&r&& 1 root root '1 an 10 1':** f'

    &rw&r&&r&& 1 root root 0 an 1* 0A:0 f

    &rw&r&&r&& 1 root root 1 an 1* 0A: f5

    &rw&r&&r&& root root 1 an 1* 0A:0 fA

    &rw&r&&r&& root root 1 an 1* 0A:0 fB

    lrwxrwxrwx 1 root root * an 1* 0B:1* f &- f*

    [root@dcalabnixser!er sril#$ ls

    dir* f1 f* f' f f5 fA fB

    [root@dcalabnixser!er sril#$ rm f*

    rm: remo!e reglar file \f*U` y

    [root@dcalabnixser!er sril#$ ls

    dir* f1 f' f f5 fA fB f

    9.unlink:se nlin% to delete the name and possibly the file it referMs to.

    Syntax:$ unlink !ilename"

    Ex: [root@dcalabnixser!er sril#$ ls

    dir* f1 f' f f5 fA fB

    [root@dcalabnixser!er sril#$ nlin% f1

    [root@dcalabnixser!er sril#$ ls

    dir* f' f f5 fA fB

    1F. mkdir E rmdir: (8a%ing and Cemo!ing directories)

    m%dir creates the new directory in which we can store files and other directories.

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    52/66

    Syntax: $ mkdir (option) irectory name"

    6ptions:&m7 &&modeF86=E set permission mode (as in chmod)7 not rwxrwxrwx & mas%

    &p7 &&parents no error if existing7 ma%e parent directories as needed

    &!7 &&!erbose print a message for each created directory

    &S7 &&contextF>66

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    53/66

    Ex: [root@dcalabnixser!er sril#$ m%dir &p dir'Naaa dirNbbb[root@dcalabnixser!er sril#$ cd dir'[root@dcalabnixser!er dir'#$ lsaaa d*

    [root@dcalabnixser!er dir'#$ cd ..[root@dcalabnixser!er sril#$ cd dir[root@dcalabnixser!er dir#$ lsbbb

    rmdir:sed to remo!e directories if they are empty.

    Syntax:rmdir (option) directory name"

    Ex: [root@dcalabnixser!er sril#$ lsdir* dir' dir dir f' f f5 fA fB

    [root@dcalabnixser!er sril#$ rmdir dir[root@dcalabnixser!er sril#$ lsdir* dir' dir f' f f5 fA fB

    11. cdAchange directoryB:he cd command enables yo to mo!e arond with in the file system.Tsed withot argments it retrns to yor home directory. o mo!e to another directory directoryname is reired as an argment.

    Syntax: cd directory name"

    To Change the irectory

    Syntax: $ cd irectory name"

    Ex: [root@dcalabnixser!er dir'#$ cd aaa[root@dcalabnixser!er aaa#$To change the directory !or>ard

    Syntax: $ cd ..

    Ex: [root@dcalabnixser!er aaa#$ cd ..[root@dcalabnixser!er dir'#$

    To Mo?e parent irectory ArootB

    Syntax: $ cd

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    54/66

    Ex: [root@dcalabnixser!er dir'#$ cd[root@dcalabnixser!er "#$

    &. Shell programming

    i.

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    55/66

    [root@dcalabnixser!er sril#+cat factorial.sh

    echo Enter n !ale

    read n

    let iF1

    let fF1

    while [ +i &le +n #

    do

    let fFf2i

    let iFi/1

    done

    echo factorial of +n is +f

    [root@dcalabnixser!er sril#+ sh factorial.sh

    Enter n !ale

    factorial of is 1*0

    ii.hich the user has readO >rite and

    execute permissions.

    S2/=C7 C27:

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    56/66

    [root@dcalabnixser!er sril#+ cat dirlist.sh

    ls - c

    $ cat c

    exec , c

    while read line

    do

    if test &f +lite

    then

    if test &r +line

    then

    if test &w +line

    then

    if test &x +line

    then

    echo +line

    fi

    fi

    fi

    fi

    done

    [root@dcalabnixser!er sril#+ sh dirlist.sh

    a.ot sample11.txt

    iii.ing string operations.

    a. To extract a substring !rom a gi?en string.

    S2/=C7 C27:

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    57/66

    [root@dcalabnixser!er sril#+ cat sample.sh

    echo enter any string

    read s

    echo enter range

    read n

    read m

    echo \+sct &c +m&+n\

    [root@dcalabnixser!er sril#+ sh sample.sh

    enter any string

    ansha

    enter range

    *

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    58/66

    S2/=C7 C27:

    $inclde,stdio.h-main()G

    int s[10#7p[10#7n7i7?7wiF07w[10#7t[10#7 st[10#7t7tstF0Qint ttF07twF0Qfloat aw atQprintf(enter no.of process)Qscanf(d7_n)Qprintf(Pn enter time anm)Qscanf(d7_t)Qprintf(Pn enter process_ser!ice time)Qfor(iF0Qi,nQi//)scanf(dd7_p[i#7_s[i#)Q

    for(iF0Qi,nQi//)st[i#Fs[i#QtstFtst/s[i#Qfor(?F0Q?,tstQ?//)for(iF0Qi,nQi//)Gif(s[i#-t)Gs[i#Fs[i#&tQw1Fw1/tQt[i#Fw1Qw[i#Ft[i#&st[i#QHelse if(s[i#^F0)Gw1Fw1/tQt[i#Fw1Qw[i#Ft[i#&st[i#Qs[i#Fs[i#&tQHHfor(iF0Qi,nQi//)GtwFtw/w[i#QttFtt/t[i#QHawFtwNnQatFttNnQprintf(processPtstPtwtPttt)Qfor(iF0Qi,nQi//)printf(dPtdPtdPtd7p[i#7st[i#7w[i#7t[i#)Q

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    59/66

    printf(awtFd7aw)Qprintf(attFd7at)QH

    %nput:

    enter no of process 'enter time antm *enter process_ser!ice time1*5'*

    2utput:

    process st >t tt 1 B * 5 5 1* ' * 5;wt F .000000att F B.000000

    b. SQ5

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    60/66

    $inclde,stdio.h-main()Gint i7?7bt[10#7n7pt[10#7wt[10#7tt[10#7t7%7l7w1F07t1F0Q

    float at7awQprintf(3enter no of ?obs4)Qscanf(3d47_n)Qprintf(3enter brst time4)Qfor(iF0Qi,nQi//)scanf4(d47_bt[i#)Qfor(iF0Qi,nQi//)for(?F0Q?,nQ?//)

    if(bt[i#,bt[?#)

    GtFbt[i#Qbt[i#Fbt[?#Qbt[?#FtQHfor(iF0Qi,nQi//)Gwt[i/1#Fbt[i#/wt[i#Qtt[i/1#Ftt[i#/bt[i#Qw1Fw1/wt[i#Qt1Ft1/tt[i#QH

    awFw1NnQatFt1NnQprintf(3PnbtPtwtPttt4)Qfor(iF0Qi,nQi//)printf(3dPtdPtdPn47bt[i#7wt[i#7tt[i#)Qprintf(3awFdPnatFd47aw7at)Qgetch()QH

    %nput:

    Enter no of ?obs

    Enter brst time1*B*02utput:

    Pt >t tt

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    61/66

    0 1* 1'B 1' **0 * awF10.A000

    atF**.000000

    c. 5C5S

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    62/66

    S2/=C7 C27:

    inclde,stdio.h-main()G

    int i7?7bt[10#7n7pt[10#7wt[10#7tt[10#7t7%7l7w1F07t1F0Qfloat at7awQprintf(3enter no of ?obs4)Qscanf(3d47_n)Qprintf(3enter brst time4)Qfor(iF0Qi,nQi//)scanf4(d47_bt[i#)Q

    for(iF0Qi,nQi//)Gwt[i/1#Fbt[i#/wt[i#Qtt[i/1#Ftt[i#/bt[i#Qw1Fw1/wt[i#Qt1Ft1/tt[i#QHawFw1NnQatFt1NnQprintf(3PnbtPtwtPttt4)Qfor(iF0Qi,nQi//)printf(3dPtdPtdPn47bt[i#7wt[i#7tt[i#)Qprintf(3awFdPnatFd47aw7at)Qgetch()QH

    %nput:

    enter no of ?obs'enter brsttime1*B*0output:

    bt >t tt

    1* 0 1*B 1* *0*0 *0 0awF10.5555A0atF*.00000

    d. 3=%2=%TR

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    63/66

    S2/=C7 C27:

    $inclde,stdio.h-main()

    Gint i7?7bt[10#7n7pt[10#7wt[10#7tt[10#7t7%7l7w1F07t1F0Qfloat at7awQprintf(3enter no of ?obs4)Qscanf(3d47_n)Qprintf(3enter brst time4)Qfor(iF0Qi,nQi//)scanf4(d47_bt[i#)Qprintf(3enter priority !ales4)Qfor(iF0Qi,nQi//)scanf(3d47_pt[i#)Q

    for(iF0Qi,nQi//)for(?F0Q?,nQ?//)if(pt[i#,pt[?#)GtFpt[i#Qpt[i#Fpt[?#Qpt[?#FtQ%Fbt[i#Qbt[i#Fbt[?#Qbt[?#F%QHfor(iF0Qi,nQi//)Gwt[i/1#Fbt[i#/wt[i#Qtt[i/1#Ftt[i#/bt[i#Qw1Fw1/wt[i#Qt1Ft1/tt[i#QHawFw1NnQatFt1NnQprintf(3PnbtPtprorityPtwtPttt4)Qfor(iF0Qi,nQi//)printf(3dPtdPtdPtdPn47bt[i#7pt[i#7wt[i#7tt[i#)Qprintf(3awFdPnatFd47aw7at)Qgetch()QH

    %nput:

    Enter no of ?obs

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    64/66

    Enter brsttime10*

    AEnter priority !ales*1'

    2utput:

    Pt priority >t tt

    1 0

    * * 5A ' 5 1'10 1' *'awF.A0000atF1*.00000

    ,. >rite programs !or !orkO ?!ork.

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    65/66

  • 8/13/2019 unixlabmanual-120422134336-phpapp01

    66/66