Post on 28-Feb-2018
transcript
7/25/2019 Linux Pracs
1/66
Kirti College T.Y.B.Sc. Linux
Practical No 3
Part-I:File System Commands:touch,cat,cp,rm,mv,mkdir,cd,rmdir
Q:1 Create !ive !iles "ith the name a1,#$,c3,d%,e& #y usin' touchcommand(
[user43@linserver user43]$ touch a1 b2 c3 d4 e5
Q:$ Create !ive !iles "ith the name !),'*,h+ usin' cat command "ithsome meanin'!ul contents "ith a[user43@linserver user43]$ cat> f6This is file f6this is cat command.hello.hi.tbsc.
[user43@linserver user43]$ cat> !"
thid is file !"hello.hi.tbsc.this is cat cmd.
[user43@linserver user43]$ cat> h#this is file h#hello.hi.tbsc.this is cat cmd.
Q:3 Concatenate the contents o! !) and '* to a !ile called ne"1(ithout creatin' ne"1[user43@linserver user43]$ cat f6 !" >>ne1[user43@linserver user43]$ cat ne1This is file f6this is cat command.hello.hi.tbsc.thid is file !"hello.hi.tbsc.this is cat cmd.
Q:% .ppend the contents o! !) and h+ to ne"1([user43@linserver user43]$ cat f6 h# >> ne1[user43@linserver user43]$ %]$ cat ne1This is file f6this is cat command.
Department of Computer Science 1
7/25/2019 Linux Pracs
2/66
Kirti College T.Y.B.Sc. Linux
hello.hi.tbsc.thid is file !"hello.hi.
tbsc.this is cat cmd.This is file f6this is cat command.hello.hi.tbsc.this is file h#hello.hi.tbsc.this is cat cmd.
Q:& Copy contents o! !) to a1, '* to #$, h+ to c3 #y usin' cpcommand([user43@linserver user43]$ c& f6 a1[user43@linserver user43]$ cat a1This is file f6this is cat command.hello.hi.tbsc.
[user43@linserver user43]$ c& !" b2[user43@linserver user43]$ cat b2thid is file !"hello.hi.tbsc.this is cat cmd.
[user43@linserver user43]$ c& h# c3[user43@linserver user43]$ cat c3this is file h#hello.hi.tbsc.
this is cat cmd.
Q:) Create t"o directions "ith the name dd1 and dd$([user43@linserver user43]$ m'dir dd1[user43@linserver user43]$ m'dir dd2
Department of Computer Science 2
7/25/2019 Linux Pracs
3/66
Kirti College T.Y.B.Sc. Linux
Q:* Copy the !iles a1 and #$ to the directory dd1 #y usin' cpcommand( Copy the !iles !), '* to the directory dd$([user43@linserver user43]$ c& a1 b2 dd1[user43@linserver user43]$ ls dd1a1 b2
[user43@linserver user43]$ c& f6 !" dd2[user43@linserver user43]$ ls dd2a1 b2
Q:+ /emove the !iles a1, #$ !rom dd1([user43@linserver user43]$ rm dd1(a1[user43@linserver user43]$ ls dd1b2
[user43@linserver user43]$ rm dd1(b2[user43@linserver user43]$ ls dd1
Q:0 /emove the directory dd$ alon' "ith its contents([user43@linserver user43]$ rm )r dd2
Q:1 /ename the !iles !), '*, h+, #y ne"!), ne"'*, ne"h+, usin' mvcommand([user43@linserver user43]$ mv f6 nef6[user43@linserver user43]$ mv !" ne!"[user43@linserver user43]$ mv h# neh#
Q:11 2ove the !iles ne"!), ne"'* to the directory dd1([user43@linserver user43]$ mv nef6 ne!" dd1[user43@linserver user43]$ ls dd1nef6 ne!"
Part II: ls and ls "ith options
Chan'e the directory to #in and do the !ollo"in' and enter thecommands in your 4ournal(i 5ist all !ilenames([user43@linserver user43]$ cd (bin[user43@linserver user43]$ lsarch cut !a' ls redtcshash date !ette*t mail rm
touchash.static dd !re& m'dir rmdirtrueaumi*)minimal df !tar m'nod r&mumounta' dmes! !un+i& m'tem& rviuname
Department of Computer Science 3
7/25/2019 Linux Pracs
4/66
Kirti College T.Y.B.Sc. Linux
basename dnsdomainname !+i& more rvieunicode,startbash doe*ec hostname mount sedunicode,sto&bash2 domainname i!a' mt setfontunlin'
bsh dum&'es i&calc mv setserialuslee&cat echo -&e!)6b netstat sh vich!r& ed 'bd,mode nice slee&viechmod e!re& 'ill nisdomainname sort&domainnamechon env lin' &!a' stt+catc& e* ln &in! suc&io false load'es &s snccsh f!re& lo!in &d tar
ii 5ist all !ilenames "ith one screen at a time([user43@linserver bin]$ ls morearchashash.staticaumi*)minimala'basenamebashbash2bshcatch!r&chmodchonc&c&iocshcutdatedddfdmes!
dnsdomainnamedoe*ec))/ore0
iii 5ist all !ilenames "ith $ characters, 3 characters([user43@linserver bin]$ ls c& dd df ed e* ln ls mt mv &s rm sh su vi
Department of Computer Science 4
7/25/2019 Linux Pracs
5/66
Kirti College T.Y.B.Sc. Linux
[user43@linserver bin]$ ls ash a' bsh cat csh cut env &d red r&m rvi sed tar
iv 5ist all !ilenames "ith $ characters and % characters at thesame time([user43@linserver bin]$ ls
arch c&io df e* !tar lin' mail mv &s sort snc vibash date echo !a' !+i& ln more nice rm stt tcsh viec& dd ed !re& 'ill ls mt &in! sh su true +cat
v5ist all !ilenames startin' "ith vo"el[user43@linserver bin]$ ls [aeiou]arch ash.static a' ed env i!a' umount unicode,startunlin'ash aumi*)minimal echo e!re& e* i&calc uname unicode,sto&uslee&
vi 5ist all !ilenames "ith the last character as a or # or c or d(
[user43@linserver user43]$ ls [abcd]fs&aa fs&ac nesed &rime.c *aa *acfs&ab masterdata &rime1.c transdata *ab
vii 5ist all !ilenames "ith e6actly three characters in "hich thesecond character is a vo"el([user43@linserver bin]$ ls [aeiou]cat cut red sed tar
viii 5ist all !ilenames startin' "ith character 7a8([user43@linserver bin]$ ls [a]arch ash ash.static aumi*)minimal a'
i6 5ist all % character !ilenames "hose !irst character is 7a8 andthe third character is 7#8([user43@linserver bin]$ ls [a][b]ls [a][b] o such file or director
6 5ist all !ilenames "hose !irst character is 7m8 or 7r8 or is inthe ran'e c to ! or v to 9([user43tbsc2#%@linserver bin]$ ls [mrc)fv)+]cat c&io df dum&'es e* m'nod mv rvi+catch!r& csh dmes! echo false m'tem& red rviechmod cut dnsdomainname ed f!re& more rm vi
chon date doe*ec e!re& mail mount rmdir viec& dd domainname env m'dir mt r&m&domainname
6i 5ist all !ilenames "hose !irst character is any thin' otherthan an alpha#et in the ran'e d to m([user43@linserver bin]$ ls [d)m]
Department of Computer Science 5
7/25/2019 Linux Pracs
6/66
Kirti College T.Y.B.Sc. Linux
arch cat nice r&m sttunicode,startash ch!r& nisdomainname rvi suunicode,sto&ash.static chmod &!a' rvie snc unlin'aumi*)minimal chon &in! sed tar uslee&
a' c& &s setfont tcsh vibasename c&io &d setserial touch viebash csh red sh true&domainnamebash2 cut rm slee& umount +catbsh netstat rmdir sort uname
6ii Construct a command to display the total num#er o! !iles "ithe6actly three characters in their !ilename([user43@linserver bin]$ ls c )l 13
6iii Construct a command to display the total num#er o! !iles "ithe6actly t"o or three or !our characters in their !ilename([user43@linserver bin]$ ls c )l 4%
Chan'e the directory to the home directory and do the !ollo"in'6iv 5ist the contents o! the directory([user43@linserver user43]$ ls dir1f1 file1
6v 5ist the contents o! the directory alon' "ith all hidden !iles([user43@linserver user43]$ ls )a dir1. .. f1 file1
Department of Computer Science 6
7/25/2019 Linux Pracs
7/66
Kirti College T.Y.B.Sc. Linux
6vi 5ist the contents o! the directory alon' "ith all hidden !ilese6cept ( and (( !iles([user43@linserver user43]$ ls )71 co&1 fcm&1,2#% !reen &ract".18&ract"." &rime1.out 9tudent date fcm&2
.!t'rc &ract".11 &ract".% &rime.c 9tudent2#%ashini date1 fcm&2,2#% .'de &ract".12&ract#.1 .&rime.c.so t4 .bash,histor dir1fcm&3,2#% line &ract".13 &ract#.11.2 &rime.outtransdata .bash,lo!out dir2 fe*1 lo!in&ract".15 &ract#.12.3 &roduct,2#% tr2.bash,&rofile dir3 .file loo& &ract".1"&ract#.14 result trTime .bashrc dollfile2 masterdata &ract".1# &ract#.3 result1.viminfo bdata2#% .emacs fod1 merit2#%&ract".3 &ract#.5 9heta2#% ellochec' em& fore! month &ract".3.1
&ract#.6 ss1 chec'!rade em&data2#% fs&2#%names &ract".4 &ract#." ss2 commandfor fact!re1 &ract &ract".5 &ract#.# ss3commandline fcm&1
6vii 5ist all !iles "ith their attri#utes and !ile permissions([user43@linserver user43]$ ls )ltotal 284)r)r))r)) 1 tbsc2#% tbsc 15% :ec " 1852 71)r)r))r)) 1 tbsc2#% tbsc 16 ;an 1# 8%5" ashini)r)r))r)) 1 tbsc2#% tbsc 1%3 ;an 1# 8#3% chec')r)r))r)) 1 tbsc2#% tbsc 38" ;an 18 1551 9tud2#%
...
...)r)r))r)) 1 tbsc2#% tbsc 13% ;an 1% 1153 9tudent)r)r))r)) 1 tbsc2#% tbsc ##1 ;an 4 8#5# t1)r)r)r)) 1 tbsc2#% 546 ##1 :ec 14 8%52 tr1)r)r)r)) 1 tbsc2#% 546 2# :ec 38 1815 hite)r)r)r)) 1 tbsc2#% 546 36 :ec 14 8%8% ello
6viii9ame as above
6i6 5ist all the !iles sho"in' the si9e o! each !ile rounded up tothe nearest kilo#yte([user43@linserver user43]$ ls )s
total 284 4 71 4 dir3 4 lo!in 4 &ract".1" 4ss1 4 ashini 4 doll 4 loo& 4 &ract".1# 4ss2 4 chec' 4 em& 4 names 4 &ract".3 4ss3
Department of Computer Science
7/25/2019 Linux Pracs
8/66
Kirti College T.Y.B.Sc. Linux
4 chec'!rade 4 fact 4 &in' 4 &ract".3.1 49tud2#% 4 commandfor 4 file2 4 &ract 4 &ract".4 49tudent 4 date 4 !re1 4 &ract".11 8 &ract"." 4hite
...
66 5ist all the !iles accordin' to !ile si9e([user43@linserver user43]$ ls )9&rime.out &rime.c month fact fcm&3,244bdata244 fcm&1,244 &ract".1# &rime1.out &ract#.14&ract".11 71 loo& merit2#% commandline&ract".3 dir1 &ract".13 &ract".12 &ract#.12.39tudent244 transdata fod1 18888dir2 &ract#.5 &ract".18 &ract#.# &ract".1" file2doll date1 dir3 &rime1.c chec'!rade9tudent line result &ract".1 &ract"."
result1 trTime &ract".% &ract".4 ss3&ract#.1 ello fs&244 &ract".3.1 date9heta244 masterdata em& !reenlo!in &ract#.6 &ract".15 &ract#." namesfcm&2,244 commandfor t4 &ract#.11.2 em&data244&ract".6 &ract".5 fcm&2 ss2 tr2 !re2co&1 !re1 fore! &roduct,244 &ract#.3 fe*19tud244 chec' &ract fcm&1 ss1ashini
66i ive the !ile listin' displayed in columns([user43@linserver user43]$ ls )c!re2 date1 &ract".1# chec' ss1 &ract".1hite !re1 commandfor ashini em& chec'!radefs&244 !reen 71 &ract#.3 fore! ss3&ract".13 &ract"." 9tud244 ss2 dir2 dir39tudent &ract".15 &ract".12 doll names t1lo!in dir1 &ract".11 &ract".1" fact &ract".6co&1 commandline tr1 &ract#.1 &ract &ract".18&ract".4 &ract".3.1 file2 ello date loo&&ract".% &ract".5 &ract".3 &in' line
66ii ive the !ile listin' in reverse order([user43@linserver user43]$ ls )rello ss2 &ract".5 &ract".13 names fs&2#%
dir2 hite chec'!rade ss1 &ract".4 &ract".12loo& fore! dir1 chec' tr1 &ract#.3&ract".3.1 lo!in file2 date1 ashini t1&ract#.1 line &ract".3 &ract".18 fact date
71 9tudent &ract".% &ract".1# &ract".1!reenem& co&1 9tud2#% &ract"." &ract".1" &ract!re2 doll commandline ss3 &ract".6 &ract".15
Department of Computer Science !
7/25/2019 Linux Pracs
9/66
7/25/2019 Linux Pracs
10/66
Kirti College T.Y.B.Sc. Linux
Practical No %
Study o! commands:!ind, tr, head, tail, "c, !ile, sort, split
1 ;isplay usin'
[user43@linserver user43]$ find (usr(sbin more(usr(sbin(usr(sbin(iconvconfi!(usr(sbin(r&cinfo(usr(sbin(build)locale)archive(usr(sbin(+dum&(usr(sbin(+ic(usr(sbin(&unconv(usr(sbin(&c'(usr(sbin(!libc,&ost,u&!rade(usr(sbin(alternatives(usr(sbin(u&date)alternatives
(usr(sbin(m'lost7found(usr(sbin(ar&in!(usr(sbin(cloc'diff(usr(sbin(&in!6(usr(sbin(rdisc(usr(sbin(trace&ath(usr(sbin(trace&ath6(usr(sbin(traceroute6(usr(sbin(adduser(usr(sbin(ch&assd(usr(sbin(!rou&add(usr(sbin(!rou&del))/ore0
ii usrs#in #e'innin' "ith a lo"ercase 7c8([user43@linserver user43]$ find (usr(sbin(c(usr(sbin(camel)inde*)control(usr(sbin(camel)loc')hel&er(usr(sbin(ca&iinit(usr(sbin(chat(usr(sbin(ch'font&ath(usr(sbin(ch&assd(usr(sbin(chroot(usr(sbin(ci&ed)cb(usr(sbin(cloc'diff
(usr(sbin(crond(usr(sbin(cu&saddsmb(usr(sbin(cu&sd
Department of Computer Science 1#
7/25/2019 Linux Pracs
11/66
Kirti College T.Y.B.Sc. Linux
iii usrs#in in capital letters #e'innin' "ith a lo"ercase 7c8(>se sin'le-?uote !or tr command[user43@linserver user43]$ find (usr(sbin(c tr .
Department of Computer Science 11
7/25/2019 Linux Pracs
12/66
7/25/2019 Linux Pracs
13/66
Kirti College T.Y.B.Sc. Linux
3Classi!y,Count and Compare Filesa Find out "hat !ile types you have in the !ollo"in' directories:i etc[user43@linserver user43]$ file (etc((etc(a2&s.cf! 9BAA Cn!lish te*t
(etc(a2&s)site.cf! 9BAA Cn!lish te*t(etc(ad-time 9BAA te*t(etc(ae& director(etc(ae&.conf 9BAA te*t(etc(ae&lo!.conf 9BAA te*t(etc(alchemist director(etc(aliases 9BAA Cn!lish te*t(etc(aliases.db can
7/25/2019 Linux Pracs
14/66
Kirti College T.Y.B.Sc. Linux
el #83#6O version 1 M9S9NO for U(Dinu* 2.2.5O dnamicall lin'edMuses sharedlibsNO stri&&ed(usr(bin(+i&!re& ourne shellscri&t te*t e*ecutable
(usr(bin(+i&info CDJ 32)bit D9e*ecutableO Antel #83#6O version 1 M9S9NO for U(Dinu* 2.2.5O dnamicall lin'edMuses sharedlibsNO stri&&ed(usr(bin(+i¬e CDJ 32)bit D9e*ecutableO Antel #83#6O version 1 M9S9NO for U(Dinu* 2.2.5O dnamicall lin'edMuses sharedlibsNO stri&&ed(usr(bin(+i&s&lit CDJ 32)bit D9e*ecutableO Ant
el #83#6O version 1 M9S9NO for U(Dinu* 2.2.5O dnamicall lin'edMuses sharedlibsNO stri&&ed(usr(bin(+less ourne shellscri&t te*t e*ecutable(usr(bin(+more ourne shellscri&t te*t e*ecutableR..
#/epeat the previous ?uestion, #ut this time:i /e-direct etc listin' to ne" !ile etc!iles(t6t[user43@linserver user43]$ file (etc( > etcfiles.t*t[user43@linserver user43]$ cat etcfiles.t*t more(etc(a2&s.cf! 9BAA Cn!lish te*t(etc(a2&s)site.cf! 9BAA Cn!lish te*t(etc(ad-time 9BAA te*t(etc(ae& director(etc(ae&.conf 9BAA te*t(etc(ae&lo!.conf 9BAA te*t(etc(alchemist director(etc(aliases 9BAA Cn!lish te*t(etc(aliases.db can
7/25/2019 Linux Pracs
15/66
Kirti College T.Y.B.Sc. Linux
(etc(cdrecord.conf 9BAA Cn!lish te*t(etc(ci&e director(etc(BF? director(etc(cron.d director(etc(cron.dail director(etc(cron.hourl director
(etc(cron.monthl director
ii .ppend the listin' !or usr#in to etc!iles(t6t[user43@linserver user43]$ file (usr(bin( >> etcfiles.t*t
c Construct a command to !ind out ho" many !iles are in theusr#in directory([user43@linserver user43]$ file (usr(bin( c Vl 2161
% Sortin'a Sort the etc!iles(t6t into reverse alpha#rtical order on the
!irst !ile([user43@linserver user43]$ sort )r etcfiles.t*t more(usr(bin(+soelim smbolic lin' tosoelim(usr(bin(+soelim smbolic lin' tosoelim(usr(bin(+ne ourne shellCDJ 32)bit D9 e*ecutableO Antel #83#6O version 1 M9S9NO for U(Dinu* 2.2.5O dnamicall lin'edMuses sharedlibsNO stri&&ed(usr(bin(+i¬e CDJ 32)bit D9e*ecutableO Antel #83#6O version 1 M9S9NO for U(Dinu* 2.2.5O dnamicall lin'edMuses sharedlibsNO stri&&ed
# /epeat the !irst sortin' e6ercise #ut i'norin' case di!!erences([user43@linserver user43]$ sort )f )r etcfiles.t*t more(usr(bin(+soelim smbolic lin' tosoelim(usr(bin(+soelim smbolic lin' tosoelim(usr(bin(+ne ourne shellscri&t te*t e*ecu
table(usr(bin(+ne ourne shellscri&t te*t e*ecutable(usr(bin(+more ourne shellscri&t te*t e*ecutable
Department of Computer Science 15
7/25/2019 Linux Pracs
16/66
7/25/2019 Linux Pracs
17/66
Kirti College T.Y.B.Sc. Linux
d Find out ho" many @n'lish te6t !iles are listed in theetc!iles(t6t !ile[user43@linserver user43]$ !re& Cn!lish etcfiles.t*t c )l 6"
& Create a !ile usin' vi editor "ith the !ollo"in' contents([user43@linserver user43]$ cat names/ahesh :esh&ande 234aresh air 431llen :isu+a 121Hari Gutian 231?amesh :ube 231'sha :as 256
i Sort on the !irst names only[user43@linserver user43]$ sort 78 )1 names'sha :as 25
llen :isu+a 121Hari Gutian 231/ahesh :esh&ande 234aresh air 431?amesh :ube 231
ii Sort on the last names only[user43@linserver user43]$ sort 71 )2 names'sha :as 256/ahesh :esh&ande 234llen :isu+a 121?amesh :ube 231Hari Gutian 231aresh air 431
iii Sort on !irst !our characters only[user43@linserver user43]$ cut )c 1)4 names sort'shlleHari/aheare?ame
iv Sort on their num#ers only
[user43@linserver user43]$ sort 72 namesllen :isu+a 121Hari Gutian 231?amesh :ube 231/ahesh :esh&ande 234'sha :as 256aresh air 431
Department of Computer Science 1
7/25/2019 Linux Pracs
18/66
Kirti College T.Y.B.Sc. Linux
)Construct and e6ecute the commands to create a !ile "ith the nameStudArollBno "ith the !ollo"in' !ields separated #y a #lank space(i[user43@linserver user43]$ cat 9tud244?ollo Jirstame Dastame :ateFfirth /ar's2#% 9heta Bhoudhar ")12)1%#5 438
2%1 /ildred :
7/25/2019 Linux Pracs
19/66
Kirti College T.Y.B.Sc. Linux
...a&&lication(nes)messa!e)ida&&lication(nes)transmissiona&&lication(ocs&)reWuesta&&lication(ocs&)res&onse
ii ;isplay !irst t"o lines o! !spAseatBno and convert all thecharacters into capital letters[user43@linserver user43]$ head )2 fs&244 tr
7/25/2019 Linux Pracs
20/66
Kirti College T.Y.B.Sc. Linux
a&&lication(inde*.cmd. . .
a&&lication(mathematica)olda&&lication(msord doca&&lication(nes)messa!e)ida&&lication(nes)transmission
a&&lication(ocs&)reWuesta&&lication(ocs&)res&onse
v Split a !ile !spAseatBno into su#parts each havin' at most $lines and display the contents o! these su#parts and count thenum#er o! lines in them[user43@linserver user43]$ s&lit )28 fs&244[user43@linserver user43]$ ls71 date1 fcm&3,2#% line t4 18888dir1 fcut1 lo!in ashini dir2 fcut2loo& &roduct,244 tr2 bdata244 dir3 fe*1masterdata result trTime chec' doll file2
merit244 result1 *aa em& fod1 month&ract".1# 9heta244 *ab em&data244 fore! names&ract".3 ss1 *ac commandline fact fsed1nesed ss2 ello co&1 fcm&1 fs&244nesedclear ss3 cutlist1 fcm&1,244 !re1 &ractcutlist2 fcm&2 !re2 &ract".1 &ract".6&rime1.cdate fcm&2,244 !reen &ract".18 &ract"."&rime1.out 9tudent244
[user43@linserver user43]$ cat *aa c )l 28[user43@linserver user43]$ cat *ab c )l 28[tbsc2#%@linserver tbsc2#%]$ cat *ac c )l 18
Department of Computer Science 2#
7/25/2019 Linux Pracs
21/66
Kirti College T.Y.B.Sc. Linux
vi Split the !iles !spAseatBno into three su#parts named !spaa,!spa#, !spac and display the contents o! these !iles and count thenum#er o! lines in them[user43@linserver user43]$ s&lit )28 fs&244 fs&[user43@linserver user43]$ ls
71 date1 fcm&3,244 line t4 18888dir1 fcut1 lo!in ashini dir2 fcut2loo& &roduct,244 tr2 bdata244 dir3 fe*1masterdata result trTime chec' doll file2merit244 result1 *aa em& fod1 month&ract".1# 9heta244 *ab em&data244 fore! names&ract".3 fs&aa *ac commandline fact fsed1nesed fs&ab ello co&1 fcm&1 fs&244nesedclear fs&ac cutlist1 fcm&1,244 !re1 &ractcutlist2 fcm&2 !re2 &ract".1 &ract".6&rime1.cdate fcm&2,244 !reen &ract".18 &ract"."
&rime1.out 9tudent244
[user43@linserver user43]$ cat fs&aa c )l 28[user43@linserver user43]$ cat fs&ab c )l 28[user43@linserver user43]$ cat fs&ac c )l 18
Department of Computer Science 21
7/25/2019 Linux Pracs
22/66
Kirti College T.Y.B.Sc. Linux
Practical No(&
1 od,cmp,comm(,di!!,uni?:Breate a file named fod1 ith some contents havin! the folloin!contents and dis&la it ini octal !orm only
[user43@linserver user43]$ od )b fod18888888 124 158 151 163 848 151 163 848 168 162 141 143 164 151 1431418888828 154 848 156 165 155 142 143 162 848 865 812 123 158 16" 1431648888848 141 848 183 158 15" 165 144 158 141 162 1"1 812 124 131 1821638888868 143 8128888862
ii octal !orm alon' "ith its te6t contents([user43@linserver user43]$ od )b )c fod1
8888888 124 158 151 163 848 151 163 848 168 162 141 143 164 151 143141 T h i s i s & r a c t i ca8888828 154 848 156 165 155 142 143 162 848 865 812 123 158 16" 143164 l n u m b e r 5 Yn 9 h et8888848 141 848 183 158 15" 165 144 158 141 162 1"1 812 124 131 182163 a B h o u d h a r Yn T S s8888868 143 812 c Yn8888862
$ Construct the commands toa Create a !ile !cmp1AseatBno "ith si6 lines containin' si6names([user43@linserver user43]$ vi fcm&1,244[user43@linserver user43]$ cat fcm&1,2449heta/e!ha/ildred9onal
i'itaisha
Department of Computer Science 22
7/25/2019 Linux Pracs
23/66
Kirti College T.Y.B.Sc. Linux
# .dd t"o more names and save the contents in !cmp$AseatBno([user43@linserver user43]$ c& fcm&1,244 fcm&2,244 ZZ cat >>fcm&2,244/inaln'it
[user43@linserver user43]$ cat fcm&2,2449heta/e!ha/ildred9onali'itaisha/inaln'it
c Sort the contents o! !ile !cmp1AseatBno([user43@linserver user43]$ sort fcm&1,244
n'it/e!ha/ildred/inali'itaisha9heta9onal
d ;isplay the names, "hich are common to !cmp1AseatBno, and!cmp$AseatBno([user43@linserver user43]$ comm fcm&1,244 fcm&2,2449heta/e!ha/ildred9onali'itaisha/inaln'it
e ;isplay the di!!erence #et"een !cmp1AseatBno and!cmp$AseatBno([user43@linserver user43]$ cat >> fcm&1,244bhishe'
[user43@linserver user43]$ diff fcm&1,244 fcm&2,244%d#P bhishe'
Department of Computer Science 23
7/25/2019 Linux Pracs
24/66
Kirti College T.Y.B.Sc. Linux
! .ppend the contents o! !cmp1AseatBno to !cmp$AseatBno andstore it in the !ile !cmp3AseatBno([user43@linserver user43]$ cat fcm&1,244 fcm&2,244 >fcm&3,244[user43@linserver user43]$ cat fcm&3,2449heta
/e!ha/ildred9onali'itaisha/inaln'it9heta/e!ha/ildred9onali'ita
isha/inaln'itbhishe'
' Sort the contents o! !cmp3AseatBno and display the contents"ithout and duplicate lines([user43@linserver user43]$ sort )u fcm&3,244bhishe'n'it/e!ha/ildred/inali'itaisha9heta9onal
3 Create t"o !iles named !cmp1 and !cmp$ "hich consists o! at least!ive lines "ith t"o or three similar lines( Construct the commands([user43@linserver user43]$ cat fcm&1This is fcm&1This is fcm&2This is uni* &racticalIractical on od
Iractical no 5
[user43@linserver user43]$ cat fcm&2This is fcm&1This is fcm&2This is 3rd lineUoodbeIractical no 5
Department of Computer Science 24
7/25/2019 Linux Pracs
25/66
Kirti College T.Y.B.Sc. Linux
.i Do check "hether the !iles di!!er([user43@linserver user43]$ cm& fcm&1 fcm&2fcm&1 fcm&2 differ bte 3"O line 3
ii Do compare the t"o !iles #yte to #yte([user43@linserver user43]$ cm& )l fcm&1 fcm&23" 165 633# 156 1623% 151 14448 1"8 4841 48 15442 168 15143 162 15644 141 14343 143 12. . .
5% 141 15168 154 14361 48 14162 15" 15463 156 4864 48 15666 144 486" 12 656# 128 12cm& CFJ on fcm&2
E >sin' di!!i Do display the lines "hich are common to #oth, the lines "hichare not common and to display the lines, "hich are common to #oth([user43@linserver user43]$ diff fcm&1 fcm&23O4c3O4P This is uni* &racticalP Iractical on od)))> This is 3rd line> Uoodbe
ii Do display the di!!erence in conte6t output !ormat([user43@linserver user43]$ diff )c fcm&1 fcm&2 fcm&1 2886)81)24 8%3821.888888888 78538
))) fcm&2 2886)81)24 8%3582.888888888 78538 1O5 This is fcm&1 This is fcm&2 This is uni* &ractical Iractical on od Iractical no 5
Department of Computer Science 25
7/25/2019 Linux Pracs
26/66
Kirti College T.Y.B.Sc. Linux
))) 1O5 )))) This is fcm&1 This is fcm&2 This is 3rd line Uoodbe Iractical no 5
iii Do display the uni!ied output !ormat([user43@linserver user43]$ diff )u fcm&1 fcm&2))) fcm&1 2886)81)24 8%3821.888888888 78538777 fcm&2 2886)81)24 8%3582.888888888 78538@@ )1O5 71O5 @@This is fcm&1This is fcm&2)This is uni* &ractical)Iractical on od7This is 3rd line7Uoodbe
Iractical no 5
C >sin' commi Do compare the !iles !cmp1 and !cmp$[user43@linserver user43]$ comm fcm&1 fcm&2 This is fcm&1 This is fcm&2 This is 3rd line Uoodbe Iractical no 5This is uni* &racticalIractical on odIractical no 5
ii Do display the lines "hich are uni?ue to !cmp1 and !cmp$[user43@linserver user43]$ comm )3 fcm&1 fcm&2 Uoodbe Iractical no 5This is uni* &racticalIractical on odIractical no 5
iii Do display the lines "hich are common to !cmp1 and !cmp$[user43@linserver user43]$ comm )12 fcm&1 fcm&2This is fcm&1
This is fcm&2This is 3rd line
; >sin' n1 to 'ive the line num#ers to lines in !cmp1([user43@linserver user43]$ nl fcm&1 1 This is fcm&1 2 This is fcm&2 3 This is uni* &ractical
Department of Computer Science 26
7/25/2019 Linux Pracs
27/66
Kirti College T.Y.B.Sc. Linux
4 Iractical on od 5 Iractical no 5
@ >sin' cat to append the !cmp1 to !cmp$ and sort this appended!cmp$ and store it in a !ile named !uni?1[user43@linserver user43]$ cat fcm&1
HelloHiUood/ornin!Uoodi!htUood e
[user43@linserver user43]$ cat fcm&2HelloHiUood/ornin!Uoodi!htUood e
HelloHiUood/ornin!Uoodi!htUood e
[user43@linserver user43]$ cat fcm&1 fcm&2 sort > funiW1[tbsc2%"@linserver tbsc2%"]$ cat funiW1Uood eUood eUood eUood/ornin!Uood/ornin!Uood/ornin!Uoodi!htUoodi!htUoodi!htHelloHelloHelloHiHiHi
Department of Computer Science 2
7/25/2019 Linux Pracs
28/66
Kirti College T.Y.B.Sc. Linux
F >sin' uni?i Do remove the duplicate lines in !uni?1[user43@linserver user43]$ uniW funiW1Uood eUood/ornin!
Uoodi!htHelloHi
ii Do count the duplications and prepend num#er to each line[user43@linserver user43]$ uniW )c funiW1 3 Uood e 3 Uood/ornin! 3 Uoodi!ht 3 Hello 3 Hi
iii Do display the duplicate lines only[user43@linserver user43]$ uniW )d funiW1Uood eUood/ornin!Uoodi!htHelloHi
iv Do display uni?ue lines only[user43@linserver user43]$ uniW funiW1Uood eUood/ornin!Uoodi!htHelloHi
% Create a !ile nameArollBno "ith !ields!irst name, second name,last name, salaryseparated #y
7/25/2019 Linux Pracs
29/66
Kirti College T.Y.B.Sc. Linux
i Sort on !irst names only([user43@linserver user43]$ sort 71 )2 9heta244nuBhandu/enon38888:ili&Bhandu/ehra68888/ildredJeli*:
7/25/2019 Linux Pracs
30/66
Kirti College T.Y.B.Sc. Linux
i Cut !irst t"o columns !rom !cut1 and store the contents in the!ile cutlist1 and cut the second and third columns !rom the !cut$and store it in cutlist$([user43@linserver user43]$ cut )c 1)2 fcut1 >> cutlist1[user43@linserver user43]$ cat cutlist1
'lHa/aa
[user43@linserver user43]$ cut )c 2)3 fcut2 >> cutlist2[user43@linserver user43]$ cat cutlist2hihihioo
ra
ii Paste the contents o! cutlist$ to contents o! cutlist1([user43@linserver user43]$ &aste cutlist2 >> cutlist1[user43@linserver user43]$ cat cutlist1'lHa/aahihihioora
Dranslate the !irst three lines into capital letters usin' trcommand([user43@linserver user43]$ head )3 fcut1 fcut2 tr JBT2 P
THA9 A9 JB/I1THA9 A9 JB/I2THA9 A9 3?: DAC
Department of Computer Science 3#
7/25/2019 Linux Pracs
31/66
Kirti College T.Y.B.Sc. Linux
Practical No )
rep,e'rep,!'rep:. Create the !ile "ith the name 're1 and the !ollo"in' contents:[user43@linserver user43]$ cat !re1This is a first line.
This is a second line.Ilease t&e the third line.:o ou ish to continue9im&l t&e the fourth line.
E Create the !ile "ith the name 're$ and the !ollo"in' contents:[user43@linserver user43]$ cat !re2The !re& is an acronm for
use shell metacharactersO or re!ular e*&ressions as &rofessional uni* users call them.
C ;o the !ollo"in':1 Search the "ord 7line8 and display the lines containin' it([user43@linserver user43]$ !re& line !re1This is a first line.This is a second line.Ilease t&e the third line.9im&l t&e the fourth line.
$ Search the "ord 7the or Dhe8 in #oth the !iles 're1 and 're$ anddisplay the lines containin' it([user43@linserver user43]$ !re& the !re1 !re2!re1Ilease t&e the third line.!re19im< t&e the fourth line.!re2The command searches the s&ecified in&t !loball for a matchith the s&ecified &attern and dis&las it.Khile formin! the &attern to be searched ecan use shell metacharactersO or re!ular e*&ressions as &rofessional uni* users callthem.
[user43@linserver user43]$ !re& The !re1 !re2!re2The !re& is an acronm for
e*&ression and &rint it
7/25/2019 Linux Pracs
32/66
Kirti College T.Y.B.Sc. Linux
3 Search !or % letters in 're1 and 're$ "hose !irst character is7r8and last character is 7r8[user43@linserver user43]$ !re& r......r !re1 !re2!re2The command searches the s&ecified in&t !loball for a matchith the s&ecified &attern and dis&las it.Khile formin! the &attern to be
searched e can use shell metacharactersO or re!ular e*&ressions as &rofessional uni*users call them.
% ;isplay the lines, "hich end "ith the characters !rom s to 9 !rom're1 and 're$[user43@linserver user43]$ !re&
7/25/2019 Linux Pracs
33/66
Kirti College T.Y.B.Sc. Linux
[user43@linserver user43]$ !re& )c H?: em&data2442
@ Create a !ile studentAsaetno "ith the !ollo"in' !ields:[user43@linserver user43]$ cat 9tudent2449819heta^115588
982/e!ha^121488983/ilu^133288984nu^112188985n'it^154388
i ;isplay the details o! student in order o! their name i'norin'case([user43@linserver user43]$ sort )i )t 71 )2 9tudent244985n'it^154388984nu^112188982/e!ha^121488983/ilu^133288
9819heta^115588
ii ;isplay the details o! student "hose num#er o! modules is'reater than 3([user43@linserver user43]$ !re&
7/25/2019 Linux Pracs
34/66
7/25/2019 Linux Pracs
35/66
Kirti College T.Y.B.Sc. Linux
3 Do check "hether the !ile "ith he name entered e6ists or not(
[user43@linserver user43]$ cat filee*istsecho enter filenameread filenameif [ )s $filename ]
then echo file e*istselse echo does not e*istsfi
Hutput
[user43@linserver user43]$ bash filee*itsenter filename!reena&&lefile e*ists
% Do compare the t"o strin's([user43@linserver user43]$ cat strin!com&areecho enter a strin!1read strin!1echo enter another strin!2read strin!2if [ $strin!1 $strin!2 ]then echo strin!s matchelse
echo strin!s do not matchfi
Hutput
[user43@linserver user43]$ bash strin!com&areenter a strin!1ni*enter another strin!2ni*strin!s match
Department of Computer Science 35
7/25/2019 Linux Pracs
36/66
7/25/2019 Linux Pracs
37/66
Kirti College T.Y.B.Sc. Linux
Hutput
[user43@linserver user43]$ bash !radesenter our mar's15#
enter belo 188
*Do check "hether the num#er is ve or Jve usin' i!Keli!(
[user43@linserver user43]$ cat 18nosecho enter a numberread aif [ $a )lt 8 ]then echo $a is ne!ativeelif [ $a )!t 8 ]then
echo $a is &ositiveelse echo number is neither &ositive nor ne!ativefi
Hutput
[user43@linserver user43]$ bash 18nosenter a number5555 is &ositive
+ Do print the day o! "eek usin' case Kin[user43@linserver user43]$ cat &ract".%echo enter a value for a daread dcase $d in1N echo /onda__2N echo Tuesda__3N echo Kednesda__4N echo Thursda__5N echo Jrida__6N echo 9aturda__"N echo 9unda__N echo Anvalid :a umberesac
Department of Computer Science 3
7/25/2019 Linux Pracs
38/66
Kirti College T.Y.B.Sc. Linux
Hutput
[user43@linserver user43]$ bash &ract".%enter a value for a da6
9aturda
0 Do !ind the type o! the character entered(
[user43@linserver user43]$ cat &ract".18echo enter the characterread charcase $char in[a)+] Necho Sou have entered small case__[)=] Necho Sou have entered ca&ital case__
[8)%] Necho Sou have entered number__Necho Sou have entered a s&ecial character__Necho Sou have entered more the one character__esac
Hutput
[user43@linserver user43]$ bash &ract".18enter the characteraSou have entered small case
1 Do !ind the pattern o! the strin' entered usin' caseKin(
[user43@linserver user43]$ cat &ract".11echo enter the strin!read scase $s in[aeiou]Necho The 9trin! be!ins ith a small case voel__[CAF]Necho The 9trin! be!ins ith a ca&ital case voel__
[8)%]Necho The 9trin! be!ins ith a di!it__[8)%]Necho The 9trin! ends ith a di!it__Necho Sou entered a five letter ord__esac
Department of Computer Science 3!
7/25/2019 Linux Pracs
39/66
Kirti College T.Y.B.Sc. Linux
Hutput
[user43@linserver user43]$ bash &ract".11enter the strin!iThe 9trin! be!ins ith a small case voel
11 Do !ind the type o! the !ile(
[user43@linserver user43]$ cat &ract".12echo enter the filenameread filenameif [ )f $filename ]then echo At is a file if [ )c $filename ] then echo At is a charcter s&ecial file
elif [ )b $filename ] then echo At is a bloc' s&ecial file else echo Jormat not reconi+ed fielif [ )d $filename ]then echo At is a directorelse echo The file or director doesnt e*istfi
Hutput
[user43@linserver user43]$ bash &ract".12enter the filename&ract".1At is a fileJormat not reco!ni+ed
1$ Do prepare a menu driven pro'ram(
[user43@linserver user43]$ cat &ract".13echo Iress 1 to see the or'in! director
echo Iress 2 to create ne file ith some contentsecho Iress 3 to see Bontents of the directorecho Iress 4 to sort a fileecho Iress 5 to see all users lo!!ed inecho Cnter Sour choiceread acase $a in
Department of Computer Science 3"
7/25/2019 Linux Pracs
40/66
Kirti College T.Y.B.Sc. Linux
1N Y&d__2N echo Cnter the filename read n Ycat > $n
__3N Yls dir1__4N echo enter the filename read f Ysort $f__5N Yho__N echo Cntr made is not valid__esac
Hutput
[user43@linserver user43]$ bash &ract".13Iress 1 to see the or'in! directorIress 2 to create ne file ith same contentsIress 3 to see Bontents of the directorIress 4 to sort a fileIress 5 to see all users lo!!ed inCnter Sour choice1(home(tbsc244
13 Do print !irst n num#er and their sum usin' "hile loop to print(
[user43@linserver user43]$ cat loo&echo enter the numberread dn1sum8
hile [ $n )le $d ]
do
echo $nsumQ e*&r $sum 7 $n Q
nQ e*&r $n 7 1 Qdoneecho The sum of $d nos is $sum
Department of Computer Science 4#
7/25/2019 Linux Pracs
41/66
Kirti College T.Y.B.Sc. Linux
Hutput
[user43@linserver user43]$ bash loo&enter the number121
23456"#%181112The sum of 12 nos is "#
1% Do call another !ile(
[user43@linserver user43]$ cat &ract".15echo Iress 1 to Bom&are the 9trin!echo Iress 2 To chec' heteher number is 7ve and )veecho Iress 3 To Fbtain sum of and &roduct to numbersread fcase $f in1N bash &ract".4__2Nbash chec'
__3Nbash &ract".1__Necho Anvalid entr__esac
Hutput
[user43@linserver user43]$ bash &ract".15Iress 1 to Bom&are the 9trin!Iress 2 To chec' heteher number is 7ve and )veIress 3 To Fbtain sum of and &roduct to numbers2Cnter an o)5The no. is ne!ative
Department of Computer Science 41
7/25/2019 Linux Pracs
42/66
Kirti College T.Y.B.Sc. Linux
1& Do print the !irst n num#ers and their sum usin' doKuntil
[user43@linserver user43]$ cat &ract".16echo Cnter The first n nos. usin! untilread ni1
sum8
until [ $i )!t $n ]doecho $isumQe*&r $sum 7 $iQiQe*&r $i 7 1Qdoneecho The 9um of $n nos is $sum
Hutput
[user43@linserver user43]$ bash &ract".16Cnter The first n nos. usin! until12123456"#%181112The 9um of 12 nos is "#
1) Do demonstrates the use o! !or loop(
[user43@linserver user43]$ cat &ract".1"echo The Jirst 18 nos usin! Jor loo&n8sum8for n in 1 2 3 4 5 6 " # % 18do
echo $nsumQe*&r $sum 7 $n Qdoneecho The sum Ff 18 nos is $sum
Hutput
The Jirst 18 nos usin! Jor loo&
Department of Computer Science 42
7/25/2019 Linux Pracs
43/66
Kirti College T.Y.B.Sc. Linux
123456
"#%18The sum Ff 18 nos is 55
Jor loo& usin! command line ar!uments[user43@linserver user43]$ cat commandforfor f in $do echo $fdone
Hutput[user43@linserver user43]$ bash commandfor 1 2 3123
1* Do display the directories and !iles(
[user43@linserver user43]$ cat &ract".1#ls
Hutput
[user43@linserver user43]$ bash &ract".1# fcm&2 lo!in &ract".1 &ract#.11.csaffron 71 fcm&22#% loo& &ract".18sam&le 18888 fcm&23%" me!ha &ract#.11.out
&ract".11 &ract#.12.3 schec' 5 fcm&2#%/e!ha2#% &ract".12 &ract#.1.a dir3 .5&ract".6 &rime.out us1 e!! &ract8#.2&ract"." &roduct2#% hite em&data2#% !reen&&le&ract11.a &ract".% &schec' or'b&buni*boolsfcm&1 head &ract11.a.c &ract#.1 resultfcm&12#% icecream &ract4.5 &ract#.11 result1
Department of Computer Science 43
7/25/2019 Linux Pracs
44/66
Kirti College T.Y.B.Sc. Linux
Practical no( +
.;L.NC@; SG@55 P/H/.22IN II
@6(1.rite a shell script to 'enerate the !ollo"in' series
1,3,$,%,3,&,%,)KKKK1rite do"n the shell script in the ans"er sheet( @6ecute it andsho" it to the e6aminer(
[user43@linserver user43]$ cat &ract#.1.ai1-3hile [ $i )le 11 ]doecho $iecho Qe*&r $i 7 2 QiQ e*&r $i 7 1 Qdone
Hutput
[user43@linserver user43]$ bash &ract#.1.a132435465"6#"%#18
Department of Computer Science 44
7/25/2019 Linux Pracs
45/66
Kirti College T.Y.B.Sc. Linux
Eive a command to display the !ollo"in' the !ollo"in' results: 1 Dhe day is: mmddyy $ Dhe "eekday is: name o! the "eekday/eplace the #rackets "ith the actual valuesrite do"n the commands in the ans"er sheet( @6ecute them andsho" it to the e6aminer(
[user43@linserver user43]$ cat dateset QdateQread mcase $m in;anNm81__JebNm82__/arNm83__&rNm84__
/aNm85__;unNm86__;ulNm8"__u!Nm8#__9e&Nm8%__FctNm18__ovNm11__:ecNm12__esacecho :ate is $m)$3)$6echo Kee' da is $1
Hutput
[user43@linserver user43]$ bash date&r:ate is 84)2)2886
Kee' da is Thu
Department of Computer Science 45
7/25/2019 Linux Pracs
46/66
Kirti College T.Y.B.Sc. Linux
@6($.i ive correct command to the !ollo"in'
1( ;isplay your current "orkin' directory($( 5ist all !iles startin' "ith letter 7C8(3( ;isplay your terminal address(
%( Create a su#directory CH2PAseatno(Chan'e to thisdirectory M create t"o !iles comp1 Aseatno1 and
Aseatno$(&( 2ake a copy o! !ile comp$Aseatno$ into !ile
comp3Aseatno3(;isplay their inode num#ers( rite do"n the commands in the ans"er sheet( @6ecute them andsho" it to the e6aminer([user43@linserver user43]$ cat &ract#.2.1echo Sou have folloin! o&tionsecho 1. :is&la our current or'in! directorecho 2. Dist all files startin! ith letter cecho 3. :is&la our terminal address
echo 4. Bhan!e to director BF/I383 and create filesecho 5. Bo& file com&2383 into file com&3383 and dis&la inodenumberecho Cnter our choiceread ccase $c in1Necho ou are or'in! on&d__2Nls c__3Ntt__4Ncd BF/I383echo Bhan!ed to director BF/I383echo Cnter to file namesread f1read f2touch $f1 $f2echo Jiles created__5Nc& com&2383 com&3383echo Jile co&iedcat com&3383ls )i com&2383 com&3383
__esac
Department of Computer Science 46
7/25/2019 Linux Pracs
47/66
Kirti College T.Y.B.Sc. Linux
Hutput
[user43@linserver user43]$ bash &ract#.2.1Sou have folloin! o&tions1. :is&la our current or'in! director
2. Dist all files startin! ith letter c3. :is&la our terminal address4. Bhan!e to director BF/I383 and create files5. Bo& file com&2383 into file com&3383 and dis&la inode numberCnter our choice5Jile co&iedThis is file com&2383Iractical no #1856#4% com&2383 1856#4# com&3383
ECreate a shell script to print summation o! !ollo"in' series
1 $ 3 % & ------- Nrite do"n shell script in the ans"er sheet( @6ecute it and sho"it to the e6aminer(
[user43@linserver user43]$ cat &ract#.2i1fact1sum8echo Cnter valuesread nhile [ $i )le $n ]do factQe*&r $fact Y $iQ
iQe*&r $i 7 1Q sumQe*&r $sum 7 $factQ echo $factdoneecho The sum of the factorial $n is $sum
Hutput
[user43@linserver user43]$ bash &ract#.2Cnter values51
2624128The sum of the factorial 5 is 153
Department of Computer Science 4
7/25/2019 Linux Pracs
48/66
Kirti College T.Y.B.Sc. Linux
@6(3.rite a shell script, "hich displays num#er o! ordinary !iles,directories and special !iles in the current "orkin' directory(
rite do"n the shell script on the ans"er sheet( @6ecute it and sho"it to the e6aminer([user43@linserver user43]$ cat filet&e
echo Cnter a filenameread filenameif [ )f $filename ]then echo Cntered a file name if [ )s $filename ] then echo Jile of len!th !reater than 8 elif [ )c $filename ] then echo 9&ecial character file elif [)b $filename ]
then echo loc' s&ecial file else echo Jile not su&&orted fi
elif [ )d $filename ]then echo entered a directorelse echo Anvalid namefi
Hutput
[user43@linserver user43]$ bash filet&eCnter a filename!reena&&leCntered a file nameJile of len!th !reater than 8
@6(%
.rite a shell script to create a !ile, "hich stores the names o!the !iles and a'ainst each name, put either 7mornin'8, 7evenin'8 or7a!ternoon8 dependin' upon the time "hen !ile "as created( rite ashell script in ans"er sheet, e6ecute it and sho" it to thee6aminer([user43@linserver user43]$ cat time1echo Cnter Jile nameread fhrsQls )l !re& $fcut )d )f 1%cut )c1O2Qecho $hrs
Department of Computer Science 4!
7/25/2019 Linux Pracs
49/66
Kirti College T.Y.B.Sc. Linux
if [ $hrs )lt 12 )a $hrs )!e 8 ]then echo Qls )l !re& $fQ /ornin!elif [ $hrs )lt 16 )a $hrs )!e 12 ]then echo Qls )l !re& $fQ fternoon
elif [ $hrs )lt 1% )a $hrs )!e 16 ]then echo Qls )l !re& $f Q Cvenin!else echo Qls )l !re& $f Q i!htfi
Hutput
[user43@linserver user43]$ bash time1Cnter Jile name
time111)r)r))r)) 1 tbsc244 tbsc 3"2 ;an 25 1115 time1 /ornin!
@6(&Create a !ile named studentAseatno "ith !ields /ollno, Studentname, 2arks( Fields are separated "ith a colon :(
rite a shell script to per!orm the !ollo"in' options1( Print the content o! he !ile($( ;elete the 'iven !ile3( /ename the !ile
%( I! a#ove three are not there then print error messa'e(rite do"n the commands in the ans"er sheet, e6ecute it andsho" it to the e6aminer(
[user43@linserver user43]$ cat &ract#.5echo Ilease enter ur choiceecho Iress 1 to &rint the contents of the fileecho Iress 2 to delete the !iven fileecho Iress 3 to rename the fileread necho Ilease enter the e*istin! filenameread fnamecase $n in1Ncat $fname __2Nrm $fnameecho $fname has been deleted __3Necho enter the ne filenameread nenamemv $fname $nename
Department of Computer Science 4"
7/25/2019 Linux Pracs
50/66
Kirti College T.Y.B.Sc. Linux
echo $fname has been re&laced ith $nename __Necho this is invalidesac
Hutput
[user43@linserver user43]$ bash &ract#.5Iress 1 Irint the contents of the fileIress 2 :elete the !iven fileIress3 ?ename the fileCnter Sour Bhoice1enter the filenamehiteThis Jile Bontainshelooo this a hite filea !ood hite file
@6(). rite a shell script, "hich allo"s the user to add uni?ue
records in the !ile productAseatno !ields are product code,product name, price and ?uantity on hand(Insert at least fiverecords in the productAseatno!ile(rite do"n shell script in the ans"er sheet( @6ecute it and sho"it to the e6aminer(
[user43@linserver user43]$ cat &ract#.6echo enter the &roduct idread id
echo enter the &roduct nameread name
echo enter the &riceread &rice
echo enter the &roduct Wtread Wt
lineQecho $id$name$&rice$WtQnQ!re& $id &roduct2#% c )lQif [ $n )!t 8 ]
then echo Bant enter du&licate recordelse echo $line >> &roduct244 echo ?ecord enteredficat &roduct2#%
Department of Computer Science 5#
7/25/2019 Linux Pracs
51/66
Kirti College T.Y.B.Sc. Linux
Hutput
[user43@linserver user43]$ bash &ract#.6enter the &roduct id84enter the &roduct name
lmnenter the &rice%8enter the &roduct Wt#?ecord entered81abc18281abc128%82&Wr28183bcd282884lmn%8#
@6(*.rite a shell script that asks the user to input a num#er N anddisplays the s?uares o! al num#ers !rom 1 to N as !ollo"s(
1 s?uare O BBBBBBB $ s?uare O BBBBBBB ( ( N s?uare O BBBBBBB
rite do"n the shell script in the ans"er sheet, e6ecute it andsho" it to the e6aminer(
[user43@linserver user43]$ cat &ract#."echo enter the number read i1sWr1hile [ $i )le $ ]dosWrQ e*&r $i Y $i Qecho $i sWuare $sWriQ e*&r $i 7 1Qdone
Hutput
[user43@linserver user43]$ bash &ract#."enter the number 51 sWuare 12 sWuare 43 sWuare %4 sWuare 165 sWuare 25
Department of Computer Science 51
7/25/2019 Linux Pracs
52/66
Kirti College T.Y.B.Sc. Linux
@6(+.enerate a shell script, "hich accepts a user name( I! user is
not present then appropriate messa'e should #e displayedother"ise tell the user to lo'out out( ait !or & seconds andthen kill the 'iven user8s 4o#s(
NHD@: >ser "ill #e provided #y the e6aminer(
rite do"n the shell script in the ans"er sheet, e6ecute it andsho" it to the e6aminer(Create a !ile named !ile Aseatno o! your choice and try that'rep command to search !or the !ollo"in' patterns alon' "ith the!ollo"in' options(
1( Do print only a count o! line that contains apattern(
$( I'nore uppercaselo"ercase distinction durin'comparison(
3( Print all lines e6cept those contain a pattern(rite do"n the commands in the ans"er sheet, e6ecute them andsho" it to the e6aminer(
[user43@linserver user43]$ cat &ract#.#echo enter the usernameread usho >> us1nQ!re& $us us1 c )l Qif [ $n )!t 8 ]thenecho Sou are valid userelseecho Anvalid userfi
Hutput
[user43@linserver user43]$ bash &ract#.#enter the usernametbsc244Sou are valid user[user43@linserver user43]$ bash &ract#.#enter the usernametbsc288Anvalid user
Department of Computer Science 52
7/25/2019 Linux Pracs
53/66
Kirti College T.Y.B.Sc. Linux
@6(0.enerate a shell script that "ill check !or every minute, ho"
many users lo''ed in(rite do"n shell script in the ans"er sheet, e6ecute it and sho"it to the e6aminer(
[user43@linserver user43]$ cat &ract#.%LTo Bhec' Khether ho man users have lo!!ed in ever minuteecho Cnter the timeread timetQho cut )c 38O31O32O33O34 !re& )c $timeQecho The umber of users ho lo!!ed in at $time $t
Hutput
[user43@linserver user43]$ bash &ract#.%Cnter the time1546
The umber of users ho lo!!ed in at 1546 3
@6(1.rite a shell script to 'enerate prime series up to N( rite do"n shell script in the ans"er sheet, e6ecute it and sho"it to the e6aminer([user43@linserver user43]$ cat &ract#.11.c
LincludePstdio.h>
LincludePmath.h>
mainMvoidN
`int noOiO-O&rime1Om_
&rintfMenter a number N_
scanfMdOZnoN_
if Mno1N
&rintfM1 is a &rimeN_
if Mno2N
&rintfM2 is a &rime numberN_
if Mno28N
&rime8_
Department of Computer Science 53
7/25/2019 Linux Pracs
54/66
Kirti College T.Y.B.Sc. Linux
else
`
forMi3_iPno_ii72N
` &rime1_
forMm3_mPMno(2N_mm72N
`
ifMnoi8N
`
&rime8_
brea'_
if M&rime1N
&rintfMYnd is a &rime numberOiN_
Hutput
[user43@linserver user43]$ !cc )o &rimeo.out &ract#.11.c[tbsc2#%@linserver tbsc2#%]$ .(&rimeo.outCnter the no 1135"
Department of Computer Science 54
7/25/2019 Linux Pracs
55/66
Kirti College T.Y.B.Sc. Linux
@6(11. rite a shell script to !ind C;M 5C; o! t"o positive num#ers(
rite do"n shell script in the ans"er sheet, e6ecute it and sho"it to the e6aminer(echo enter to numbers
read a b&rodQe*&r $a Y $b bc )l Qif [ $a )lt $b ]then tem&$a a$b b$tem&firQ e*&r $a $b Qhile [ $r )!t 8 ]do a$b
b$r rQ e*&r $a $b Qdoneecho UB: $bDB/Qe*&r $&rod ( $b bc )l Qecho DB/ $DB/
Hutput[user43@linserver user43]$ bash !cdenter to numbers38 5#UB: 2DB/ #"8
E rite a shell script "hich takes t"o ar'uments( Dhe !irstar'ument is a pattern M second is a !ilename (Check "hether the
pattern supplied is !ound in the !ile or not( I! !ound store itin other !ile named outputAseatno and display the content o!output !ile "ith line num#ers(
rite do"n shell script in the ans"er sheet, e6ecute it and sho"it to the e6aminer(
[user43@linserver user43]$ cat &ract#.12.3
if [ $L )!t 2 )o $L )lt 2 ]then
echo Kron! ar!umentselif [ )f $2 ]then echo Q!re& )n $1 $2Q >> resultcat resultelse echo Jile does not e*istfi
Department of Computer Science 55
7/25/2019 Linux Pracs
56/66
Kirti College T.Y.B.Sc. Linux
Hutput[user43@linserver user43]$ bash &attern1 a&&le !reena&&le1223343"""1223343"""asda'-'-dh'e
2asda'-'-dh'e2asda'-'-dh'e1i am a&&le 2then i am !reena&&le
@6 1$rite a shell script,"hich acceptes a month num#er , and printcorrespondin' month name([user43@linserver user43]$ cat month1echo enter month numberread ncase $n in 1Necho ;anuar
__2Necho Jebruar__3Necho /arch__4Necho &ril__5Necho /a__6Necho ;une__"Necho ;ul__#Necho u!ust__%Necho 9e&tember__18Necho Fctober__11Necho ovember__12Necho :ecember__Necho Anvalid /onth
__Csac
Hutput[user43@linserver user43]$ bash month1enter month number1;anuar
Department of Computer Science 56
7/25/2019 Linux Pracs
57/66
Kirti College T.Y.B.Sc. Linux
@6(13 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR.Create the !ollo"in' !iles usin' 'iven !ields( Fields are
separated #y a colon : 2asterdataAseatno Product num#er,product name, rate, description, supplier code,Supplier name, supplier address
DransdataAseatno Product num#er, customer code, customer name, unit sold, rate o! sale, date o! sale( Insert at least threerecords in each !ile and "rite a shell
script to display !ollo"in' menu: 1: Product Query $: CustomerQuery @6it@nter choice -$:I! the choice is 1, 'et the customer num#er !rom the user anddisplay all records "ith this product num#er !rom the !ile
masterdataAseatno, and then ask the user i! heshe "ants to?uery on another product( I! the ans"er is no, the user should #ereturned to main menu(I! the choice is $, 'et the customer num#er !rom the user and
display all transactions pertainin' to this customer !rom the!ile transdataAseatno(I! the choice is , the user shall return to shell prompt(I! choice is other than -$ then an error messa'e should #edisplayed and the choice is re-accepted( rite do"n shell script in the ans"er sheet, e6ecute it andsho" it to the e6aminer(
[user43@linserver user43]$ cat Iract14echo Iress 1 &roduct Wuerecho Iress 2 customer Wuerecho Iress 8 for e*itread ncase $n in1Nhile [ $result ]doecho enter &roduct noread &noecho Qcut )f 1 /asterdata !re& $&noQecho
7/25/2019 Linux Pracs
58/66
Kirti College T.Y.B.Sc. Linux
Hutput
$a%ter&ata
[user43@linserver user43]$ cat /asterdata81abc18*+c881defbbbb
82uuu18&&&c882llloooo83'''11hhhc883ttttiiii
Dransdata
[user43@linserver user43]$ cat Transdata81Bust81sheta832822;an288582Bust82/ilu832521Fct288683Bust83nu842411&r2884
eneral Hutput
Iress 1 &roduct WuerIress 2 customer WuerIress 8 for e*it1enter &roduct no8383'''11hhhc883ttttiiii:o u ant to chec' an other &roductM(nNnIress 1 &roduct WuerIress 2 customer WuerIress 8 for e*it
2enter customer noBust8181Bust81sheta832822;an28851:o u ant to chec' an other customerM(nNnIress 1 &roduct WuerIress 2 customer WuerIress 8 for e*it
Department of Computer Science 5!
7/25/2019 Linux Pracs
59/66
Kirti College T.Y.B.Sc. Linux
Practical No 0
@ditors In 5inu6Part I
vi editor
Create a !ile "ith the name !vi1 "ith atleast 1 lines([user43@linserver user43]$ vi fvil
1 Per!orm the vi commands to the !ollo"in' cursor movements:- 3 "ords to the ri'ht 3
- % "ords to the le!t 4b
- Eottom o! screen D
- Ee'innin' o! current line F
- Ee'innin' o! the !ile H
- @nd o! current line $
- @nd o! the line U
$ Per!orm the vi commands to do the !ollo"in' deletions:- character at the cursor *
- one "ord !rom the current positiond
- current line dd
- ne6t % lines 4dd
- line to the le!t o! cursor d8
- line to the ri'ht o! cursor d$
Department of Computer Science 5"
7/25/2019 Linux Pracs
60/66
Kirti College T.Y.B.Sc. Linux
Part II@6 line editorCreate a !ile "ith the name !e61 havin' the contents as !ollo"s:;o the !ollo"in':1 Invoke this !ile !rom e6 mode
[user43@linserver user43]$ e* fe*1
$ ive line num#ers to the lines o! included in the !ile set nu
3 ;elete the last line dd
% Copy the !irst line a!ter the last line $ then 1&
& Copy lines $ to & a!ter the last line
e4 e&
) ;elete the line 1 to & e5dd* .ppend the lines ) to 1 to this line e3 e&
+ Dry out various options to #rin' the !ile in the ori'inal ordero! line num#ers set nu
0 /eplace all occurrences o! the "ord is "ith IS !rom the !irstline to the end o! !ile sed 1O$ s(is(A9(! fe*1
1 /eplace all occurrences o! the "ord !or "ith FH/ !rom the!ollo"in' lines o! the para'raph you have already typed sed 1O18 s(for(JF?(! fe*1
Part IIIsed editorCreate a !ile "ith !ive records "ith the name !sed1 and do the!ollo"in' usin' sed command:[user43@linserver user43]$ cat fsed1This is file fsed1
this is cat command.hello.hi.tbsc.
1 ;isplay !irst three lines[user43@linserver user43]$ sed )n
7/25/2019 Linux Pracs
61/66
Kirti College T.Y.B.Sc. Linux
this is cat command.hello.
$ ;isplay the last line[user43@linserver user43]$ sed )n
7/25/2019 Linux Pracs
62/66
Kirti College T.Y.B.Sc. Linux
Practical No 1
1 5ink to the !ile :ln. Create t"o !iles "ith some contents "ith name ln1([user43@linserver user43]$ vi ln1[user43@linserver user43]$ cat ln1
This is file ln1Iractical no 18
E Copy ln1 to ln$([user43@linserver user43]$ c& ln1 ln2[user43@linserver user43]$ cat ln2This is file ln1Iractical no 18
C Create a hard link to as
7/25/2019 Linux Pracs
63/66
Kirti College T.Y.B.Sc. Linux
hat is your conclusionTHard lin' Hardln1 shos the content as deletin! the file ln1.ut 9oft lin' 9oftln1 does not shos the content as ori!inal fileis deleted.
$ File Permissions: chmod. Construct the command to check the permissions o! all the !ilesand directories on your current "orkin' directory([user43@linserver user43]$ ls )l Hardln1 9oftln1)r)r))r)) 2 tbsc2#% tbsc 33 Jeb 3 1143 Hardln1lr*r*r* 1 tbsc2#% tbsc 3 Jeb 3 114% 9oftln1 )>ln1
Chan'e the permissions o! the !iles or directories usin'i"ei'ht notations % $ 1[user43@linserver user43]$ chmod 421 ln1[user43@linserver user43]$ ls )l ln1
)r))))))* 2 tbsc244 tbsc 33 Jeb 3 1143 ln1
iisym#ol notations r " 6!or di!!erent 'roups u-o"ner, '-'roup users, o-others
3 Construct the commands. Do see the process runnin' on your terminal([user43@linserver user43]$ &s T IA: TTS 9TT TA/C BF//:2461 &ts(8 9 888 )bash53%" &ts(8 ? 888 &s T
E Do see the detailed listin' o! processes runnin' on yourterminal([user43@linserver user43]$ &s )fA: IA: IIA: B 9TA/C TTS TA/C B/:tbsc2#% 2461 243% 8 8#35 &ts(8 888888 )bashtbsc2#% 5411 2461 8 1216 &ts(8 888888 &s Vf
C Do see the process run #y a particular user([user43@linserver user43]$ &s )u tbsc383 IA: TTS TA/C B/:2%"3 &ts(1 888888 bash
; Do see the process run #y all the users connected in the net"ork(
[user43@linserver user43]$ &s )f )a moreA: IA: IIA: B 9TA/C TTS TA/C B/:ashini 5#18 566% 8 1241 &ts(5 888888 man lsashini 5#14 5#13 8 1241 &ts(5 888888 sh )c Mcd(usr(share(man ZZ Mecashini 5#21 5#14 8 1241 &ts(5 888888 (usr(bin(less )isrtbsc2#% 5#26 2461 8 1241 &ts(8 888888 &s )f )atbsc2#% 5#2" 2461 8 1241 &ts(8 888888 more
Department of Computer Science 63
7/25/2019 Linux Pracs
64/66
Kirti College T.Y.B.Sc. Linux
@ Do see all the system process([user43@linserver user43]$ &s )f )u rootA: IA: IIA: B 9TA/C TTS TA/C B/:root 1 8 8 8#33 888884 initroot 2 1 8 8#33 888888 ['eventd]
RRR..RRR..
root 5443 21%# 8 1228 888888 in.telnetd1%2.16#.188.32root 5446 5443 8 1228 888888 [lo!in]root 54#2 21%# 8 1221 888888 in.telnetd1%2.16#.188.32root 54#" 54#2 8 1221 888888 [lo!in]
%Construct the command.Do mount the !loppy and C;/H2([root@linserver mnt]L mount )v flo&&
(dev(fd8 An&ut(out&ut error-mount ou didn
7/25/2019 Linux Pracs
65/66
Kirti College T.Y.B.Sc. Linux
&System .dministration JPartI Construct the commands to
.5o'in as a root user([user43@linserver user43]$ suIassord
[root@linserver root]L
ECreate t"o users
7/25/2019 Linux Pracs
66/66
Kirti College T.Y.B.Sc. Linux
@Chan'e the 'roup o! !ile and directories o! di!!erent users([user43@linserver user43]$ ls )l student)r)r))r)) 1 tbsc2%1 tbsc 18% ;an 1% 115# student
[root@linserver user43]L ch!r& ashini (home(tbsc2%1(student
[user43@linserver user43]$ ls )l student)r)r))r)) 1 tbsc2%1 ashini 18% ;an 1% 115# student
FConstruct the command to chan'e !orm one particular user toother user([root@linserver user43]L su tbsc2%1[user43@linserver user43]$ &d(home(tbsc2#%[user43@linserver user43]$ cd (home(tbsc2%1[user43@linserver user43]$
Chan'e the status o! the normal user to the super user([user43@linserver user43]$ suIassord[root@linserver root]L
GChan'e the pass"ord o! the normal user([user43@linserver user43]L &assd tbsc388Bhan!in! &assord for user tbsc388.e &assord?et&e ne &assord&assd all authentication to'ens u&dated successfull.