UNIX NOTE BOOK - Raj Sekhar ANna
UNIX NOTE BOOK - Raj Sekhar ANna
UNIX NOTE BOOK - Raj Sekhar ANna
UNI
X
SDLC(
sof
twar
edev
elopmentl
i
fecy
cle)
1.Requi
rementanal
ysi
s
2.Desi
gn
3.Dev
elopment
4.Test
ing
5.Mai
ntai
ns/
suppor
t
Pr
oduct
ionsuppor
t/Appl
i
cat
ionsuppor
t
Pr
oduct
ionsuppor
tist
het
eam wor
ksonpr
oduct
ioni
ssues.
Theteam i
sresponsi
bleformonit
ori
ngproduct
ionacti
vi
ti
esacknowledgei
ssues,
worki
ngont r
oubleshoot
ing/i
nvesti
gat
ionandresol
uti
onprocess.
Thet
eam shoul
descal
atet
heissuespr
oductkeyt
oot
hert
eamssuchasdev
elopat
admi
nsetc.whenev
err
equi
red.
Pr
oduct
ionsuppor
tteam i
sal
sor
esponsi
blef
orcodedev
elopmenti
nthepr
oduct
ions.
Lev
elsi
npr
oduct
ionsuppor
t
Theyar
ethr
eedi
ff
erentt
eamsi
nthepr
oduct
ionsuppor
t
L1t
eam
L1team i
sthet
eam worksonthebasi
clevelofi
nvest
igat
iont
heywor
konper
for
ming
checkout
s,moni
tor
inggener
atingr
eport
setc.
Theybasi
cal
l
ycont
ainonl
yreadaccessest
othecode.
Theywor
kaspert
hedocument
ati
onpr
ocess[
wackypages]
.
L1team i
stheteam whoreceivest
heissue[
acknowledge]andper
formt
hebasi
clev
elof
checkoutandescal
atetheissuetoL2team i
ftheycountresol
vei
t.
L2t
eam
L2team i
stheteam wor
ksont
roubl
eshoot
ing,
inv
est
igat
ionandper
for
mingr
ootcause
anal
ysi
s[RCA].
I
fanyissuecomesinthepr
oducti
onL2t
eam shoul
dtaket
her
esponsi
bil
i
tyby
per
for
mi ngal
lther
equir
edsteps.
Ifani
ssueneededcodel
evel
changesar
ecodel
evel
inv
est
igat
iont
henL2t
eam can
escal
atet
heissuetoL3t
eam.
L2t
eam cont
ainsal
ll
evel
ofaccesst
ocodesuchasr
ead,
wri
teandexecut
e[maynot
2
cont
ainswr
it
eaccess
L3t
eam
L3t
eam i
snot
hingbutdev
elopmentt
eam.
L3team worksoncodelev
elfi
xesanddatabasechangesaswel
lasworki
ngonissues
whi
chr equi
redcodelev
eli
nvest
igat
iont
hem mustcontainr
ead,
wri
teandexecut
e
per
mi ssi
ontothecode.
Ski
l
ls/t
ool
srequi
redf
orpr
oduct
ionsuppor
t
Aproducti
onsupportguyshoul
dhavet
heknowl
edgeonanydat
abasesuchasor
acl
e
(
or)Sybase(or
)sqlserver(
or)DBet
c.
Suppor
tguyshoul
dhav
eknowl
edgeonanyoper
ati
ngsy
stem suchaswi
ndows(
or)Uni
x.
Schedul
i
ngt
ool
s
Aut
osy
’s,
cont
rol
+m,
tidal
.
Ti
cket
ingt
ool
s
Bmcr
emedy
,Ser
vicenow,
Jir
a.
Moni
tor
ingt
ool
s
I
TRS,
Gomej
moni
tor
ing
Dat
abaseconv
ert
ingt
ool
s
Put
ty,
Tect
ia,
QPt
ool
.
3
Uni
xar
chi
tect
ure
Uni
xisanoper
ati
ngsy
stem t
hatcont
ainssetofpr
ogr
amsandact
sasal
i
nkbet
weenuser
andcomput
er.
Theyar
edi
ff
erentt
ypes/f
lav
orsar
eav
ail
abl
eint
hemar
ket
Exampl
e:r
edhatl
i
nux,
sunsol
ari
es,
hpuni
x,i
bm ai
x,Ubunt
uandsoon
Themostf
requent
lyusev
ersi
onofuni
xisr
edhatl
i
nux
Har
dwar
e
Ker
nel
Shel
l
User
User:
Useri
snot
hingbutwhoex
ecut
ethecommandsandcont
ainssetofappl
i
cat
ionpr
ogr
ams.
Shel
l:
Shel
li
scommandi nter
pret
eri
ttransl
atest
hecommandsent
erbyusert
otheker
nel
ina
l
anguageunder
standabl
ebykernel.
Theyar
edi
ff
erentt
ypesofshel
l
sinuni
x
Bour
neshel
l(sh)
Bour
neagai
nshel
l(bash)
Csh–cshel
l
4
Kor
nshel
l–ksh
Tcsh(
tcshel
l
)–t
exi
m cshel
l
Not
e:
Al
ltheshel
l
shast
heal
mostsamef
eat
ures
Butt
hewayofexecut
iondi
ff
erencesf
rom shel
ltoshel
l
Thedef
aul
tlogi
nshel
lwar
iesf
rom onef
lav
ort
oanot
herf
lav
or
Isanexampl
einr
edhatl
i
nuxt
hedi
ff
erentshel
li
sbashandi
nsunSol
ari
sthedi
ff
icul
t
shel
li
scsh.
Q.whati
stheshel
lthaty
ourcur
rent
lywor
kingon?
Ans:
bash
Q.howt
ochange(
or)swi
tchf
rom oneshel
ltoanot
hershel
l?
Ans:
byt
ypi
ngt
heshel
lname
Q.howt
ofi
ndoutwhi
chi
sthedef
aul
tshel
l?
Ans:
echo$SHELL
Q.howt
ofi
ndoutcur
rentwor
kingshel
l?
Ans:
echo$0(
zer
o)
ker
nel
kernel
ist
hecoreofuni
xoper
ati
ngsy
stem t
hrought
heker
nel
thepr
ogr
am get
sexecut
es
thr
oughtheker
nel
Har
dwar
e
Har
dwar
eisnot
hingbutsy
stem r
esour
cessuchascpu,
ram,
har
ddi
sket
c
UNI
XBASI
CCOMMANDS
$l
ogname:
itdi
spl
ayscur
rentusername
$pwd:
Itdi
spl
ayspr
esentwor
kingdi
rect
orypat
h
$dat
e:i
tdi
spl
ayssy
stem dat
e&t
ime
$cl
ear:
tocl
eart
hescr
een
$cal
:Itdi
spl
ayscur
rentmont
hcal
endar
5
$cal
2000:
itdi
spl
ays2000y
earcal
endar
$cal
061995:
itdi
spl
aysJunemont
h1995y
ear
$uname:
itdi
spl
aysoper
ati
ngsy
stem name
$uname-
r:i
tdi
spl
aysker
nal
ver
sion
$host
name:
itdi
spl
aysser
vername
$host
name-
i:i
tdi
spl
aysser
verI
Paddr
ess
$who:
itdi
spl
aysl
i
stofuser
swhoar
econnect
edt
otheser
ver
$whoam i
:itdi
spl
ayscur
rentuseri
nfor
mat
ion
$t
ty:
itdi
spl
ayscur
rentt
ermi
nal
name
$upti
me:itdi
spl
ayshowl
ongser
veri
supandr
unni
ng,
no.
ofuser
sconnect
ed,
andav
eragel
oad
ontheser
ver
$su:
iti
susedt
oswi
tchf
rom oneuseraccountt
oanot
heruseraccount
sy
ntax:
$su-user
name
$whoami
:itdi
spl
aysswi
tchedusernameorchi
l
dusername
$exi
t:t
ologoutf
rom cur
rentuseraccount
$mancommandname:
itdi
spl
ayshel
ppagesofgi
vencommand
Basi
cuni
xcommands
whoam I:
i
tgivesthecurr
entuseri
nfor
mat
ionsuchasuser
name,
ter
minal
name,
dat
eandt
ime,
since
userloggedi
ndate.
Out
put:
User
name t
ermi
nal
namedat
e t
ime
Pr
akash pt
s/0 2018/
02/
27 10:
40(
:00)
Who:
I
tgi
vest
hei
nfor
mat
ionaboutal
luser
swhoar
ecur
rent
lyl
oggedi
ntot
hemachi
ne/ser
ver
.
Out
put:
User
name t
ermi
nal
name dat
e t
ime
Pr
akash t
ty 2018/
02/
27 03:
20(
:0)
6
Pr
akash pt
s/0 2018/
02/
27 03:
21(
:00)
l
ognameorwhoami
:
I
tgi
vest
heusernamewhoi
scur
rent
lyl
oggedi
n.
Output: pr
akash
t
ty:
I
tgi
vest
het
ermi
nal
typeoft
hecur
rentuserwhoi
scur
rent
lyl
oggedi
n.
Output:t
ermi
nal
typeoft
hecur
rentuser
/
dev
/pt
s/0
Last:
I
tgi
vest
hel
ogi
nandl
ogouti
nfor
mat
ionofal
luser
s
Output:
User t
ermi
nal
name dat
e t
ime
Pr
akash pt
s/0 :
00t
uef
eb27 03:
21st
il
ll
oggedi
n
Uname-
a:
Itgi
vestheinf
ormat
ionaboutoper
ati
ngsy
stem suchast
ypeofoper
ati
ngsy
stem r
eleasedat
e,
kernel
versi
on,ty
peofuni
xetc.
Output:
Li
nuxl
ocal
hostl
ocal
domai
n2.
6.32-
71.
e16.
i686#/smpwedsep|
01:
26:
34EDT201
Howt
ofi
ndoutorhowt
ocheckoper
ati
ngsy
stem v
ersi
on?
I
nuni
xther
eist
hedi
rect
orycal
l
edet
cwhi
chi
slocat
edunderhomedi
rect
ory
.
InETCdir
ect
oryt
her
eashouldbeafil
ecal
l
edr
elease.Ther
eleasef
il
econt
ainst
hei
nfor
mat
ion
aboutv
ersi
onofuni
xoper
ati
ngsyst
em.
cat/
etc/
*real
ease*
Output:
Redhatent
erpr
isel
i
nuxser
verr
elease6.
0(st
ant
iago)
Redhatent
erpr
isel
i
nuxser
verr
elease6.
0(Sant
iago)
Cpe:
/0:
redhat:
ent
erpr
ise_
li
nux:
6ser
ver:
go.
ser
ver
dat
e:
7
I
tisusedt
ofi
ndoutt
hecur
rentdat
eandt
imeandt
imezoneoft
heser
ver
.
Output:
Wedj
an2403:
44:
44pst2018
dat
e+%d=24
i
tisusedt
odi
spl
ayonl
ydat
e
dat
e+%m =01
i
tdi
spl
aymont
hoft
hey
ear
dat
e+%y=18
t
odi
spl
ayt
hey
ear
dat
e+%H=03
t
odi
spl
ayt
hehour
s
dat
e+%M =46
t
odi
spl
ayt
hemi
nut
es
dat
e+%S=49
t
odi
spl
ayt
heseconds
Touch:
Touchi
susedt
ocr
eat
ezer
o(0)by
tef
il
esaswel
las‘
n’numberoff
il
esatat
ime.
Sy
ntax:
touchf
il
e1f
il
e2f
il
e3-
--
--
--
fi
len
NOTE:
Whenweusetouchcommandwhil
ecreat
edanyf
il
eift
hef
il
eisal
readyexi
stedt
het
imest
amp
oft
hefi
l
ewil
lbechangedt
ocurr
entti
me.
Q.Howt
ochanget
het
imest
ampoft
hef
il
eusi
ngt
ouchcommand
Ti
mest
ampi
snot
hingbutt
heaccess,
modi
fi
ed,
changet
imeoft
hef
il
e.
Byusi
ng‘
stat
’commandwecanseet
het
imest
ampoft
hef
il
e.
Exampl
e:st
atf
il
ename
NOTE:
I
fwechanget
hecont
entoft
hef
il
eordat
aoft
hef
il
ethati
scal
l
edasmodi
fi
edt
ime
8
Ifwechangetheext
ernal
fil
eatt
ri
butessuchasper
missi
onsar
eowner
,gr
oupet
cthati
scal
l
ed
aschangeti
me( onl
yti
mewi l
lbechange)
Touch–af
il
enamei
twi
l
lbechanget
heaccesst
ime
Touch–m f
il
enamei
twi
l
lbeusedt
ochangemodi
fyt
imeoraccesst
ime
Touch–cf
il
ename i
twi
l
lbeusedt
ochangeaccesst
imeormodi
fyorchanget
ime
Byusingabov
ecommandwecanchanget
heaccessed,
modi
fi
edandchangedt
imet
othe
cur
rentti
me(ti
mest
amp)
Q.Howt
ochanget
het
imest
ampofaf
il
ewi
thanot
herf
il
eti
mest
amp?
Touchr
equi
redf
il
ename-
rref
erencedf
il
ename
Touch–rr
efer
encedf
il
enamer
equi
redf
il
ename
CATCOMMAND:
Catcommandisusedt
ocr
eat
enewf
il
easwel
lasi
nser
ti
ngt
hedat
awhi
l
ecr
eat
ionaswel
last
o
vi
ewt hef
il
econt
ent
Sy
ntax: cat>f
il
ename
-
--
--
-
-
--
--
--
Ct
rl+d t
ocomeoutorexi
t
Byusi
ngabov
ecommandwecancr
eat
ethef
il
easwel
laswecani
nser
tthedat
aint
othef
il
e
Catcommandt
oappendt
hedat
a
Sy
ntax: cat>>f
il
e1
Theabov
ecommandi
susedt
oappendt
hedat
atot
heexi
sti
ngf
il
e
NOTE:
cont
rol
+d
Toqui
tthedat
apr
ompt
Sy
ntax: catf
il
e1f
il
e2f
il
e3-
--
-f
il
en
Byusi
ngabov
ecommandwecanv
iewar
edi
spl
aymul
ti
plef
il
edat
aatat
ime
Redi
rect
ionoper
ator
sinuni
x:-(
>,>>)
Inuni
xwehav
etwor
edi
rect
ionoper
ator
swhi
char
eusedt
oredi
rectt
hedat
atoanot
herf
il
ear
e
anyfi
l
e
WhenIusesi
ngl
eredi
rect
ionoper
ator(
>)t
hedat
aoft
hedest
inat
ionf
il
ewi
l
lbeov
erwr
it
tenwi
th
t
hesourcef
il
e
9
Whenweusedoubl
eredi
rect
ionoper
ator(
>>)t
hedat
aoft
hedest
inat
ionf
il
ewi
l
lbeappended
wi
ththesour
cef
il
edata
Exampl
e:
catf
il
e1f
il
e2>f
il
e3
Byusi
ngabov
ecommandwecancopyt
hef
il
e1andf
il
e2cont
entt
ofi
l
e3
I
ffi
le3i
sal
readyexi
stedandi
fit
sal
readycont
aini
ngt
hedat
acanbeov
err
etur
nfi
l
e1andf
il
e2
dat
a
I
ffi
l
e3i
snotexi
stedanewf
il
ewi
l
lbecr
eat
edwi
thf
il
e1andf
il
e2dat
a
Exampl
e: catf
il
e1f
il
e2>>f
il
e3
Byusi
ngabov
ecommandwecancopyt
hef
il
e1andf
il
e2cont
entt
ofi
l
e3
I
ffi
le3i
salr
eadyexi
stedandi
fit
’sal
readycont
aini
ngt
hedat
athatcanbeappendedf
il
e1and
f
il
e2data
Howt
omakeaf
il
easempt
yfi
l
eusi
ngcatcommand
Ex: cata>a
EX:
2::
cat>a
Ct
rl
+d
Whati
sthedi
ff
erencebet
weent
ouchandcatcommands
Byusi
ngt
ouchcommandwecancr
eat
eonl
y‘0’
(zer
o)by
tef
il
esaswel
las‘
n’numberoff
il
esat
ati
me
Byusi
ngcatcommandwecancr
eat
efi
l
esal
ongwi
thdat
ainser
tbutwecancr
eat
eonl
yonef
il
e
atati
me
Byusi
ngt
ouchcommandwecanchanget
het
imest
ampoft
hef
il
e
Byusi
ngcatcommandwecanv
iewt
hedat
aoft
hef
il
e
TOCREATEDI
RECTORI
ES:
Mkdi
r:
Sy
ntax:mkdi
rdi
r1di
r2di
r3-
--
--
-di
rn
Tocr
eat
eempt
ydi
rect
ori
es
Sy
ntax:mkdi
r-pdi
r1/
dir
2/di
r3/
--
--
/di
rn
Tocr
eat
edi
rect
ori
esr
ecur
siv
ely
10
Tor
emov
efi
l
esanddi
rect
ori
es:
r
m:
i
tisusedt
oremov
eoneormor
efi
l
esatat
ime
sy
ntax:r
mfi
l
e1f
il
e2f
il
e3-
--
--
-f
il
en
r
m –f:fopt
ioni
susedt
oremov
ethef
il
esf
orci
ble
sy
ntax:r
m-ff
il
e1f
il
e2f
il
e3-
--
--
--f
il
en
r
m –i
:
i
tisusedf
oraski
ngper
missi
onbef
orer
emov
ingt
hef
il
eify
ouent
er‘
Y’t
hef
il
ewi
l
lber
emov
ed
i
fyouent
er‘
N’t
hef
il
ewi
l
lbenotr
emov
ed
r
mdi
r:i
tisusedt
oremov
eonl
yempt
ydi
rect
ori
es
r
m-r:
iti
susedt
oremov
ethedi
rect
ori
esr
ecur
siv
ely
ex:r
m-rdi
r1/
dir
2/di
r3
cp(
copy
):
I
tisusedt
ocopyt
hef
il
esanddi
rect
ori
esf
rom onel
ocat
iont
oanot
herl
ocat
ion
Sy
ntax:cpsour
cef
il
e t
argetf
il
e
Ex: cpf
il
e1f
il
e2
Theabov
ecommandcopi
esdat
afr
om f
il
e1t
ofi
l
e2
I
ffi
l
etoi
sal
readyexi
stedt
hedat
aoff
il
e2wi
l
lbeov
err
etur
nwi
thf
il
e1dat
a
I
ffi
l
e2i
snotal
readyexi
stedt
henewf
il
ewi
l
lbecr
eat
ed
Whenwecopyt
hef
il
est
het
imest
ampoft
hef
il
eswi
l
lbedi
ff
erent
Tocopyt
hef
il
ewi
thsamet
imest
ampwehav
etouse‘
-
p’opt
ion
cp–p f
il
e1f
il
e2
ex: cp-
p di
r1/
dir
2fi
l
e
cp-
p r
aju/
ram babu
Theabovecommandi
susedt
ocopyt
hef
il
eunderdi
r1/
dir
2tot
hel
ocat
ion‘
babu’
whi
chi
sunder
raj
u/r
am
cp-
r:i
tisusedt
ocopyt
hedi
rect
ori
esr
ecur
siv
ely
ex:
cp–rdi
r1/
dir
2/di
r3
11
kash/
babu/
prav
t
heabov
ecommandi
susedt
ocopyt
hedi
rect
orycal
l
ed‘
prav
’whi
chi
sunderkash|
babu
mv(
mov
e):
i
tisusedt
omov
ethef
il
esar
edi
rect
ori
esf
rom onel
ocat
iont
oanot
herl
ocat
ion
sy
ntax:
mvsour
cef
il
e t
argetf
il
e
ex: mv f
il
e1 f
il
e2
Byusi
ngabov
ecommandwear
emov
ingf
il
e1t
ofi
l
e2
I
ffi
l
e2al
readyexi
stedi
sthr
ought
heer
ror
I
ffi
l
e2i
snotal
readyexi
stedanewf
il
ewi
l
lbecr
eat
ed
Ex:mvf
il
e1/
var/
temp/pr
akash
Theabovecommandi
susedt
omov
ethef
il
ecal
l
edasf
il
e1t
odi
rect
orycal
l
edpr
akashwhi
chi
s
under/
temp
l
s:
l
scommandi
susedt
oli
stt
hef
il
esanddi
rect
ori
esundert
hecur
rentdi
rect
ory
l
s–r
:
l
tisusedt
oli
stt
hef
il
esanddi
rect
ori
esi
nrev
erseal
phabet
ical
order
l
s-l
:
i
tisusedt
olongl
i
stt
hef
il
esanddi
rect
ori
es
l
s-l
r:
i
tisusedt
oli
stt
hef
il
esanddi
rect
ori
esi
nrev
erseal
phabet
ical
orderwi
thl
ongl
i
sti
ng
l
s-t
:
i
tisusedtodi
spl
aythef
il
esanddi
rect
ori
esbasedont
imest
amp[
basedonchangedand
modif
icat
iont
ime]
l
s-t
r:
i
tisusedt
odi
spl
ayt
hef
il
esanddi
rect
ori
esbasedondescendi
ngt
imest
amp
l
s-l
tr
:
i
tisusedt
olonglistt
hef
il
esanddir
ect
ori
esi
nrev
erset
imest
ampi
tmeanst
her
ecent
lycr
eat
ed
f
il
esanddir
ector
iescometothebot
tom
l
s-a:
12
i
tisusedt
oli
stoutt
heal
lfi
l
esanddi
rect
ori
esal
ongwi
thhi
ddenf
il
es
NOTE:
Whil
ecr
eat
inganyf
il
esi
fwepr
efi
x(.
)dotbef
oret
othef
il
enamet
hatf
il
ewi
l
lbecomehi
dden
f
il
e
Q.howt
ohi
ddenf
il
escr
eat
ed?
Sy
ntax:cat>.
fi
lename
Remov
e(r
m):
r
m .
fi
lename
Fi
eldswhenweusel
s–l
tr(
or)l
s–l
opt
ion:
-
Ex:
-rw-
r-
-xr
-x 1 pr
akash,
kash 123 may2011:
23
har
i
↑ ↑ ↑ ↑ ↑ ↑
Fil
e(or
)dir
ect
ory no. of username,
groupname si
zeoft
hef
il
eti
mest
amp
f
ilenamety
pefi
leper
missi
ons links
I
nunixwehavedi
ff
erentt
ypesoff
il
essuchasnor
mal
fil
es,
dir
ect
oryf
il
es,
li
nks,
socketf
il
e,
pi
pedfi
l
esetc
_
nor
mal
fil
e
ddi
rect
oryf
il
e
l
li
nkedf
il
e
|
pi
pedf
il
e
Ssocketf
il
e
NOTE:
r-r
ead w-
wri
te x-
execut
e
Regul
arcommandswi
thl
scommandwhi
l
edi
spl
ayi
ngt
hef
il
es:
*:‘*
’iscal
l
edasgl
obal
sear
ch,
whenweuse*i
tmeansi
tcanber
epl
acedwi
thanynumberor
anyval
ue
Ex:
ls-
lt
r abc*
I
tisusedt
olongl
i
stt
hef
il
esanddi
rect
ori
eswhi
chst
art
swi
thabc
?
:-‘
?’i
susedt
orepl
acef
orsi
ngl
echar
act
er
Ex:l
s-l
tr a?
c?
Theabov
ecommanddi
spl
ayst
hef
il
esanddi
rect
ori
eswhi
char
efouri
nlengt
handf
ir
stl
ett
er
13
shoul
dbe‘
a’andt
hir
dlet
tershoul
dbe‘
c’andsecondandf
our
thcanbeany
thi
ng
[]
:-i
tisusedt
ospeci
fi
cthemul
ti
plechar
act
erswhi
chi
susedt
orepl
acet
hesi
ngl
echar
act
er
Ex:
ls-
lt
r[axzy
]*
Theabov
ecommanddi
spl
ayst
hef
il
esanddi
rect
ori
eswhi
chst
art
swi
thl
ett
er‘
a’or‘
x’or‘
z’or‘
y’
Ex:l
s-l
tr[
xmn]
?[pas]
?
Theabovecommanddi
spl
aysthefil
esanddirect
ori
eswhi
charefourinl
engthandt
hefi
rst
l
ett
ercanbe‘x’
or‘
m’or‘
n’andthi
rdlet
tercanbe‘p’
or‘
a’or‘
s’andsecondandfour
thl
ett
ercan
beanythi
ng
NOTE:
af
tert
hel
scommandi
fyougi
veanyf
il
enameonl
ythatf
il
einf
ormat
ionwi
l
lbedi
spl
ayed
Forexampleifweusedl
scommandthedir
ector
ywi
l
lbel
ongl
i
stedbutt
hef
il
esandsub-
di
rector
iesi
nsidet
hedir
ect
orywi
l
lbelongl
ist
ed
l
s-l
ddi
rname
i
tisusedt
olongl
i
stt
hespeci
fi
cdi
rect
ory
l
s-l
r:
i
tisusedtodisplaytheal
lfi
l
esanddi
rect
ori
esi
ncur
rentdi
rect
oryaswel
lasi
nal
lsub-
di
rect
ori
esrecursivel
y
pwd(
presentwor
kingdi
rect
ory
):
I
tisusedt
odi
spl
ayedt
hecur
rentorpr
esentwor
kingdi
rect
ory
cd:
(changeddi
rect
ory
)
sy
ntax: cd l
ocat
ion
ex:cd /
var
/tmp/
prv
i
tisusedt
ochanget
hecur
rentdi
rect
oryl
ocat
iont
o‘pr
v’di
rect
orywhi
chi
sunder/
var
/tmp
cd.
.:
i
tisusedt
ogot
otheonedi
rect
orybackwor
d
ex: cd.
./.
./.
./.
.
I
tisusedt
ogot
othef
ourdi
rect
ori
esbackwor
d
Cd/:
I
tisusedt
ogot
other
ootdi
rect
ory
14
cd$home(
or)cd:
I
tisusedt
ogot
othehomedi
rect
oryoft
heuser
cd–:
iti
susedt
ogot
othepr
evi
ouswor
kingdi
rect
orywher
eyouar
epr
evi
ousl
ywor
kingon
Head:i
tisusedt
odi
spl
ayf
ir
st‘
n’numberofl
i
nef
rom t
hef
il
e
Sy
ntax:
head–nf
il
ename
Ex:head-
5fi
l
ename
Theabov
ecommandi
susedt
odi
spl
ayst
hef
ir
st5l
i
nesoft
hef
il
e
NOTE:
I
fwedon’
tpassspeci
fi
cli
nenumbert
otheheadcommand
I
twi
l
ldi
spl
aysf
ir
st10l
i
nesoft
hef
il
e
Ex:
head f
il
ename
Tai
l
:iti
susedt
odi
spl
aysl
ast‘
n’numberl
i
nesoft
hef
il
e
Sy
ntax:t
ail-
nfi
l
ename
Ex:
tai
l-15 f
il
ename
NOTE:
Si
mi l
art
oheadcommandifwedon’
tpassanyspeci
fi
cli
nenumbert
otai
lcommandbydef
aul
t
i
tdispl
aysl
ast10l
inesoft
hef
il
e
(|
)pipe:i
tisanoper
atorwhi
chi
susedt
otaket
heout
putofpr
evi
ouscommandandsendi
nto
nextcommandasainput
Ex:
ls–l
tr|
head-
5
Theabov
ecommanddi
spl
ayst
heonl
y5f
il
esf
rom al
lfi
l
esi
ncur
rentdi
rect
ory
Q.Howdoy
oupr
intl
i
nesf
rom 12t
o17i
nthef
il
e?
Head-
17 f
il
ename|
tai
l-6
per
missi
onsi
nuni
x:
Umaskval
ueistheval
uewhi
chi
susedt
osett
hedef
aul
tper
missi
onst
oaf
il
esanddi
rect
ori
es
bef
orei
tgetcr
eates.
Thedef
aul
tumaskv
aluei
s‘022’
15
The‘
022’
val
uewi
l
lbesubt
ractf
rom ‘
666’
and‘
777’
forf
il
esanddi
rect
ori
es
Tochanget
heumaskv
aluewecanusebel
owsy
ntax
Sy
ntax:
umaskv
alue
Ex:
umask546
chmod:
iti
susedt
ochanget
heper
missi
onsoft
hef
il
esanddi
rect
ori
esaf
tercr
eat
ed
sy
ntax:chmod v
alue f
il
eordi
rect
ory
Ex: chmod666 f
il
ename
chmod 555 f
il
ename
chmodugo+x f
il
ename
chmodugo+w f
il
ename
chmodg+x f
il
ename
chmodo+w f
il
ename
chmodugo–x f
il
ename
St
ickybi
t:
St
ickybi
tist
heopt
iont
hati
susedt
opr
ovi
det
hesecur
it
yfort
hef
il
esanddi
rect
ori
es
I
fwecr eat
ethest
ickybi
tonthefi
leordi
rector
yapotf
rom t
heuserwhocr
eatedthef
il
eor
di
rect
orynooneelsecanchangeormodifyormovear
eremovethefi
l
eordir
ector
y
Sy
ntax:chmod+tf
il
enameordi
rect
oryname t
ocr
eat
ethest
ickybi
t
chmod -
tfi
l
enameordi
rect
oryname t
oremov
ethest
ickybi
t
Howt
oident
if
yweat
herst
ickybi
tispl
acedonf
il
eordi
rect
ory
Whenwel ongl
istt
hef
il
esusi
ngls-lopti
oni
fwesee‘
T’l
ett
eront
heper
missi
onf
iel
ditmeans
st
ickybi
tispl
acedont
hefi
leordi
rect
ory
I
nodenumber
:
I
nodenumberi
stheaddr
essoft
hef
il
egi
venbyt
heuni
xoper
ati
ngsy
stem t
othef
il
es
Eachandev
eryi
nodenumberi
s‘uni
que’
Tocheckt
hei
nodenumberwecanusebel
owcommand
Sy
ntax: l
s-i f
il
ename(
or)di
rect
oryname
16
wc:i
tisusedt
ocountt
hechar
act
ers,
wor
dsandl
i
nesoft
hef
il
e
sy
ntax: wc f
il
ename
wc-
c onl
yforchar
ater
s
wc-
w onl
yforwor
ds
wc-
lonl
yforl
i
nes
Q.Howt
ofi
ndouthowmanyf
il
esanddi
rect
ori
esar
ether
eundercur
rentdi
rect
ory
?
l
s|wc-
w
passwd:
iti
susedt
ochanget
hepasswor
doft
heuser
cut:
i
tisusedt
oext
ractt
her
equi
rednumberofchar
act
ersandf
iel
dsf
rom t
hegi
venf
il
e
Ex:
cut-
c1 f
il
ename t
oext
ractt
hef
ir
stchar
act
eroft
hef
il
e
cut-
c1,
4fi
l
ename t
oext
ractt
hef
ir
standf
our
thchar
act
eroft
hef
il
e
cut-
c2-
5fi
l
ename t
oext
ractt
hechar
act
erf
orm secondposi
ti
ont
ofi
ft
hposi
ti
on
cut-c2-
5,10-
20fil
ename toext
ractthechar
act
ersf
rom secondposi
ti
ont
ofi
ft
hposi
ti
on
andfor
mt enthposi
ti
ontotwent
iet
hposit
ion
cut-
c2-f
il
ename t
oext
ractt
hechar
act
erf
rom secondposi
ti
ont
oendoft
hef
il
e
cut-
d““-
f1f
il
ename t
oext
ractt
hef
ir
stf
iel
doft
hef
il
e
cut-
d““-
f1,
4fi
l
ename t
oext
ractt
hef
ir
standf
our
thf
iel
doft
hef
il
e
cut-
d““-
f2-
5,10-
20f
il
ename t
oext
ractt
hef
i d2ndt
el o5thf
iel
dandf
rom 10tht
o20th
f
iel
d
cut-
d““-
f2-f
il
ename t
oext
ractt
hef
iel
dfom 2ndf
r iel
dtoendoft
hef
il
e
NOTE:
I
nt heabov
ecommand–dst andsfor‘
del
i
miter
’whi
chi
snothi
ngbutfi
eldsepar
ator
,weneedt
o
passthefi
eldsepar
atort
othecutcommandwhenweareext
ract
ingt
hefiel
ds
PASTE:
Past
ecommandi
susedt
ojoi
nthef
il
eshor
izont
all
y
Sy
ntax:
past
e f
il
e1 f
il
e2-
--
--
--
fi
len
Ex:f
il
e1
17
abc xy
z
100 200
f
il
e2
abc 123
cab 200
out
put:past
efi
l
e1 f
il
e2
abc xy
z abc 123
SORT:
Sor
tcommandi
susedt
osor
tthedat
abasedonascendi
nganddescendi
ngor
der
1.sor
tfi
l
ename:
I
tisusedt
osor
tthedat
abasedon‘
ascendi
ngor
der
’
2.sor
t-rf
il
ename:
I
tisusedt
osor
tthedat
abasedon‘
descendi
ngor
der
’
3.sor
t-nf
il
ename:
Thi
sopt
ioni
susedt
osor
tthedat
apr
oper
lywhenwehav
enumber
sint
hedat
a
4.sor
t-nrf
il
ename:
Thi
sopt
ioni
susedt
onumber
sonwi
thr
ever
seor
der
5.sor
t-uf
il
ename:
Thi
sopt
ioni
susedt
oav
oidt
hedupl
i
cat
esandpr
intt
heuni
quev
alues
6.sor
t-nuf
il
ename:
Toav
oidt
hedupl
i
cat
esandsor
tthedat
apr
oper
lywhenwehav
enumber
s
7.sor
t-nr
ufi
l
ename:
Toav
oidt
hedupl
i
cat
eandpr
intt
hedat
ainnumer
ical
rev
erseor
der
Wi
tht
hesor
tcommandwecansor
tthedat
abasedondesi
rednumberoff
iel
d
sor
t-t‘
‘-k3 f
il
ename (
or) sor
t-t‘
‘-nkr
3fi
l
ename
UNI
Q:
18
Uniqcommandi susedt
odi spl
aythedat
abyavoi
dingdupl
i
cat
erowsaswell
astopr
intonl
y
dupli
caterowsandtopr
intonlyther
owswhichar
euniqueaswel
last
opri
ntther
owsalong
wit
ht hecountoft
herow
NOTE:
Uniqcommandsearchesf
orthedupli
cat
ebychecki
ngcogi
tati
verows,i
fanyoft
herowis
repeat
edt
henitt
reatsasadupl
icat
esothatwealwayssor
tthedatabef
oreweuseuni
que
command
Sy
ntax:uni
qfi
l
ename
sor
tfi
l
ename|
uni
q
sor
tfi
l
ename|
uni
q-u
sor
tfi
l
ename|
uni
q–d
sor
tfi
l
ename|
uni
q–c
LI
NKS:
Linksar
ebasi
cal
lyusedtorefer
encethef
il
esordi
rect
ori
eswi
thanot
herf
il
esanddi
rect
ori
esso
thatwecanachi
evedataref
erenci
ng
Theyar
etwot
ypesofl
i
nks
1.Har
dli
nk
2.Sof
tli
nkorsy
mbol
i
cli
nk
1.
Har
dli
nk:
l
n sour
cef
il
e l
i
nkort
argetf
il
e
NOTE:
Ifl
inkfi
l
eort
argetf
il
eisal
readyexi
stedt
hesy
stem t
hrought
heer
rori
fnotnewf
il
ewi
l
lbe
creat
ed
Har
dli
nkcanbecr
eat
edonl
yanf
il
esnotondi
rect
ori
es
Whenwecr
eat
ehar
dli
nkt
hei
nodenumberf
orbot
hsour
ceandt
argetf
il
eissame
I
fwer
emov
ethesour
cef
il
est
il
lwecanuset
het
argetf
il
eorv
icev
ersa
I
fsour
cef
il
eismodi
fi
edaut
omat
ical
l
ythet
argetf
il
egetmodi
fi
edorv
icev
ersa
Whenwelongli
stthef
il
esusingl
s–iopti
oni
fanyoft
het
wof
il
eshav
ingt
hesamei
node
numberi
tmeansthosearehardl
i
nkedfi
l
es
19
Sof
tli
nk:
l
n-s sour
cef
il
e l
i
nkort
argetf
il
e
Sof
tli
nkcanbecr
eat
edonbot
hfi
l
esanddi
rect
ori
es
Whenwecr
eat
esof
tli
nkt
hei
nodenumberf
orsour
ceandt
argetf
il
esi
sdi
ff
erent
Whenweremovethesour
cef
il
ethet
argetf
il
eisunusef
ulbuti
fyour
emov
ethet
argetf
il
ewe
canst
ayusesour
cefi
le
NOTE:
Whenwer emovethesour
cefi
let
hetar
getfi
lei
sonlargerinusebuti
fsti
llr
emai
nint
he
di
rect
oryandi
tbecameacti
vewhenwecreat
ethesour
cef i
leagai
ninfeat
ure.
I
fwemodi
fyt
hesour
cef
il
edat
aaut
omat
ical
l
ythet
argetf
il
edat
agetmodi
fi
ed(
or)v
icev
ersa.
Toi
denti
fythesof
tli
nkwhenwedols-
l,
ifanyoft
hef
il
eisshowi
ngas1l
ett
eri
nthebegi
nni
ng
oft
heli
neifmeansit
’sasof
tli
nk.
COMMANDSTOOPENTHEFI
LE(
or)LOGFI
LES:
Logefil
eisnot
hingbutaf
il
ewhichst
orest
heinf
ormati
onaboutspeci
fi
cpr
ocess(or
)ser
vicein
real
timescenar
ioswemustusethebel
owspeci
ficcommandswhenwegot hr
oughthel
ogf i
l
e
Less
Mor
e
Vi
ew
Vi
t
ail-
f
LESS:
Sy
ntax:l
ess f
il
ename
I
tisusedt
oseet
hel
ogf
il
einf
ormat
ionpagebypage
Onceweopent
hef
il
eusi
ngl
esscommandasepar
ate
Wecanusescrol
ldownandscr
oll
upt
ovi
ewf
ort
hepagesaswel
laswecanhi
tent
ir
etov
iew
t
hefur
therpages
Sosear
chforanyl
i
neswhi
chast
hespeci
fi
ckey
wor
dar
est
ri
ngwecant
ype‘
/’andst
ri
ngname
[
/keyword]
I
twi
l
lst
artsear
chi
ngf
ort
hel
i
neswhi
chast
hekey
wor
dinf
orwar
ddi
rect
ion
20
Tosear
chf
ort
hest
ri
ngcont
aini
ngl
i
nesi
nbackwor
ddi
rect
ionwehav
etouse
‘
?’st
ri
ng[
?Key
wor
d]
Togotheendofthefi
l
ewecanuse‘G’(
shi
ft+g)tomaket
hedynami
cinf
ormat
iont
obe
updat
edoftheendofthef
il
ewecanuseF(shi
ft+f)(
qui
t–q)
MORE:
Sy
ntax:mor
efi
l
ename
Moreisusedtoseet
hefi
leinformati
onper
cent
agebyper
cent
age.I
tmeanswear
eopeni
ngt
he
pagesinper
cent
agebypercentage
Onceweopent
hef
il
eatt
hebot
tom i
tisshowl
i
kemor
especi
fi
cper
cent
agei
stobev
iewwhen
90%wer
e10%
Wecanuset
henav
igat
ekey
swheny
ouopent
hemor
ecommand
Onl
ybyhi
tt
ingent
erwecanscr
oll
downbutwecannotscr
oll
up
I
tisal
way
sbet
tert
ousel
esscommandwhencompar
ethemor
ecommand
VI
EW :
Sy
ntax: v
iew f
il
ename
I
tist
hecommandt
oseet
hef
il
einf
ormat
ionwhenr
eadonl
ymode
Onceweopent hefi
l
eusingvi
ewcommandthefi
lewil
lopenvi
modebutwecannotmakeany
changestothefi
l
e,i
fyoutr
ytomaket
hechangesit
’st
hrought
heer
ror
ssuchasfi
leopent
he
fi
lereadonl
y
Wecanscr
oll
upanddownaswel
laswecansear
chf
ort
hest
ri
ngj
ustl
i
keasl
esscommand.
Tai
l-f:
I
tisusedtoseethedy
namicinfor
mat i
onoft
hef
il
edy
nami
cinf
ormat
ioni
snot
hingbutt
he
i
nfor
mationwhichi
sgett
ingupdated
Sy
ntax: t
ail-
ffi
l
ename
Theabov
ecommanddispl
ayslast10l
i
nesbydef
aul
twecanchanget
henumberofl
i
nesby
usi
ngbel
owsynt
axt
ail
–ff i
lename
VIEDI
TOR:
Vii
sanli
needi
tort
hati
susedtomani
pul
atet
hedat
aoft
hef
il
ebyusi
ngv
iedi
torwecan
per
for
mthefol
lowi
ngacti
ons
1.Cr
eat
ingnewf
il
e
21
2.Modi
fyi
ngexi
sti
ngf
il
e
3.Tov
iewt
hef
il
e
I
nthev
iedi
torwehav
e3modesofoper
ati
ons
1.Commandmode
2.I
nser
tmode
3.Ex–commandmode
1.commandmode:
I
nthi
smodeal
lthekey
spr
essedbyt
heuserar
eint
erpr
etert
otheedi
torcommands
I
nthecommandmodethekeysthatarehi
tbytheusercannotdi
spl
ayedont
hescr
eenby
def
aul
twhenweopent
hefil
lusi
ngv i–edi
tori
twil
lopenitcommandmode
2.i
nser
tmode:
Thesemodepermitst
ousertoinser
tthedataandupdatet
hedat aanddel
etet
hedat
aeachof
theseoper
ati
onscanbeper
form onl
yafterchangi
ngoverf
rom commandmodet oi
nser
tmode
Thef
oll
owi
ngar
ethekey
sgot
othei
nser
tmode
i: t
ogot
othei
nser
tcommandf
rom commandmodeandt
oinser
tthedat
aatt
hecur
sor
posi
ti
on
I :
toi
nser
tthet
estatt
hebegi
nni
ngoft
hel
i
nei
rr
espect
iveoft
hecur
sorposi
ti
on
a :
toappendt
henextt
othecur
sorposi
ti
on
A :
appendt
hedat
aatt
heendoft
hel
i
nei
rr
espect
iveoft
hecur
sorposi
ti
on
3.commandl
i
ne:
h–mov
ethecur
soronechar
act
ert
othel
eft
l
-mov
ethecur
soronechar
act
ert
other
ight
j
-mov
ethecur
soronechar
act
ert
othedownt
hel
i
ne
k-mov
ethecur
soronechar
act
ert
othemov
ethecur
sorupont
hel
i
ne
w–mov
ethecur
soronr
ightont
hef
ir
stchar
act
eroft
henextwor
d
b–mov
ethecur
sort
othebackt
othef
ir
stchar
act
er
e–mov
ethecur
sort
otheendoft
hecur
rentwor
d
0(
zer
o)–t
ogot
othebegi
nni
ngoft
hecur
rentl
i
ne
$-t
ogot
otheendoft
hecur
rentl
i
ne
22
F–scr
oll
thewi
ndowf
orwar
ddi
rect
ion
B–scr
oll
i
ngwi
ndowbackwor
ddi
rect
ion
G–t
ogobegi
nni
ngl
astl
i
neoft
hef
il
e
nG–t
ogot
othebegi
nni
ngofnt
hli
neoft
hef
il
e
o–cr
eat
enewl
i
nebel
owl
i
neandi
ninser
tmode
O–cr
eat
enewl
i
neabov
ecur
rentl
i
neandi
nser
tmode
R– t
orepl
acet
het
extposi
ti
onf
rom cur
sorposi
ti
on
x–t
odel
etet
hechar
act
eratcur
sorposi
ti
on
nx–t
odel
etet
hent
hchar
act
eratcur
sorposi
ti
on
X–t
odel
etet
hechar
act
erl
eftt
othecur
sorposi
ti
on
dw–t
odel
etet
hewor
d
ndw -t
odel
etet
he‘
n’wor
ds
dd–t
odel
etet
hecur
rentl
i
ne
ndd–t
odel
etet
he‘
n’l
i
nes
d0(
zer
o)–t
odel
etet
het
extf
rom cur
sorposi
ti
ont
obegi
nni
ngoft
hel
i
ne
d$-t
odel
etet
het
extf
rom cur
sorposi
ti
ont
oendoft
hel
i
ne
u–t
oundot
hel
astcommandchange
U–t
oundoal
lchangesi
ncur
rentl
i
ne
J–t
ojoi
nbel
owl
i
net
othecur
rentl
i
ne
Ex–commandmodeopt
ions:
:
sh–t
empor
all
yret
urnt
otheshel
lforexecut
inguni
xcommand
:
w–t
osav
ethef
il
e
:
q–t
oqui
tthef
il
eaf
tersav
echanges
:
wq–sav
eandqui
t
:
q!–wi
thoutsav
equi
t
:
!pwd–t
oexecut
euni
xcommandswi
thoutexi
tfr
om v
i–edi
tor
:
nd–t
odel
etent
hli
ne
:
10d–t
odel
ete10l
i
nes
23
:
5,10d–t
omov
eli
ne‘
m’af
ter‘
p’
:
5mo2–t e5thl
omov i
neaf
ter2ndl
i
ne
:
m,nmop–t
omov
eli
nesm t
onaf
ter‘
p’
:
3,5mo2–t
omov
eli
nes3,
5li
neaf
ter2ndl
i
ne
:
m cop–t
ocopyl
i
ne‘
m’af
ter‘
p’
: ocopy5thl
5co2–t i
neaf
ter2ndl
i
ne
:
/pat
ter
nor/
str
ing–t
osear
chf
orapat
ter
ninal
i
ne
:
/tcs–t
osear
chf
orast
ri
ngt
csi
naf
il
e
:
?pat
ter
nor?st
ri
ng–t
osear
chf
orast
ri
ngi
nbackwor
dposi
ti
on
:
n–r
epeat
etol
astsear
chcommand
:
N–r
epeat
ethel
astsear
chcommandi
nopposi
tedi
rect
ion
:
sei
c–seti
gnor
ecase
:
senoi
c–setnoi
gnor
ecase
:
senu–setnumbert
othel
i
ne
:
senonu–setnonumber
FI
ND&REPLACE:
:
s/st
r1/
str
2–r
epl
acef
ir
stoccur
renceofst
r1wi
thst
r2i
ncur
rentl
i
ne
:
s/st
r1/
str
2/g–r
epl
aceal
loccur
renceofst
r1wi
thst
r2i
ncur
rentl
i
ne
:
m,ns/
str
1/st
r2-r
epl
acef
ir
stoccur
renceofst
r1wi
thst
r2f
rom l
i
nem t
on.
:
m,ns/
str
1/st
r2/
g–r
epl
aceal
loccur
renceofst
r1wi
thst
r2f
rom l
i
nem t
on
:
1,$s/st
r1/
str
2–r
epl
acef
ir
stoccur
renceofst
r1wi
thst
r2i
neachl
i
nef
rom f
ir
stl
i
net
oendof
t
heli
ne
:
1,$s/st
r1/
str
2/g–r
epl
aceal
loccur
renceofst
r1wi
thst
r2i
neachl
i
nef
rom f
ir
stl
i
net
oendof
t
heli
ne
:
1,.s/
str
1/st
r2–r
epl
acef
ir
stoccur
renceofst
r1wi
thst
r2f
rom f
ir
stl
i
net
ocur
rentl
i
ne
:
1,.s/
str
1/st
r2/
g–r
epl
aceal
loccur
renceofst
r1wi
thst
r2f
rom f
ir
stl
i
net
ocur
rentl
i
ne
:
.$s/
str
1/st
r2 –r
epl
acef
ir
stoccur
renceofst
r1wi
thst
r2f
rom cur
rentl
i
net
oendofl
i
ne
:
.$s/
str
1/st
r2/
g–r
epl
aceal
loccur
renceofst
r1wi
thst
r2f
rom cur
rentl
i
net
oendofl
i
ne
24
:
%s/
str
1/st
r2/
g–t
orepl
aceal
loccur
rencei
nal
ll
ines
COPYPASTE:
y
y–t
ocopycur
rentl
i
ne
ny
y–t
ocopy‘
n’l
i
nes
y
0(zer
o)–copyf
rom cur
sorposi
ti
onoft
hel
i
ne
y
$-copyl
i
nef
rom cur
sorposi
ti
onofl
i
ne
p–past
ecopi
edl
i
nes
TEE:
Teecommandisusedt
othrowtheout
putofanycommandt
oanyf
il
easwel
last
omaket
he
out
puttobedi
spl
ayonthescr
een
Ex:
Catf
il
e1|
teef
il
e2
Theabovecommanddi
spl
ayst
hef
il
e1cont
entont
hescr
eenaswel
lasi
twi
l
lcopyt
heout
putt
o
fi
l
e2[over
writ
e]
l
s |t
ee f
il
e2
Theabovecommanddispl
ayst
heout
putofl
scommandont
hescr
eenaswel
lasi
tcopi
est
he
out
puttofi
le2[
over
ri
de]
NOTE:
I
ffi
l
e2i
snotexi
stedt
hedat
aoff
il
e2wi
l
lbeov
erwr
it
tenwi
tht
hepr
evi
ouscommanddat
a
Byusi
ng–aopt
ionwecanmaket
hedat
atobeappendedt
othegi
venf
il
e
Ex: l
s |t
ee-
afi
l
e2
catf
il
e1f
il
e2f
il
e3|
tee-
afi
l
e4
Wecanuset
het
eecommandwi
thmul
ti
pleoper
ati
onsasbel
ow
catf
il
e1|head-
10|t
ee-
afi
l
e4
TR(
transl
ate)
:
t
rcommandisusedtotr
anslat
ethechar
act
erornumber
sar
eanyspeci
alchar
act
ersaswel
las
t
odelet
especi
fi
cchar
acter
s
Ex:t
r‘a-
z’‘
A-Z’<f
il
ename(
or)
t
r[:
l
ower
:][
:upper
:]<f
il
ename
25
Theabov
ecommandconv
ert
sthesmal
ll
ett
erst
ocapi
tal
let
ter
sint
hegi
venf
il
e
Ex:t
r‘‘‘
\t
’<f
il
ename(
or)
t
r[:
space:
]‘\
t’<f
il
ename
Q.howdoy
oumakespacesepar
atedf
il
eas(
,)separ
atedf
il
e
Ans:t
r‘‘‘
,
’<f
il
ename(
or)
t
r[:
space:
]‘,
’<f
il
ename
Ex:t
r‘‘‘
\n’ < f
il
ename (
or)
t
r[:
space:
]‘\
n’<f
il
ename
Theabov
ecommandconv
ert
sthespacest
onewl
i
nes
Ex:t
r-d‘
a-z’<f
il
ename
Theabov
ecommanddel
eteal
lal
phabi
t(smal
l
)fr
om at
oz
Ex:t
r-d‘
a’<f
il
ename
Theabov
ecommanddel
etel
ett
er‘
a’i
ntheent
ir
efi
l
e
Ex:t
r-d‘
0-9’<f
il
ename
Theabov
ecommanddel
eteal
lthedi
git
sint
hef
il
es
Ex:t
r-d‘
a-z’<f
il
ename
Theabov
ecommanddel
etesal
ltheal
phabet(
smal
landcapi
tal
)fr
om gi
venf
il
e
Q.howt
omakeaf
il
ewhi
chcont
ainsmul
ti
plel
i
nesasasi
ngl
eli
nef
il
e(or
)
Howt
oconv
ertal
lthenewl
i
neswi
thspaces(
or)
Howt
ojoi
nal
lthel
i
nesofaf
il
e
Ans:t
r‘\
n’‘‘<f
il
ename
I
NPUTANDOUTPUTREDI
RECTI
ON(
I/OREDI
RECTI
ON):
Dev
ice st
ream v
alue
Key
boar
d st
andar
dinput 0
Ter
minal
scr
een st
andar
dout
put 1
Ter
minal
scr
een st
andar
dout
puter
ror2
26
I
nev
eryoper
ati
ngsy
stem t
her
eisst
andar
dinputandst
andar
dout
putdev
ices
Inuni
xalsowehavest
andardinputthati
skeyboardandstandar
dout
putt
hati
ster
minal
scr
een
aswellasst
andar
doutputer
rorthatisal
soterminal
screen
Wecanmanaget
he(
redi
rect
)theout
putander
rorwi
th1and2v
alues
Ex:
catf
il
e1>f
il
e2 (
or) catf
il
e11>f
il
e2
I
ntheaboveexampl
ewehav
eusedsingl
eredi
rect
ionoper
atortocopythest
andardout
put[
by
def
aul
t‘1’
]ift
hecommandt
hroughanyer
rort
hatwil
lbedispl
ayedonthescreen
I
fwecan’
ttor
edi
rectt
heer
rorout
putt
osomeot
herf
il
ewecanusenumber‘
2’
Ex:catf
il
e22>f
il
e2
Iftheabovecommandt
hroughsanyer
rorthatwil
lber
edi
rect
edt
ofi
l
e2,
ifi
t’
sthr
oughsany
standardout
putt
hatwi
l
lbedispl
ayedonthescreen
Ex:catf
il
e1>f
il
e22>f
il
e3
Byusi
ngabov
ecommandwecanr edi
rectbot
hst
andar
dout
putandout
puter
rort
othespeci
fi
c
fi
l
enothi
ngwil
lbedi
spl
ayedont
hescreen
Ex:catf
il
e1>f
il
e22>&1
I
nt heabov
eexampl
ewehav
eused&1,
iti
susedt
ospeci
fyt
hesamef
il
enamewhi
chwehav
e
usedforst
andar
dout
put
di
ff:
di
ffcommandi
susedt
ofi
ndoutt
hedi
ff
erencebet
weent
wof
il
es
sy
ntax:di
fff
il
e1 f
il
e2
Thi
scommandwi
l
lshowt
hechangest
obemadei
nfi
l
e1t
obecomei
dent
ical
tof
il
e2
Intheoutputifweseeanykeywor
das‘c’i
tmeanschange,
ift
her
eisanyl
ett
eras‘
a’i
tmeans
add,ift
hereisanylet
ter‘
d’i
tmeansdelet
e
CMP:
cmpcommandi sal
sousedtofi
ndthedi
ff
erencebet
weent wofil
esbuti
twi
llnotshowt
he
di
ff
erences,
itshowsonl
ytheli
nenumberwherethefi
rstdi
ffer
encei
sfound
Sy
ntax:cmp f
il
e1 f
il
e2
ALIAS:
al
iascommandi
susedt
osett
heal
i
asnamef
oranycommand
Wi
thhel
pofal
i
asnamewecancr
eat
etheshor
tnamef
orf
requentandl
ongercommands
27
Sy
ntax:al
i
asal
i
asname=‘
anycommand’
Ex:al
i
asx=’
l
s–l
tr
’
Tounsett
heal
i
asnamewecanusebel
owsy
ntax
Sy
ntax:
unal
i
asal
i
asname
Tol
i
stoutal
ltheal
i
asnameswecanuseal
i
as
MAN:
Mancommandi
susedt
ofi
net
hei
nfor
mat
ionaboutanyuni
xcommandi
ndet
ail
Sy
ntax:man commandname
Ex:man cat
HI
STORY:
Hist
orycommandi
susedt
ofi
ndoutt
hecommandswhi
char
eent
eredbyuseri
nther
ecent
post
Wecanexecut
ethesamecommandwhi chwewer
eal
readyexecut
edwi
thhel
pof(
!)r
egr
ati
on
sy
mbolandsequencenumberofcommand
Ex:!200
SPLI
T:
Spl
i
tcommandi
susedt
ospl
i
tthef
il
eint
osmal
l
erf
il
es
Bydef
aul
tspl
i
tcommandspl
i
tthef
il
ewi
th1000l
i
nesf
il
es
Sy
ntax:spl
i
t-n f
il
ename
NOTE:Oncewespl
i
tthef
il
ethenewf
il
eswi
l
lbecr
eat
edwi
tht
henamei
nthesequenceas
bel
ow
Xab
Xac
Xad
-
--
-
-
--
-
Xzz
NOTE:
ifwewantt
ocr
eat
ethef
il
eswi
thr
equi
redst
art
ingoff
il
ewecanusebel
owsy
ntax
Sy
ntax:spl
i
t-n pr
akash
28
Out
put:pr
akashab
Pr
akashac
-
--
--
--
--
-
--
--
--
--
--
GREPCOMMAND:
(
Global
l
ysear
chf
orr
egul
arexpr
essi
onandpr
inti
t)
Gr
epcommandi
sbasi
cal
l
yusedt
osear
chf
ort
hel
i
neswhi
chast
hegi
venst
ri
ng
Sy
ntax:gr
ep(
opt
ion) ‘
str
ing’f
il
ename
Wi
tht
hegr
epcommandwecandomul
ti
pleoper
ati
onswi
tht
hebel
owopt
ions
Opt
ions:
-
c:(
count
)
I
tpr
int
sthenumberofl
i
nest
hroughcont
ainsgi
venst
ri
ngi
nthef
il
e
-
i:(
ignor
ecase)
I
tignor
est
hecasewhi
l
esear
chi
ngf
ort
hest
ri
ng
-
n:(
numberofl
i
nes)
I
tret
urnst
hel
i
nest
rough’
scont
ainsgi
venst
ri
ngal
ongwi
tht
hel
i
nenumber
-
v:(
ver
bose)
I
tret
urnst
hel
i
neswhi
chdoesnothav
ethegi
venst
ri
ng
-
w:(
exactwor
d)
Tosear
chf
ort
hel
i
neswhi
chast
heexactst
ri
ng
-
l:(
li
stoft
hef
il
es)
Tosear
chf
ort
hef
il
enamest
hroughcont
ainsgi
venst
ri
ng
-
r:(
recur
siv
e)
Tosear
chfortheli
nesorfi
l
enamest
hathast
hegi
venst
ri
ngi
nal
lfi
l
esi
ncur
rentdi
rect
oryal
ong
wi
thall
subdi
rector
iesr
ecursi
vel
y
-
A:(
aft
er)
29
Itdi
spl
ayt
hel
i
net
hatcont
ainsspeci
fi
cst
ri
ngal
ongwi
thl
i
nesaf
tert
hel
i
net
hatcont
aingi
ven
stri
ng
-
B:(
bef
ore)
Itdi
spl
aythel
i
net
hatcont
ainsspeci
fi
cst
ri
ngal
ongwi
thl
i
nesbef
oret
hel
i
net
hatcont
ains
gi
venst
ring
-
C:(
commandbot
hA&B)
Itdi
spl
aytheli
net
hatcont
ainsspeci
fi
cst
ri
ngal
ongwi
thl
i
near
ound(
bef
oreandaf
ter
)thel
i
ne
t
hatcont
ainsgi
venst
ri
ng
^:
iti
susedt
osear
chf
ort
hel
i
nest
hroughst
art
swi
thgi
venst
ri
ng
$:
iti
susedt
osear
chf
ort
hel
i
nest
hroughendwi
thgi
venst
ri
ng
Q.howdoy
oudi
spl
ayt
o‘bl
ankl
i
ne’
inaf
il
e?
Ans:
grep“
^$”f
il
ename (
or)
gr
ep-
n“^
$”f
il
ename (
or)
gr
ep-
v .f
il
ename
Q.howdoy
oudi
spl
ayal
ll
inesoft
hef
il
ewi
thoutbl
ankl
i
nes?
Ans:gr
ep .f
il
ename (
or)
gr
ep -
v“^
$” f
il
ename
Q.howdoy
oucountt
heoccur
rencesofanyst
ri
ngi
nthef
il
e?
Ans:t
r‘‘‘
\n’<f
il
ename|
grep-
c“st
ri
ng”
Q.howdoy
oucountt
henumberofoccur
renceofeachandev
eryst
ri
ngi
nthef
il
e?
Ans:t
r‘‘‘
\n’<f
il
e|sor
t|uni
q-c
Gr
epwi
thandcondi
ti
on[
byusi
ng*
]:
Wecanusegrepcommandt osear
chforthemul
ti
plest
ri
ngsi
nsi
ngl
eli
net
hati
snot
hingbutt
he
l
ineswhi
chcont
ainsmul
ti
plerequi
redst
ri
ngs
Sy
ntax:
grep“
str
ing1.
*st
ri
ng2.
*st
ri
ng3.
*--
--
str
ingn” f
il
ename
*i
saspeci
alkey
wor
dthati
susedt
oper
for
mtheandcondi
ti
on
I
tmat
ches0(
zer
o)ormor
eoccur
rencesofpr
evi
ouschar
act
erorst
ri
ng
egr
ep(
or)gr
ep-
E:
30
Sy
ntax:
egr
ep“
str
ing1|st
ri
ng2|
str
ing3-
--
--
|st
ri
ngn“f
il
ename (
or)
gr
ep-
E“st
ri
ng1|
str
ing2|
str
ing3-
--
--
|st
ri
ngn“ f
il
ename
egr
epi
susedt
osear
chf
ort
hemul
ti
plest
ri
ngswecancal
l
edi
tasper
for
mingt
he‘
or’
condi
ti
on
Wecanuseal
ltheopt
ionsasweusi
nggr
epcommand
f
grep(
or)gr
ep-
F[f
ixedorf
astgr
ep]:
f
grepi
susedt
osear
chf
ort
hel
i
nesi
naf
ast
erwast
hant
hegr
epcommand
I
tdoesnotsuppor
tthespeci
alchar
act
erssuchas^
,$,
.(dot
),*
sy
ntax:f
grep“
str
ing” f
il
ename
gr
ep-
F“st
ri
ng” f
il
ename
NOTE:
Wecanuseal
ltheopt
ionsi
nfgr
epasweusi
nggr
epcommandbutwecannotusespeci
al
char
act
ers
PROCESS:
Apr
ocessi
sani
nst
anceofanypr
ogr
am
Whenwer unanycommandsorscr
ipt
soranypr
ogr
amsaspeci
fi
cpr
ocesswi
l
lgener
atedandi
t
cont
ainsonei
dwhichi
scall
edasprocessi
d
Theyar
e3t
ypesofpr
ocessi
nUni
xoper
ati
ngsy
stem
1.Daemonpr
ocess
2.Or
phanpr
ocess
3.Zombi
epr
ocess
1.DAEMONPROCESS:
Daemoni
sthepr
ocesswhi
chst
art
swhenwest
artt
heser
veroroper
ati
ngsy
stem
I
tkeepsr
unni
ngi
nthebackgr
oundunt
ilt
heser
veroroper
ati
ngsy
stem shoutdown
2.ORPHANPROCESS:
Or
phanpr
ocessi
sthepr
ocesswhi
chchi
l
dpr
ocessdoesnothav
ethepar
entpr
ocess
Gener
all
ywhenwest
artanypr
ocesst
hatpr
ocesscanspawnorcr
eat
eorcal
l‘
n’numberofsub
pr
ocesses
31
Thesubpr
ocessesar
ecal
l
edchi
l
dpr
ocesses
Themai
npr
ocesswhi
chspawnst
hechi
l
dpr
ocessi
scal
l
edpar
entpr
ocess
Whenever
yaparentprocessspawnsthechi
ldprocessitshouldacknowledget
hecompl
i
cat
ion
ofchi
l
dprocessandremov et
heentr
iesofchi
ldprocessfrom processt
able
I
nsomeabnormalcondi
ti
ons(net
wor
kissues)thepar
entpr
ocessmaygett
ermi
nat
edbef
ore
t
hechi
l
dprocessesasther
eisnopar
entprocessfort
hoseprocesses
I
nthi
scondi
ti
oninitwi
l
lhi
ret
hechi
l
dpr
ocess[
orphanpr
ocess]andr
emov
etheent
ri
esofchi
l
d
pr
ocessf
orm pr
ocesst
abl
e
I
nor
phanscenar
iomanual
act
ioni
snotr
equi
red
3.ZOMBI
EPROCESS:
Ifanypar
entprocessi
gnor
eoneoft
hechi
l
dpr
ocessest
hatchi
l
dpr
ocesswi
l
lbecomeas
zombieprocess
I
nthi
sscenari
othedetai
l
sofchildprocesswil
lnotgetr
emov
edbypar
entpr
ocessaswel
las
f
rom i
nitpr
ocessasital
readyastheparentpr
ocess
I
tleadst
olastofmemor
yleakagehencemanual
act
ioni
srequi
redt
ocl
earsuchki
ndofzombi
e
pr
ocess
Q.howt
oident
if
yzombi
epr
ocess?
Whenweuseps–elfwegetonecol
umnwhi
chshowspr
ocessst
atei
fthepr
ocessst
atei
sas‘
z’
i
tmeanst
hatpr
ocessiszombiepr
ocess
PS:
ps–u(
user
s)
ps–e(
eachandev
erypr
ocess)
ps–f(
ful
ll
ist
)
ps–l
(longl
i
st)
psaux(
all
user
sanyusername)
USAGE:
ps–uuser
name
ps–ef
ps-
elf
psaux
User
nameoruseri
d:whoi
nit
iat
edt
hepr
ocess
32
PI
D:pr
ocessi
d
PPI
D:par
entpr
ocessi
d
C:
numberofcpu’
sal
l
ocat
edt
othepr
ocess
PRI
:pr
ocesspr
ior
it
y
NI
:ni
cev
alue
St
ime:t
imewhent
hepr
ocessst
art
ed
Ti
me:
timet
hatt
her
esour
cesspendont
hepr
ocess
cmd:
commandorscr
ipt
%cpu:
%ofcpuspendont
hepr
ocess
%mem :
%ofmemor
yspendoft
hepr
ocess
STAT(
or)S:
processst
ate
t
ty:
ter
minal
typef
rom wher
ethepr
ocessi
srunni
ng
Pr
ocesspr
ior
it
yandni
cev
alue:
Pr
ocesspri
ori
tyi
snothi
ngbutthei
mport
anceoft
hepr
ocessandhowmuchat
tendancet
he
sy
stem r
esour
cesneedtospendonpr
ocess
Pr
ocesspr
ior
it
yrangesf
rom 0t
o39
0i
sthehi
ghpr
ior
it
y
39i
sthel
esspr
ior
it
y
Thedef
aul
tpr
ior
it
yis20
Wecancust
omi
ze/mani
pul
atet
hepr
ocesspr
ior
it
ybasedont
heni
cev
alue
PRI=20+ni
cev
alue
=20+(
-20)
=0
NI
CEVALUE:
Ni
cev
aluei
stheuserspacewhi
chi
susedt
odef
inedt
hepr
ior
it
y
Ni
cev
aluer
angesf
rom -
20t
o19
-
20i
shi
ghpr
ior
it
y
33
19i
slesspr
ior
it
y
Def
aul
tni
cev
aluei
s0(
zer
o)
Tost
artanypr
ogr
am wi
thspeci
fi
cni
cev
aluewecanusebel
owsy
ntax
Sy
ntax:ni
ce-
n pr
ocessname
Wecanr
eni
ceorsai
dtheni
cev
alueev
enaf
terwei
nit
iat
edt
hepr
ocess[
forr
unni
ngpr
ocess]
Sy
ntax:
reni
ce -
n-p pi
d
Ex:r
eni
ce-
n-20 1234
BACKGROUDPROCESS:
I
ngeneral
ifwerunanyprogr
am anUni
xter
minal
wecal
lthatpr
ocessasf
oregr
oundpr
ocess
whi
chisvi
sibl
etotheuser
Wecanrunthepr
ocessinscr
eenbackgroundwhichhel
pstorunthesomeot
herpr
ogr
amsin
t
hefor
eground,anypr
ocessthati
srunni
nginbackgroundi
scall
edasbackgr
oundpr
ocess
Torunthepr
ocessi
nthebackgr
oundwecanuse‘
&’oper
atoratt
heendoft
hecommand/
scr
ipt
Ex:abc.
sh&
I
fweusethe&torunt
heprocessi
nbackgr
oundt hecomplet
ionanderr
orswi
llbet
hroughon
t
hescr
eenatanypoi
nttoavoi
dthi
swecanredi
recterr
orsandoutputt
oanyfi
l
e
Ex:
“abc.sh>/
var/
temp/
fi
le2>&1&”
I
fweuse‘&”f
orthebackgr
oundprocessi
ftheuserl
ogoutf
rom t
hesessi
onaut
omat
ical
l
ythe
backgr
oundpr
ocesswil
lbeabor
ted
Toav
oidt
hisdr
awbackwehav
eonecommandcal
l
ed“
nohup”
NOHUP(
NOHANGUP)
:
Nohupcommandi
susedt
orunt
hepr
ocessi
nser
verbackgr
oundnoti
nthescr
eenback
gr
ound
Whenwer untheanyprocesswi
thnohupopt
ionweneedtouse‘&’
alsot
or unt
heprocessi
n
screenbackground.Itmeansyourunni
ngt
heprocessi
nthescr
eenbackgroundaswellasi
n
theserverbackground
Ex:
nohupabc.
sh&
Whenweusenohupcommandautomat
ical
l
ytheoutputwi
llbethr
oughtot
hef
il
ecal
l
ednohup.
out,
wecanredi
rectt
heout
putt
oanyfi
l
ebyusingredir
ect
ionoperat
or
Q.howt
obr
ingbackgr
oundpr
ocesst
ofor
egr
ound?
34
Jobs-
l:
Togett
hebackgr
oundpr
ocesst
ofor
egr
oundwecanusecommandcal
lfg
FG (
for
egr
ound):
Weneedtopasssequencenumbert
ofgcommandt
ogett
hepr
ocesst
ofor
egr
oundf
rom
backgr
ound
Ex:
fg 1 sequencenumber
f
g 2 sequencenumber
NOTE:i
fwedon’
tpassanysequencenumberbydef
aul
tthel
atestar
elastbackgr
oundr
unni
ng
pr
ocesswi
l
lcometothefor
eground
Q.howt
obr
ingf
oregr
oundpr
ocesswhi
chi
sal
readyr
unni
ngt
obackgr
ound
Ans:whil
eanypr
ocessi
srunni
ngi
fyoudo‘
cont
rol+c’t
hepr
ocesswi
l
lbeper
manent
ly
ter
minat
ed
Buti
fweuse‘
cont
rol
+z’
thepr
ocesswi
l
lbet
empor
ari
l
ysuspendedandwi
l
lbecameas
tempor
ari
l
y
Backgr
oundpr
ocess:
Wecanusebgcommandt
omaket
hepr
ocesst
oruni
nbackgr
oundwi
thhel
pofsequence
number
Ex:bg 1
NOTE:
I
fwedon’
tpassanysequencenumbert
obgcommandbydef
aul
tthel
atestsuspendedpr
ocess
wi
ll
becomeasbackgroundprocess
KI
LL:
Ki
l
lcommandi
susedt
oki
l
lthepr
ocessmanual
l
y
I
nkil
lcommandwehav
edi
ff
erentsi
gnal
swhi
char
epassedt
oki
l
lcommandbasedont
he
r
equi
rement
Sy
ntax:ki
l
l-si
gnalpi
d
35
Ex:ki
l
l-9 1234
NOTE:
Bydef
aul
t-15si
gnal
wil
lbepassedt
oki
l
lcommandi
fwedon’
tspeci
fi
canysi
gnal
Wegett
hepr
ocessi
dfr
om t
hepscommandt
henwecanpasst
hatpi
dtoki
l
lcommand
Q.howdoy
ouki
l
lthepr
ocesswheny
ouknowonl
ypr
ocessname
Ans: Byusingps-efcommandwecanli
stoutal
lthepr
ocessesi
ntheser
ver
,wecanpass
thatoutputtogr
epcommandt
osear
chforthel
ine
Q.whati
sthedi
ff
erencebet
weenki
l
l-9andki
l
l-15?
Ki
l
l-9andki
l
l-15bot
har
eusedt
oki
l
lthepr
ocessi
nuni
xwi
thhel
pofpi
d
Wecanuseki
l
l-9whenweneedt
oki
l
lthepr
ocessgr
acef
ulandf
orcef
ull
y
Whenweneedtokil
ltheprocessnor
mall
ywecanuseki
l
l-15whi
chi
scal
l
edasnor
mal
kil
land
i
tist
hedef
aul
tsignaltot
heki l
lcommand
Ki
l
l-9wi
l
lpasst
hesi
gnal
cal
l
edsi
gki
l
l
Ki
l
l-15wi
l
lpasst
hesi
gnal
cal
l
edsi
gter
m
Q.howt
oident
if
yki
l
landzombi
epr
ocess?
Byusi
ngps–elf(or
)psauxwecangettheprocessesi
nfor
mati
onal
ongwi
tht
hest
ateoft
he
pr
ocess.I
fthepr
ocessst
atei
s‘z’
itmeansi
t’
szombi epr
ocess
Byusi
ngbel
owcommandwecanl
i
stoutonl
yzombi
epr
ocesses
ps–el
f|gr
ep-
Iw’
z’
Oncewehavet
hepi
doft
hepr
ocesswecant
rykil
li
ngitwi
thki
l
l-9commandsomet
imest
his
commanddon’
twor
kast
hepr
ocessi
sdeadprocess
wecant
ryki
l
l-1thati
ssighubsignal
bypassi
ngthepid,
incaseift
hisoncealsodoesn’twork
t
henwecanpassppid[par
entpr
ocessid]t
okil
l-17(
sigchil
d)toki
llal
lthechil
dprocesses
I
ncasei
fthi
sonceal
sodoesn’
twor
kthenweneedt
oki
l
lthepar
entpr
ocess
KI
LLALL(
or)PKI
LL:
Ki
l
lal
lorpki
l
lisusedt
oki
l
lthepr
ocessbypr
ocessname
NOTE:
Ifwepasstheprocessnametokil
lorpki
l
lifanyotherprocessorwhi
char
erunni
ngi
nthe
serv
erwit
ht hesamekeyword(name)wealsogetkil
led
Sy
ntax:ki
l
lal
l–(
signal
)pr
ocessname
Pki
l
l–(
signal
)pr
ocessname
36
PGREP(
processgr
ep)
:
I
tisusedt
oli
stoutt
hepr
ocessesbasedonpr
ocessname
Sy
ntax:pgr
ep-
l‘pr
ocessname’
Out
put
:pi
dpr
ocessname
CRONTAB:
Cr
ont
abi
saschedul
i
ngcommandwhi
chi
susedschedul
ether
epet
it
ivet
asksi
ntheser
ver
Thi
siscal
l
edasj
obschedul
i
ngcommand
Toschedul
ethej
obwecanusebel
owsy
ntax
Sy
ntax:cr
ont
ab-
e(edi
t)
Onceweusecr
ont
ab-
ethel
i
stofj
obs[
ifany
thi
ngar
eal
readyexi
stedwi
l
lbeopeni
na‘
vimode’
Wecanedi
ttheol
djobsandwecanhav
enewent
ryf
ort
henewj
ob
Onel
i
necont
ainssi
xfi
eldswhi
chi
sequal
toonej
ob
FI
ELDS:
mi
n hour
s dom moy dow scr
ipt
mi
n–mi
nut
esst
art
sfr
om 00-
59
hour
s–hour
sst
art
sfr
om 00-
23
dom -dat
eofmont
hst
art
sfr
om 1-
31
moy–mont
hofy
earst
art
sfr
om 1-
12
dow–dayofweekst
art
sfr
om 00-
06
00–Sunday
01–Monday
02–Tuesday
03–Wednesday
04–Thur
sday
05–Fr
iday
06–Sat
urday
Scr
ipt
:anygi
venscr
ipt
NOTE:
37
Ifwespeci
fyst
ar(
*)i
ntheanyf
iel
ditmeanssuchasev
erymi
nut
e,ev
eryhour
,ev
erydayand
etc
I
fwespeci
fyt
wov
aluesunderanyf
iel
dwi
th(
,)comasepar
atedi
tmeansand
Ex:
11,
15 11mi
nut
eand15mi
nut
e
I
fwespeci
fyt
wov
aluesunderanyf
iel
d‘_
’separ
atedi
tmeansr
ange
Ex:
01-
12 f
rom hour1t
ohour12
I
fweuse*
/anyv
aluei
tmeansev
erynt
hval
ue
Ex:*
/2 onceandev
ery2hour
s
NOTE:
*-ev
ery
,/-
and,--r
ange,
*/n–ev
erynt
hval
ue
Exampl
eforcr
ont
abent
ri
es:
Q.Schedul
eaj
obt
orunatmi
dni
ght12am ev
eryday
?
Ans: mi
n hour
s dom moy dow scr
ipt
00 00 * * * abc.
sh
Q.Schedul
eaj
obt
orunf
orev
eryhour
?
Ans mi
n hour
s dom moy dow scr
ipt
00 * * * * abc.
sh
Q.Schedul
eaj
obwhi
chr
unatev
eryThur
sdayat7:
10am?
Ans: mi
n hour
s dom moy dow scr
ipt
10 07 * * 04 abc.
sh
Q.Schedul
eaj
obwhi
chr
unsonev
erySat
urdayandSundayat8:
59am?
Ans: mi
n hour
s dom moy dow scr
ipt
s
59 20 * * 6,
0 abc.
sh
Q.Schedul
eaj
obwhi
chr
unsonal
lweekday
sat8:
59pm?
Ans: mi
n hour
s dom moy dow scr
ipt
s
59 20 * * 1-
5 abc.
sh
Q.Schedul
eaj
obwhi
chr
unsatf
ir
stofev
erymont
hifi
tisf
oll
owi
ngonMonday
?
Ans: 00 00 1 * 1 abc.
sh
Q.Schedul
eaj
obwhi
chr
unsatev
eryt
wohour
s?
38
Ans: 00 *
/2 * * * abc.
sh
Q.Schedul
eaj
obt
orunatoncei
nev
ery10mi
nut
es?
Ans: *
/10 * * * * abc.
sh
Q.Schedul
eaj
obwhi
chr
unsatoncei
nev
ery30seconds?
Ans:i
ncront
abwecannotschedul
eaj
obf
orl
esst
hanami
nut
easwedon’
thav
esecondsf
iel
ds
i
ncrontab
Speci
alkeywor
dsi
ncr
ont
ab:
@y
ear
ly 00 00 1 1 * abc.
sh
@mont
hly 00 00 1 * * abc.
sh
@weekl
y 00 00 * * 00 abc.
sh
@dai
l
y 00 00 * * * abc.
sh
@hour
ly 00 * * * * abc.
sh
@r
eboot whi
chr
unsaf
terev
eryr
eboot
Cr
ont
ab–l
:
Cr
ont
ab–l
isi
susedt
oli
stoutal
lent
ri
esofcr
onj
obswi
thoutopeni
ngt
hroughcr
ont
ab–e
Cr
ont
ab–r:
I
tisusedt
oremov
eal
lent
ri
esofcr
on
Q.howt
otakebackupofal
lcr
onj
obs?
Cr
ont
ab -
l>anyf
il
e
Q.howt
odepl
oyal
lthej
obs(
ent
ri
es)f
rom af
il
etocr
ont
ab?
Sy
ntax:
Cront
ab f
il
ename
NOTE:i
fweuseabov
ecommandal
ltheexi
sti
ngent
ir
eincr
ont
abwi
l
lber
epl
acedwi
thent
ri
esi
n
t
hefi
le
Q.t
herei
soneproduct
ionser
verwhi
chi
sget
ti
ngmygr
adet
onewser
ver
,Iwantt
ocopyal
lthe
j
obstonewser
ver
Ans:
fir
stwecant
aket
heal
lent
ri
esofcr
ont
abt
oaf
il
eint
heol
dser
ver
Cr
ont
ab –l>/
var/
temp/
fil
e
Thenwecant
ransf
ert
hatf
il
etonewser
verbyusi
ngsf
tporscpcommand
Oncewehav
ethef
il
einnewser
verwecandepl
oyt
hatf
il
eent
ri
esbyusi
ngbel
owcommand
39
cr
ont
ab f
il
ename
FI
ND:
Fi
ndcommandisusedtosear
chforthef
il
esanddir
ect
ori
esbasedont
her
equi
rementaswel
l
astogett
hecompl
etepat
hofthefi
le(or
)dir
ect
ory
I
tisv
eryusef
ulcommandt
ofi
ndt
hef
il
esanddi
rect
ori
eswhenwedon’
tknowt
hel
ocat
ionof
t
hefi
le
Sy
ntax: f
inddi
rect
oryt
ost
artsear
chi
ng -
typef(
or)–t
yped -
requi
rementscenar
ioor
f
orf
il
esanddi
rect
ori
es r
equi
redst
ri
ng
bydef
aul
tcur
rentdi
rect
ory bydef
aul
tbot
h
Sear
chf
ort
hef
il
esanddi
rect
ori
esbasedonname:
Ex:
find .–t
ypef -
name “
abc*
”
Theabov
ecommandsear
chf
ort
hef
il
esundercur
rentdi
rect
orywhi
chwi
thabci
nthename
NOTE:
I
nthedi
rect
oryf
iel
difwement
ion‘
/’i
tmeansr
ootdi
rect
ory
Ex:
find .–t
ypef-
iname “
*.sh”
Theabov
ecommandi
gnor
ethecasewhi
l
esear
chi
ngf
ort
hef
il
es
Sear
chf
ort
hef
il
esanddi
rect
ori
eswhi
char
eempt
y:
Ex:
find.–t
ypef -
empt
y(or
)
Fi
nd .–t
yped -
empt
y
Di
spl
ayonl
yfi
l
esordi
rect
ori
eswi
thoutanyr
equi
rement:
Ex:
find.–t
ype f(
or)
f
ind.–t
ype d
Sear
chf
ort
hef
il
esanddi
rect
ori
esbasedonper
missi
ons:
Ex:
find.per
m 755
Topasst
hemul
ti
pler
equi
rement
s
Ex:
find.–t
ypef-
name “
*.sh” -
per
m 755
Sear
chf
ort
hef
il
esanddi
rect
ori
esbasedonl
i
nks:
Ex:
find.–l
i
nks +2 mor
ethan2
40
2 exact
ly2
-
2 l
esst
han2
Sear
chf
ort
hef
il
esanddi
rect
ori
esbasedoni
nodenumber:
Ex:
find .–i
num 1234
Sear
chf
ort
hef
il
esanddi
rect
ori
esbasedonsi
ze:
Ex:
find.–t
ypef -
size+10K
Sear
chf
ort
hef
il
esbasedonchar
act
ers,
wor
dsandl
i
nes:
Ex:
find.–t
ypef -
size +10C
Sear
chf
ort
hef
il
esanddi
rect
ori
esbasedonaccess,
creat
edandmodi
fi
edt
ime:
Forday:
Ex:f
ind.–t
ypef -
ati
me +10
-
cti
me 10
-
mti
me -
10
Formi
nut
es:
Ex:
find .–t
ypef -
ami
n +10
-
cmi
n 10
-
m mi
n -
10
Q.sear
chf
ort
hef
il
esanddi
rect
ori
eswhi
char
ecr
eat
ed5hour
sbef
ore?
Ans:
find .–cmi
n +300
XARGS& -
EXEC:
Xar
gsandexecbot
hareusedt
opasst
heli
stofar
gument
sfr
om pr
evi
ouscommandandsend
asonebyonear
gumentt
onextcommand
Xar
gs:
I
fweusexar
gst
hecommandwi
l
lwor
kint
hebel
owway
Ex:
find .–cmi
n-10|
xar
gsr
m –r
Vi
ewofexecut
ion
r
m –r f
il
e1 f
il
e2 f
il
e3-
--
--
41
I
ntheabov
escenar
iot
hecommandwi
l
lwor
kingsi
ngl
eshor
t
Exec:
Fi
nd .–cmi
n-10–exec r
m –r{}\
;
I
ntheabov
escenar
iot
hecommandwi
l
lexecut
edf
ormul
ti
plet
imes
Q.howt
oki
l
lal
lthepr
ocessor
swhi
char
enamedaspr
oxywi
thoutusi
ngki
l
lal
l(or
)pki
l
l
Ans:
ps-
ef|
grep–i‘
proxy
’|cut-
d‘‘-
f2|
xar
gski
l
l-9(
or)
ps-
ef|
grep-
i‘pr
oxy
’|awk-
F‘‘‘
{pr
int$2}
’|xar
gski
l
l-9
Q.r
emov
eal
lthef
il
eswhi
char
emor
ethan10GBi
nsi
ze
Ans:f
ind .–t
ypef-
size+10G -
execr
m –r
f{}\;(
or)
Fi
nd .–t
yped-
size+10G -
execr
m –r
f{}\;
Q.r
emov
eal
lthef
ileswhi
char
eol
dert
han1mont
h?
Ans:
find.-t
ypef-
cti
me +30
MAXDAPTHANDMI
NDEPTHI
NFI
NDCOMMAND:
Maxdepthandmi
ndept
hbot
har
eusedt
oli
mit
izet
hesear
chwhi
l
esear
chi
ngf
ort
hef
il
esand
di
rect
ori
es
Maxdept
h:
Maxdept
hisanopt
ionwhi
chi
susedt
oli
mit
izesear
chwhi
l
esear
chi
ngf
ort
hef
il
es&di
rect
ori
es
Ex:f
ind -
maxdept
h3-i
name 100
Theabovecommandsear chforthefi
leswhichasthename100andi twil
lsearchf
ort
hef
il
es
onl
yincurrentdi
rect
oryi
twil
lnotsearchfi
lesi
nsubdirect
ori
esaswespeci f
iedmewit
hmax
dept
hoptionifwespecif
iconeitwil
lsear
chonlyinthecur
rentdi
rect
ory
I
fwespeci
fy‘
2’i
twi
l
lsear
chf
orcur
rentdi
rect
oryaswel
lasonedi
rect
oryi
nsi
de
I
fwespeci
fy‘
3’i
twi
l
lsear
chf
orcur
rentdi
rect
oryandt
wodi
rect
ori
esi
nsi
de
Mi
ndept
h:
I
tisal
soanopt
ionsi
mil
art
omaxdept
hwhi
l
eli
mit
izet
hesear
ch
Themindept
hcr
it
eri
aisexact
ly‘
1’i
twi
l
lsear
chf
ort
hef
il
efr
om cur
rentdi
rect
oryt
omaxi
mum
al
ll
evel
s
I
fiti
s‘2’
itwi
l
lsear
chf
ort
hef
il
eaf
teronedi
rect
oryf
rom cur
rentdi
rect
ory
42
I
fiti
s‘3’
sear
chf
rom af
ter‘
2’di
rect
oryf
rom cur
rentdi
rect
ory
Sy
ntax:f
ind -
mindept
h2-
iname 100
Therearefewpr
ocessest
hatar
erunni
ngwi
thnamecal
l
edABC,
howcany
ouki
l
lal
lthose
processesatat
ime
Ps-
ef|
grep-
w“abc”|
cut-
d““-
f2|
xar
gski
l
l-9
FREECOMMAND:
Fr
ee:
I
tisav
eryusef
ulcommandt
ocheckt
hememor
yut
il
izat
ionoft
heser
ver
Thecommandwil
lsot
hecompl
eteinf
ormat
ionsuchaswhati
stot
almemor
y,whati
sbuf
fer
memory,
whati
sswapmemoryetc
Mai
lX:
Mai
lXcommandi
susedt
osendt
heemai
l
sfr
om uni
xser
vert
oanyr
ecept
ions
Wecankeepr
ecept
ioni
ntol
i
st,
inccaswel
lasi
nbcc
Sy
ntax:
Mai
lX-
s(subj
ect
)-cmai
l
ids -
bmai
l
ids t
oli
stmai
l
ids
-
s subj
ect
-
ccc(
car
boncopy
)
-
b bcc(
bli
ndcar
boncopy
)
Aft
erwehi
tmail
Xcommandthepr
omptwil
lactf
orthedat
awhichisasmessagebodywecan
ent
erasmuchaswewantt
hent
ypecont
rol
+d(or)‘
.
’toexi
tfr
om thecommand
Q.sendanemai
lwi
thsubj
ectandmessagebodywi
thsev
eral
recept
ionsi
ntol
i
stwi
thmai
lX
command?
Mai
lX-s‘
sampl
e’abc.
com,
xyz.
com,
xnt
.com -
--
--
- ent
er
Q.sendanemai
lbypassi
ngsomecont
ext(
inf
ormat
ion)asabodyoft
heemai
l
?
echo“
hai
Iam -
--
-“|
mai
l
x–s“
subj
ect
”to-
li
str
ecept
ion
Q.sendanemai
lwi
thf
il
eout
putasbodyoft
heemai
l
?
Catf
il
ename|
mai
lx-
s“subj
ect
”to–l
i
st(
or)mai
li
dsr
ecept
ions
Q.sendanemai
lwi
thf
il
easat
tachment
?
43
Wi
tht
hemai
lXcommandwehav
etousecommandcal
l
eduuencodet
oat
tachanyf
il
est
othe
emai
l
uuencode “
fi
let
oat
tach”“
fi
let
obeat
tachedwi
thdesi
redname”|
mai
lX–s“
subj
ect
”
Q.sendanemai
lwi
thmul
ti
plef
il
esasat
tachment
?
(
uuencode f
il
e1f
il
e1f
il
e2f
il
e2-
--
--
)|mai
lX-
s“subj
ect
”mai
l
ids
Q.sendanemai
lbyat
tachi
ngmul
ti
plef
il
esaswel
laswi
thsomecont
extasbodyoft
heemai
l
?
(
echo“
Iam x“
,uuencodef
il
e1f
il
e1;
uuencodef
il
e2f
il
e2;
---
--
)|mai
lX-
s“subj
ect
”mai
l
ids
Q.sendanemai
lwi
thmul
ti
plef
il
esasat
tachedaswel
lasf
il
econt
entasbodyoft
heemai
l
?
(
catf
il
e;uuencodef
il
e1f
il
e1;
uuencodef
il
e2f
il
e2;
---
-)|
mai
lX -s“
subj
ect
”mai
l
ids
NOTE:
Whi
l
esendi
nganemai
ltomul
ti
pler
ecept
ionsweneedt
osepar
atet
hem wi
th‘
,
’
df:
dfcommandi
susedt
ocheckt
heusageofv
ari
ouspar
ti
ti
onsandf
il
esy
stemsdi
ski
nfor
mat
ion
(har
ddi
sk)
Ex:
df
fi
l
esy st
em t
otal
space usedspace av
ail
abl
espace usedspacei
n%
part
it
ion
NOTE:
Bydef
aultdfcommandshowsinf
ormationaboutal
lpar
ti
ti
ons,
togett
hedet
ail
sofspeci
fi
c
par
tur
it
ionsweneedtopasst
hatpart
it
iontodfcommand
Ex:
df/
expor
t/dat
a/00(
or)f
il
esy
stem
NOTE:
Bydefaul
tdfcommandshowstheinformati
oni
nblocksf
ormat
,togett
hei
nfor
mat
ioni
n
ki
loby
teaswellasi
nhumanreadableformatwecanuse–kand–h
Ex:
df-
k/expor
t/dat
a/00(
or)f
il
esy
stem
df-
h/expor
t/dat
a/00(
or)f
il
esy
stem
DU(
dir
ect
oryusage)
:
ducommandi
susedt
ofi
ndt
hesi
zeofsubdi
rect
ori
esandf
il
esundercur
rentdi
rect
ory
Ex:
dudi
rname
pwd
44
/
var/
tmp
Hk/
var/
tmp/
a
10k/v
ar/t
mp
12k/
var
/tmp/b
2k m
3k n
NOTE:
Togetthei
nfor
mat
ioni
nki
l
oby
teaswel
lasi
nhumanr
eadabl
efor
matwecanuse–kand–h
opt
ion
Q.di
splaytop10mostdi
skoccupi
edf
il
esanddi
rect
ori
es[
whi
chcont
ainsmor
esi
ze]under
cur
rentdi
rector
y?
du–k|
sor
t–nr|
head-
10
TAR:
t
arcommandi
susedt
ocol
l
ectt
hef
il
esanddi
rect
ori
esandmakeasonear
chi
vedf
il
e
Sy
ntax:t
ar-cv
ftarf
il
ename f
il
esordi
rect
ori
est
otar
c cr
eat
e
v v
erbosel
ydi
spl
ay
f f
il
ename
Ex:
tar-cv
ffi
l
e.t
arf
il
e1f
il
e2f
il
e3-
--
--f
il
en
NOTE:
Oncewecr
eat
ethet
arf
il
ewecansendt
hatt
oanyser
veraswel
laswecanzi
pthatt
arf
il
e
Cr
eat
ecompr
essed[
zipped]t
arf
il
e:
Sy
ntax:
tar-
cvzff
il
e.t
arf
il
e1f
il
e2f
il
e3-
--
-f
il
en
Di
spl
ayt
hef
il
esi
ntarf
il
ewi
thoutext
ract
ing:
Sy
ntax:t
ar-
tvff
il
e.t
ar
Tr
anspar
ent(
or)di
spl
ay
45
Ext
ractt
hef
il
esi
ntarf
il
e:
t
ar-
xvff
il
e.t
ar
NOTE:
Bydef
aul
ttarcommandext
ract
sthef
il
est
ocur
rentdi
rect
ory
,toext
racti
ttospeci
fi
cdi
rect
ory
weneedt
ouse- copt
ion
Ex:
tar-
xvff
il
e.t
ar-
c/v
ar/
temp
Ext
ractdesi
redf
il
esf
rom t
arf
il
e:
t
ar-
xvff
il
e.t
ar f
il
e1f
il
e2 f
il
e3
ZI
P:
Zi
pcommandi
susedt
oreducet
hesi
zeoff
il
esanddi
rect
ori
es
Sy
ntax:zi
pfi
l
e.zi
pfi
l
est
ozi
pped
Tozi
pal
lthef
il
esi
nspeci
fi
cdi
rect
ory
:
zi
pfi
l
e.z
ip/
var/t
mp/*
Tozi
pal
lthef
il
esandsubdi
rect
oryf
il
esr
ecur
siv
ely
zi
p-rf
il
e.zi
p/v
ar/
tmp/
*
Tounzi
pthezi
ppedf
il
es:
Sy
ntax:unzi
p f
il
e.zi
p
Li
stt
hef
il
esi
nzi
ppedf
il
ewi
thoutunzi
ppi
ng:
unzi
p-lf
il
e.zi
p
Unzi
pthespeci
fi
cfi
l
efr
om t
hezi
ppedf
il
e:
unzi
pfi
l
e.zi
pfi
l
e1 f
il
e2-
--
--f
il
en
gzi
p(gunzi
p):
gzi
pal
soanusef
ulcommandt
oreducet
hedi
skspacebycompr
essi
ont
hef
il
es
Sy
ntax:gzi
pfi
l
est
ocompr
essed
Ex:gzi
pfi
l
e1f
il
e2 f
il
e3-
--
--f
il
en
46
gzi
pthef
il
esbykeepi
ngt
heor
igi
nal
fil
e:
bydef
aul
twegzi pcommandt
hef
il
eswi
l
lrenameas.
gzext
inct
ion,
wecanuse-
copt
iont
o
keept
heori
ginal
fil
easi
tis
sy
ntax:
gzi
p-cf
il
e1>f
il
e1.
gz
Toz
ipal
lthef
il
esi
ncur
rentdi
rect
oryal
ongwi
thal
lsubdi
rect
ori
esf
il
esr
ecur
siv
ely
:
Sy
ntax:
gzi
p-r* f
oral
lfi
l
esgzi
p
Tounzi
pthegzi
pfi
l
es:
Sy
ntax:
gunzi
pfi
l
e.gz
gunzi
p-r* f
oral
lfi
l
esunz
ip
NOTE:
Toseet
hezippedfi
lecont
entwecannotusecommandsl
i
kecat
,vi
andv
iewweneedt
ouse
commandscall
edzcatandless
Tosear
chf
oranypat
ter
n[gr
ep]i
nthegzi
pfi
l
ewehav
etousezgr
ep
Ex:zgr
ep“
pat
ter
n” f
il
e.gz
NETWORKI
NGCOMMAND:
Pi
ng:
Pi
ngcommandi
susedt
ofi
ndoutt
heser
verst
atusweat
hert
heser
veri
sup&r
unni
ngornot
Sy
ntax:
pingi
paddr
ess(
or)ser
vername
NOTE:
Whenweuset heabovecommandwewi l
lgeti
nfor
mationsomemuchofpocket
sanddataas
beengett
ingtr
ansmi
t,att
heendoftheout
puti
fwesee0%pocketlossi
tmeansserv
erinup
andrunni
ngifweseeany%ofpocketl
ossmeansserv
erisdown
Host
name:
Sy
ntax:
host
name
I
tisusedt
ofi
ndoutt
heser
vernameorl
oggedi
n
Host
name-
i:(
ipaddr
ess)
I
tisusedt
ofi
ndoutt
hei
paddr
essofcur
rent
lyl
oggedi
nser
ver
47
Upt
ime:
Upti
mecommandisusedtofi
ndoutt
hel
ostr
eboot
edt
imei
nawayhowl
ongt
heser
veri
sup
andrunni
ngt
imef
rom l
astr
eboot
I
ntheout
putwecanal
soseet
hel
oadav
erageoft
heser
verf
orl
ast1mi
nut
eand15mi
nut
e
Who-
b:
I
tshowt
hel
astr
eboot
edt
imeoft
heser
ver
nsl
ookup:
i
tisusedt
ofi
ndoutt
heser
vernamewhenweknowt
hei
paddr
essorv
icev
ersa
nsl
ookup i
paddr
ess orhost
name
I
fconf
ig:
I
tisusedt
ofi
ndoutt
henet
wor
kconf
igur
ati
onser
ver
Net
stat:
Netst
atcommandisusedt
ofindoutt
henet
workstr
ati
coftheser
versuchast
hemachi
ne
connect
edtowhi
chremoveserv
erpor
tnumberandthest
atusoft
heportet
c
Sy
ntax:net
stat
net
stat|
head–10
Net
stat-
a:
Iti
susedtofi
ndoutaboutal
lpor
twhi
char
eli
sti
ngaswel
laswhi
char
eest
abl
i
shedt
he
connect
ion
Net
stat-
l:
I
twi
l
ldi
spl
ayonl
ythepor
twhi
char
eli
steni
ng
Q.howdoy
ouf
indoutwhet
hert
hepor
tisl
i
steni
ng(
act
ive)ornot
net
stat-
l|gr
ep“
por
tnumber
”
net
stat-
p:
i
tisusedtof
indoutt
heconnect
ionofr
emot
eser
veral
ongwi
thpr
ocessi
d’swhi
char
eusedt
o
connect
48
Fi
l
etr
ansf
ercommands:
I
nuni
xwehav
e3di
ff
erentcommandst
otr
ansf
ert
hef
il
esf
rom oneser
vert
oanot
herser
ver
4
1.FTP
2.SFTP
3.SCP
FTP&SFTP:
(fi
l
etr
ansf
erpr
otocol
andsecur
efi
l
etr
ansf
erpr
otocol
)
f
tpandsf
tpbot
hhast
hesamesy
ntaxest
hef
oll
owi
ngsy
ntaxescanbeusedi
nanycommand
sy
ntax:
sft
phost
name(
or)i
paddr
ess
user
name:
passwor
d:(
or)
sf
tpuser
name@ host
nameori
paddr
ess
passwor
d:
Sy
ntaxt
otr
ansf
ert
hef
il
es:
Sf
tp>putf
il
ename
I
tisusedt
oputt
hef
il
einr
emot
eser
ver
Thefi
l
enamewhatwear
ecopy
ingshoul
dbei
nthepr
esentwor
kingdi
rect
orywhenwear
enot
gi
vi
ngabsol
utepat
h
Bydef
aultt
hefil
ewi l
lbecopi
edt
otheremoteserv
er’
shomedi
rect
ory
,ify
ouwantt
ocopyi
tto
someotherdi
rect
ionsweneedtospeci
fydi
rect
ory
Ex:
sft
p>putf
il
ename/
ver/
tmp
Formul
ti
plef
il
es:
sf
tp>mputf
il
e1f
il
e2f
il
e3-
--
--
fi
len (
or)
sf
tp>mputf
il
e*
FORDI
RECTORI
ES:
sf
tp>put-
rdi
rect
ory
49
Fr
om r
emot
eser
vert
ocur
rentser
ver
:
sf
tp>get f
il
ename
NOTE:
Bydef
aul
tthef
il
ewi
l
lbecopyt
opr
esentwor
kingdi
rect
oryofcur
rentser
ver
Sy
ntax:
sft
p>get f
il
ename /
var
/tmp
Formul
ti
plef
il
es:
sf
tp>get f
il
e1f
il
e2f
il
e3-
--
-fi
l
en(
or)
sf
tp>getf
il
e*
Fordi
rect
ori
es:
sf
tp>get-
rdi
rect
ory
Wecanexecutesev
eral
uni
xcommandsi
nsf
tppr
omptwi
thoutexi
tonwi
thoutl
ogi
ntot
he
cur
rentser
ver
Toexecut
eanycommandi
ncur
rentser
verf
orm sf
tppr
omptwehav
etouse‘
!
’negat
iont
hen
command
Ex:
!pwd
I
fwepasst
heanycommandwi
thout(
!)negat
iont
heandwi
l
lruni
nremot
eser
ver
Insft
ppr
omptwecannotuseal
lcommandst
ofi
ndoutwhi
char
ethecommandsuppor
tedby
sft
pwecanty
pe‘hel
p’
cd t
ochanget
her
emot
eser
vercur
rentdi
rect
ory
l
cd t
ochanget
hel
ocal
ser
vercur
rantdi
rect
ory
l
s t
oli
stt
her
emot
eser
vercur
rentdi
rect
oryf
il
es
l
l
s t
oli
stt
hel
ocal
ser
vercur
rentdi
rect
oryf
il
es
pwd t
ofi
ndoutr
emot
eser
ver
spr
esentwor
kingdi
rect
ory
l
pwd t
ofi
ndoutcur
rentser
ver
spr
esentwor
kingdi
rect
ory
Toexi
stf
rom t
hesf
tppr
omptwecanuse
By
e(or
)!(
or)
exi
t
50
Q)di
ff
erencesb/
wft
pandsf
tp?
1whenweuseftptheencr
ypt
ionoft
hef
il
esmaydonear
emaynotbedonewhi
l
etr
ansf
ert
he
f
il
efr
om oneser
vertoanot
her
2whenweusesf
tpt
heencr
ypt
ionmustbedonewhi
l
etr
ansf
err
ingt
hef
il
es
3t
hepor
tnumberf
tpi
s‘21’
4t
hepor
tnumberf
orsf
tpi
s‘22’
NOTE:
sf
tpr
un’
sov
ersshhencet
hepor
tnumberf
orsf
tpi
s‘22’
SCP:
(secur
ecopy
)
scpi
sal
sousedt
ocopyt
hef
il
esordi
rect
ori
esf
rom oneser
vert
oanot
her
NOTE:
Weneedt
oest
abl
i
shanyconnect
ionwhi
l
eusi
ngscp
Sy
ntax:
scpf
il
enameuser
name@ i
paddr
ess(
or)host
name:/
dir
ect
orypat
htocopyt
othef
il
e
Ex:
scpf
il
e1pr
akash@ abc.
prod.
lav
a:/
var
/tmp
Fordi
rect
ori
es:
Sy
ntax:
Scp-rdir
ect
oryname username@ i
paddr
essorhost
name:
/di
rect
orypat
htocopyt
he
di
rector
y
Ex:
scp–r/
dir
1/di
r2pr
akash@ abc.
prod.
lav
a:/
var/
tmp
Copy
ingf
il
esanddi
rect
ori
esf
rom r
emot
emachi
net
olocal
machi
ne:
Syntax:
scpuser
name@ host
nameori
paddr
ess:
fil
etar
getf
il
esav
ingdi
rect
oryi
nlocal
serv
er
Ex:
scpuser
name@ abc.
prod.
l
ava:
/var/
tmp /
dir
1/di
r2
Fordi
rect
ori
es:
Scp-
ruser
name@ host
nameori
paddr
ess:
dir
ect
oryt
argetdi
rect
orysav
ingdi
rect
oryi
nlocal
51
ser
ver
Ex:
scp-
rpr
akash@ abc.
prod.
lav
a:/
var/
tmp /
dir
1/di
r2
ssh:
(secur
eshel
l(or
)secur
esockethost
):
i
tisusedt
ologgingi
ntheremoteserv
erfrom cur
rentser
veraswel
lasexecut
ecommandar
e
scr
ipt
sofremoteser
verf
rom curr
entser
ver
Sy
ntax:
sshuser
name@{
host
nameori
paddr
ess}t
ologgi
ngi
ntot
her
emot
eser
ver
passwor
d:
ex:
sshpr
akash@ pr
od.
lav
a
passwor
d:
sy
ntax:
sshusername@ host
nameori
paddr
esscommandorscr
ipt
passwor
d: }t
oexecut
ether
emot
eser
vercommandsorscr
ipt
sinl
ocal
serv
er
ex:
sshpr
akash@pr
od.
lav
aabc.
sh
passwor
d:
i
nunixwehaveanopt
ioncal
l
edkey
gentocr
eat
epasswor
dlesspr
otocol
bet
weent
woser
ver
s
t
ocreat
ethekeywecanusebel
owsynt
ax
sy
ntax:
ssh–key
gen-
trsa[
rsa=r
emot
esecur
eaut
hent
icat
ion]
NOTE:
whenwecr
eat
ethekey
gent
hef
oll
owi
ngcomment
scanbeusedwi
thoutanypasswor
d
sf
tp,
scp,
ssh
Gener
ati
ngpubl
i
c|pr
ivat
e‘r
sa’
keypai
r
Ent
erfi
l
einwhicht
osav
ethekeyc|
home|
kash|
.ssh|
id–r
sa):
/home/
deskt
op(
fi
lenamet
o
wheret
hekeyhast
obecopy)
Ent
erpassphr
ase(
empt
yfornopassphr
ase):
passwor
dtopr
otectt
hef
il
e
52
Ent
ersamepassphr
aseagai
n:r
eret
urnt
hepasswor
d
Youri
dent
if
icat
ionasbeensavedinfi
leweneedt
ocopyt
heabov
efi
l
einr
emot
emachi
net
o
per
for
m passwordlessaut
henti
cati
on
Wecancopyt
hef
il
einr
emot
emachi
neusi
ngsf
tporscp
SED:
(st
ri
ngedi
tororst
ream edi
tor
)
sedcommandisusedt
orepl
acet
hestr
ingwit
hanotherst
ri
ng,
printt
hespeci
fi
cli
nesbasedon
thepat
ter
norl
i
nenumberaswell
asdel
etetheli
nesbasedonthepatt
ernorl
i
nenumber
sedcommandf
orr
epl
acementorst
ri
ngsubst
it
uti
on:
Byusi
ng‘
s’opt
ionwecanr
epl
acet
hest
ri
ngwi
thanot
herst
ri
ng
Sy
ntax:sed ‘
ns/
oldst
ri
ng/
newst
ri
ng/
g‘f
il
ename
n nt
hli
nenumber(
bydef
aul
tal
ll
ines)
Occur
rence nt
hoccur
rence(
bydef t1stoccur
aul rence)
g f
oral
loccur
rences(
g gl
obal
sear
ch)
Q.r
epl
acet
hest
ri
ngwi
thanot
herst
ri
ngi
nal
ll
inesoft
hef
ieat1stoccur
l rence
Ans:sed‘
s/ol
dst
ri
ng/
newst
ri
ng/
’fi
l
ename(
or)
sed‘
s/ol
dst
ri
ng/
newst
ri
ng‘f
il
ename
Ex:
repl
acet
hest
ri
ngwi
thanot
herst
ri yat4thl
ngonl i n2ndoccur
nei rence
Ans:sed ‘
4s/
oldst
ri
ng/
newst
ri
ng/
2’f
il
ename
Ex:
repl
acet
hest
ri
ngwi
thanot
herst
ri
ngi
nal
ll
inesandal
loccur
rences
Ans:sed‘
s/ol
dst
ri
ng/
newst
ri
ng/g’f
il
ename
Ex:
repl
acet
hest
ri
ngwi
thanot
herst
ri
ngf
rom 2ndl
i o7thl
net i
nei
nal
loccur
rences
Ans:sed‘
2,
7s/
oldst
ri
ng/
newst
ri
ng/
g’f
il
ename
Ex:
r epl
acet
hest
ringwi
thanot
herst
ri
ngi
nev
eryal
ter
nat
eli
nest
art
ingf
rom f
ir
stl
i
net
olastl
i
ne
nd
at2 occurr
ence
Ans:sed‘
1~2s/
oldst
ri
ng/
newst
ri
ng/
2‘f
il
ename
I
ntheabov
eexampl
ewehav
eusedt
il
t(~)sy
mbol
toski
pthespeci
fi
cnumberofl
i
nesbef
ore
53
r
epl
aci
ngt
hest
ri
ng
Thest
art
ingnumberspeci
fi
est
hel
i
nenumbert
ost
artwi
thandt
heendi
ngnumberspeci
fi
est
he
l
inest
oskip
Ex:r
epl
acet
hest
ri
ngwi
thanot
herst
ri
ngst
art
ingf
rom 2ndl
i
neandi
nal
ll
inesbyski
ppi
ng3l
i
nes
Ans:sed‘
2~3s/ol
dst
ri
ng/newst
ri
ng/
g’f
il
ename
NOTE:
All
thechangeswhichwemakeusi
ngsedcommandar
etempor
aryweneedt
oredi
rectt
he
outputt
oanyfil
eifrequi
red
Wecanuse‘
-
i’opt
iont
omaket
heper
manentchangeswi
thsedcommand
Ex:sed-
i‘s/
oldst
ri
ng/newst
ri
ng/g‘f
il
ename
Sedcommand-
eopt
ion[
ext
endabl
esed]
:
Byusi
ng–eopt
ionwecanpass‘
n’numberofr
equi
rement
stosedcommand
Ex:sed–e‘
2s/
oldst
ri
ng/
newst
ri
ng/
g f
ir
str
equi
rement
ss/
old/new/
g secondr
equi
rement
10s/ol
d/new/
4 t
hir
drequi
rement
12,
15s/
old/
new/
g f
our
thr
equi
rement
17~2/
old/new/
g‘f
il
enamel
astr
equi
rement
Q.howt
ocommental
ll
inesoft
hef
il
e?
Inanyf
il
e[speci
fi
cal
lyscr
iptfi
le]i
fweadd“#”att
hest
art
ingoft
hel
i
nei
tmeanst
hel
i
nei
s
commentedandthatli
newill
notgetexecut
ed
sed‘
s/^
/#/
’fi
l
ename
st
art
ingoft
hel
i
ne
Q.howt
orepl
acest
ri
ngwi
thnul
lval
uei
nal
ll
inesoft
hef
il
esandal
loccur
rences?
sed‘
s/ol
dst
ri
ng//g‘f
il
ename(
or)
sed‘
s/ol
dst
ri
ng//
g‘f
il
ename (mi
ddl
espacet
opr
esst
abbut
ton)
Q.howt
orepl
aceast
ri
ngwi
thanot
herst
ri
ngi
fthel
i
nest
art
edwi
thspeci
fi
cst
ri
ng?
sed‘
s/^ol
dst
ri
ng/newst
ri
ng/
g‘f
il
ename
54
Ex:sed‘
s/^r
am /Rahi
m /g‘f
il
ename
Qhowcanucommental
lthel
i
nesoft
hef
il
e?
Sed‘
s/^#//‘f
il
ename
Q.howt
orepl
acespeci
alchar
act
ersusi
ngsedcommand?
Ans:
wit
hsedcommandwehav
especi
alchar
act
erssuchas^
,$,
.&/
.
I
fweneedtorepl
acet
hesev
alueswi
thanyanot
herv
aluewehav
etoki
l
lthespeci
almeani
ngof
t
hesechar
act
ers
Wecanki
l
lthespeci
almeani
ngbypr
efi
xi
ng‘
\’bef
oret
othechar
act
er
Ex:
sed‘
s/\
^/p/‘f
il
ename
Ex:
sed‘
s/‘‘/,
/‘f
il
ename
Q.howt
ost
opanycr
ont
absf
orexecut
ion(
or)howt
ost
opt
hej
obbef
oreexecut
ion?
Ans:
int
hecr
ont
abfil
ewecanadd‘
#’att
hebegi
nni
ngoft
hel
i
nef
oranyj
ob,
thi
siscal
l
edas
commit
ti
ngt
hel
ine
I
fwecommentt
hel
i
net
hatspeci
fi
cjobwi
l
lnotbeex
ecut
ed
Q.howdoy
oucommental
lj
obsi
nthecr
ont
ab?
Ans:
cront
ab–l|
sed‘
s/^
/#/
’
Theabov
eoperati
oni
stempr
orar
y,ifwewantt
hepermanentchangesi
nall
cronentr
ieswe
needt
oredi
rectt
heout
putt
oanyfil
eandweneedthatf
il
etobedeployedwi
thcront
ab
St
ep1:
cront
ab–l|
sed‘
s/^/#/‘>new.
cron.
St
ep2:
cront
abnew.
cron.
Sedcommandt
opr
intt
hel
i
nes(
p):
Wecanusesedcommandt
opr
intt
hel
i
nesoft
hef
il
ebasedonpat
ter
naswel
lasbasedonl
i
ne
number
Sy
ntax:
sed-
n‘/pat
ter
n/p‘f
il
ename(
forpat
ter
nbased)
Sed-
n‘l
i
nenumberp’f
il
ename(
forl
i
nebased)
55
I
ntheabovecommand‘ -
n’i
susedt
osurpr
isether
epet
it
ivel
i
nest
obepr
int
ed,
ifwedon’
tuse
t
he‘-
n’opt
ionthedupl
i
cateli
neswi
l
lgetpr
inted
Q.pr
intt
hel
i
nesf
rom 1t
o4usi
ngsedcommand
Ans:
sed -
n‘1,
4p’f
il
ename
Q.pr
intt
hel
i
nesoft
hef
il
ewhi
chast
hespeci
fi
ckey
wor
d?
Anssed-
n‘/key
wor
dorst
ri
ngorpat
ter
n/p‘f
il
ename
Q.pr
intt
hel
i
nesf
rom 2ndl
i
net
il
lendoft
hef
il
ebyski
ppi
ng3l
i
nes?
Ans:
sed-
n‘2~3p’f
il
ename
Q.pr
intal
ter
nat
eli
nesoft
hef
il
est
art
ingf
rom 1stl
i
ne(
or)pr
intal
loddl
i
nesoft
hef
il
e?
Ans:
sed–n‘
1~2p’f
il
ename
Q.pr
intal
lev
enl
i
nesoft
hef
il
e?
sed-
n‘2~2p’f
il
ename
Q.pr
intal
ll
inesoft
hef
il
eapar
tfr
om 1t
o5?
sed-
n‘1,
5!p’f
il
ename
Q.pr
intt
hel
i
nesoft
hef
il
ewhi
chst
art
swi
thspeci
fi
ckey
wor
dusi
ngsedcommand?
Ans: sed-
n‘/
^key
wor
d/p‘ f
il
ename
Ex: sed-
n‘/
^ram /p‘ f
il
ename
Q.pr
intt
hel
i
neswhi
chendswi
thspeci
fi
ckey
wor
dusi
ngsedcommand?
Ans: sed-
n‘/
keywor
d$/p‘ f
il
ename
Ex: sed-
n‘/r
am $/p‘ f
il
ename
Q.pr
intt
hel
i
nesoft
hef
il
ewhi
chasonl
y3char
act
ersi
ntot
all
engt
hoft
hel
i
ne?
Ans: sed-
n‘/^
…$/p‘ f
il
ename
Q.pr
intt
hebl
ankl
i
nesusi
ngsedcommand?
Ans: sed-
n‘/
^$/p‘ f
il
ename
Q.pr
intnonempt
yli
nesusi
ngsedcommand?
Ans: sed-
n‘/
^$!/p‘ f
il
ename
56
Sedt
odel
etet
hel
i
nes(
d):
sed‘
/pat
ter
n/d‘ f
il
ename(
pat
ter
nbased)
sed‘
li
nenumberd‘f
il
ename(
li
nenumberbased)
-
if
orper
manentchanges
Ex:
del
etet
hel
i
nesf
rom 1t
o4usi
ngsedcommand
Ans: sed‘
1,4d‘ f
il
ename
Ex:
del
etet
hel
i
nesoft
hef
il
ewhi
chast
hespeci
fi
ckey
wor
d?
Ans: sed‘
/key
wor
dorst
ri
ngorpat
ter
n/p‘ f
il
ename
Ex:
del
etet
hel
i
nesf
rom 2ndl
i
net
il
landoft
hef
il
ebyski
ppi
ng3l
i
nes?
Ans: sed‘
1~2d’ f
il
ename
Ex:
del
eteal
lev
enl
i
nesoft
hef
il
e?
Ans: sed ‘
2~2d‘ f
il
ename
Ex:
del
eteal
ll
inesoft
hef
il
eapar
tfr
om 1t
o5
Ans: sed‘
1,5!
d‘ f
il
ename
Ex:
del
etet
hel
i
nesoft
hef
il
ewhi
chst
art
swi
thspeci
fi
ckey
wor
dusi
ngsedcommand?
Ans: sed‘
/^key
wor
d/d‘f
il
ename
Ex: sed‘
/^r
am /d‘ f
il
ename
Ex:
del
etet
hel
i
neswhi
chendswi
thspeci
fi
ckey
wor
dusi
ngsedcommand?
Ans: sed‘
/key
wor
d$/d‘
fi
lename
Ex:
del
etet
hel
i
nesoft
hef
il
ewhi
chasonl
y3char
act
ersi
ntot
all
engt
hoft
hef
il
e?
Ans: sed‘
/^...$/d‘ f
il
ename
Ex:
del
etebl
ankl
i
nesusi
ngsedcommand?
Ans: sed‘
/^$/d‘f
il
ename
Ex:
del
etet
henonempt
yli
nesusi
ngsedcommand?
57
Ans: sed‘
/^$!/d‘
fi
lename
Awk:
Awkcommandisusedtogener
atet
her
epor
taf
tert
hemani
pul
ati
onaswel
lasaf
tert
hef
il
ter
,it
per
for
mthefol
l
owingacti
on
1.I
tscansaf
il
eli
nebyl
i
ne
2.I
tscansal
ldat
aint
ofi
elds
3.I
tcompar
est
hei
nputl
i
neswi
tht
hepat
ter
n
Basi
csy
ntax:
awk[
act
ion] f
il
ename
j
ohn 1234 20 35 r
ecor
ds $0
al
ex 2586 30 45 r
ecor
ds $0
mat
ri
x3282 40 65 r
ecor
ds $0
v
inay 2796 60 89 r
ecor
ds $0
dav
id 2790 64 37 r
ecor
ds $0
f
iel
d1 f
iel
d2 f
iel
d3 f
iel
d4
$1 $2 $3 $4
Ex: awk‘
/al
ex/‘f
il
ename
Ans: al
ex 2586 30 45
Ex: awk‘
{pr
int$1}‘ f
il
ename
Ans: j
ohn
al
ex
mat
ri
x
di
nay
dav
id
Ex: awk-F““‘
{pr
int$2}‘ f
il
ename
NOTE:
58
Weneedtospeci
fyt
hef
iel
dsepar
atoraf
tert
he‘
F’
,weknowneedt
ospeci
fyi
fiti
swhi
tespace
separ
ator
Ex: awk-F““‘
{pr
int$1,
$2}‘ f
il
ename
Ans: 1234 20
2586 30
3282 40
3685 50
2790 37
Ex: awk ‘
/al
ex/{
pri
nt$4}‘ f
il
e
Ans: 45
Ex: awk ‘
/al
ex/‘
fil
e(or
)awk‘
/al
ex/{pr
int$0}‘
fil
e
Ans: al
ex 2596 30 45
Bui
l
tinv
ari
abl
es:
Wi
thawkcommandt
heyar
esi
xbui
l
tinv
ari
abl
eswhi
char
eusedt
ocust
omi
zet
hedat
a
FS f
iel
dsepar
ator(
bydef
aul
twhi
tespace)
RS r
ecor
dsepar
ator(
bydef
aul
tnewl
i
ne)
NF numberoff
iel
ds
NR numberofr
ecor
ds(
int
hesequence)
OFS out
putf
iel
dsepar
ator
ORS out
putr
ecor
dsepar
ator
FS,
RS,
OFS,
areusedi
nthebegi
ncl
asswi
thawkcommand
NF&NRcanbeusedatt
heact
ionpar
t
Ex: awk‘
{pr
intNR,
$0}‘f
il
e
Ans: 1-
--
--
-recor
d1
2-
--
--
-recor
d2
3-
--
--
-recor
d3
59
Ex: awk‘
/mat
ri
x/{pr
intNR,
$0}‘ f
il
ename
Ans: 3 mat
ri
x3282 40 65
Ex: awk‘
{pr
intNF}‘ f
il
ename
Ans: 5
NOTE:I
tshowsno.off
iel
dsi
neachr
ecor
d
Ex: awk‘
/vi
nay/{
pri
ntNF}‘ f
il
e
Ans: 5
Ex: awk‘
/vi
nay/{
pri
ntNF,
$0}
’fi
l
e
Ans: 5 v
inay 2790 37 37
Ex: awk‘
NF>1’ f
il
ename
Ans:
itwi
l
lbedi
spl
aycompl
etef
il
e
Ex: awk‘
NF<1‘ f
il
ename
Ans:
theabov
ecommanddi
spl
ayst
hebl
ankl
i
nes
Ex: awk‘
NF<1‘
‘{pr
intNR}‘ f
il
ename
Ans:
theabov
ecommanddi
spl
ayst
her
ecor
dnumberi
nsequencewhi
chi
sthebl
ankl
i
nes
Ex: awk‘
NR>1’ f
il
ename
Ans:t
heabov
ecommandext
ractal
lther
ecor
dapar
tfr
om f
ir
str
ecor
d
Oper
ator
swi
thawkcommand:
Expr
essi
onmat
ches:
~ l
i
ke
!
~ notl
i
ke
Ar
themat
icoper
ator
s:
+ addi
ti
on
60
_ subst
ract
ion
* mul
ti
pli
cat
ion
/ di
vi
sion
Rel
ati
onal
oper
ator
s:
== equal
to
!= notequal
to
> gr
eat
ert
han
< l
esst
han
>= gr
eat
ert
hanequal
<= l
esst
hanequal
Logi
cal
oper
ator
s:
&& and
|
| or
! not
Ex: awk‘
$1~/j
ohn/{
pri
nt$0}
’fi
l
e
Theabov
ecommandpr
int
sonl
yther
ecor
dwhi
chcont
ainsj
ohni
nthef
ir
stf
iel
d
Ex: awk‘
$1!
~/j
ohn/{
pri
nt$0}
’fi
l
e
Theabov
ecommandpr
int
sal
lther
owswhi
char
enothav
ingj
ohnasf
ir
stf
iel
d
Ex: awk‘
$4~89{
pri
nt$0}
’fi
l
e
Ans: dav
id 2790 67 37
Ex: awk‘
{pr
int$4+$5}
’fi
l
e
Ans:
Ex: awk‘
{pr
int$4+100}
’fi
l
e
Ans:
Ex: awk‘
$4==65’
fi
le
61
Ans: mat
ri
x2796 40 65
Ex: awk‘
$5!
=278’ f
il
e
Ans:
Ex: awk‘
$1~/j
ohn/&&$4==35’ f
il
e
Ans:
Ex: awk‘
$1~/
vinay/|
|$3==50’ f
il
e
Ans:
Q.howdoy
oudi
spl
ayt
hej
obswhi
char
eschedul
edbet
ween9am t
o6pm i
ncr
ont
ab?
Ans: cr
ont
ab–l|
awk‘
$2>=09&&$2<=18
Awkcommandwi
thmul
ti
plel
ogi
cs:
Ex: awk‘
/john/-l
ogi
c1
>/ / -l
ogi
c2
>/ / -l
ogi
c3
>/ /{}‘f
il
ename-l
ogi
c4
Q.di
spl
ayt
hel
ogi
nfor
mat
ionwhi
chi
sinbet
weenspeci
fi
cti
met
ospeci
fi
cti
me
Ans: awk‘
/2018:
02:
05/
,/2018:
02:
01/‘f
il
e
$NF&$NR:
$NF&$NRbot
har
eusedt
ofet
cht
hel
astf
iel
dofar
owand1f
iel
dineachandev
eryr
ow
Q.howdoy
ouext
ractl
astf
iel
dorcol
umnofaf
il
e?
Ans: awk-
F““ ‘
{pr
int$NF}‘ f
il
ename
Q.ther
earecert
ainsal
eshappenedi
n2017,
Iwantt
ogett
otal
amountofal
lperchange
happenedi
nlastquart
er(
octtodec)
Sampl
efi
l
e:
01–01–2017 2000
02-02–2017 2000
62
02–03–2017 3000
02–04–2017 5000
05–05–2017 6000
05–03–2017 6000
01–10–2017 7000
04–10–2017 7000
05–10–20177000
06–11–2017 7000
06–12–2017 8000
07–12–2017 8000
Out
put
: awk‘
BEGI
N {sum =0:
}$1>=“01–10–2017“&&$1<=“31–12–2017“
sum =$2+sum
END {pr
intsum }
awkscr
ipt
ingandf
unct
ional
i
ty:
awkcommandcont
ains3di
ff
erentsect
ions
1.BEGI
N
2.ACTI
ONorBODY
3.END
1.BEGI
N:
Begi
nsect
ioni
sthepre-pr
ocessi
ngsect
ioni
tmustbeper
for
m bef
oredat
aget
spr
ocessedand
l
ogi
cgeti
mplemented.
I
nthebegi
nsecti
ononl
ywecandecl
areal
ltheuserdef
inedv
ari
abl
es[
x=1]andsy
stem def
ined
v
ari
abl
es[RS,FS,ORS,
OFS]
2.ACTI
ONorBODY:
I
ntheact
ionsect
ionwecanhav
eal
ogi
candmai
npr
ocessi
ngsect
ion
I
tisl
i
keal
oopt
hatkeepsoni
ter
ati
veunt
ilt
hel
astr
ecor
d
63
I
faf
il
econt
ains100r
ecor
dst
hebodysect
ionwi
l
lbeexecut
edf
or100t
imes
3.END:
I
nthe‘
end’
sect
ionwecanper
for
m postpr
ocessi
ng
I
tcont
ainsl
ogi
ctobeexecut
edaf
teral
li
nputdat
aget
spr
ocessed
awk‘
BEGI
N{} begi
nact
ion
execut
ion{}
execut
ion{}}act
ionorbody
end{}‘f
il
ename}endsect
ion
Exampl
e:
James,
30, sal
es,Rm, 2000,300
Al
ex, 40, mar
ket
, t
.a, 3000,400
John,50, f
inance, t
.l
, 1000,200
Mat
ri
x,60, admi
n,t
.l
, 2000,50
Dav
id,70, t
echy
,emp, 1500,100
Output
: awk‘
BEGI
N{FS=“,
”;OFS=““;
pri
nt“
ename
dnum dnamedesi
gnsal
ary i
ncent
ives“}
{pr
int$1,
$2,
$3,
$4,
$5,
$6}
END{pr
int“
/ndat
ahasbeenpr
ocesssuccessf
ul“}‘f
il
ename
Q.howdoy
oudi
spl
ayl
astst
ri
ngoft
hef
il
e?
Ans:
tai
l–lf
il
ename|
awk–F“
,”‘
{pr
int$NF}‘
Q.howdoy
oudi
spl
ayl
astchar
act
eroft
hef
il
e?
Ans:
tai
l–lf
il
ename|
awk–F“
,”‘
{pr
int$NF}‘
|rev|
cut–c1
64
TOP:
Topcommandi
susedt
ofi
ndoutt
hehi
ghestcpuandmemor
yut
il
izat
ionpr
ocesses
Bydef
aul
ttopcommandshowst
hepr
ocessest
hatar
etaki
ngmor
ecpu
I
fwepr
essM [
shi
ft+m]t
hepr
ocesswhi
char
etaki
ngmor
ecpuwi
l
lber
efr
eshedandpopul
ated
Theout
putoft
opcommandi
sasf
oll
ows
Theveryf
ir
stl
ineoft
opcommandshowst hei
nformat
ionf
orhowlongt heserv
erisup&
runni
ngandhowmanyuser
sareconnect
edandt hel
oadaver
ageoflast1mi n,5minand15
min
Thesecondli
neshowst
hei
nfor
mat
ionaboutt
otal
taskst
hatar
erunni
ngandsl
eepi
ng,
stopped
andzombie
I
nthet
hir
dli
nei
tdi
spl
aysal
lcpust
hatar
ebei
ngut
il
izeal
ongwi
th%ofut
il
izat
ion
I
nthef
our
thl
i
nei
tdi
spl
ayst
het
otal
memor
y[RAM]al
ongwi
thused,
buf
fer/
cacheandf
ree
memor
y
I
nthef
if
thl
i
nei
tdi
spl
ayst
heswapmemor
yinf
ormat
ion
Af
tert
heset
hepr
ocesser
’si
nfor
mat
ionwi
l
lbedi
spl
ayedoner
owf
oreachpr
ocess
FREE:
Fr
eecommandi
susedt
ofi
ndoutt
hememor
yinf
ormat
ioni
ntheser
ver
I
tshowst
hedet
ail
sofbuf
fer/cachememor
yandusedmemor
yandswapmemor
y
Bydef
aul
tthei
nfor
mat
ionwi
l
lbedi
spl
ayedi
nki
l
oby
tes
Togett
hei
nfor
mat
ioni
nGB’
swecan–g[
fr
ee–g]
Togett
hei
nfor
mat
ionbysummar
izi
ngwecanuse–topt
ion[
tpert
otal
][f
ree–t
],
usage:
free
–gt
Fr
eecommando/
pexampl
e:buf
fer/
cache:
40G
used :
50G
f
ree :
10G
swap :
10G
BUFFERMEMORY:
65
Buf
fermemoryisthetemporar
yhol
dingmemor
yfort
hedat
athati
sbei
ngt
ransf
err
edi
nthe
ser
vert
hroughext
ernaldev
ices
CACHEMEMORY:
Cachei
sal
sotemporar
yholdi
ngmemor yf
ort
hef
il
es/
dat
athati
sbei
ngut
il
izef
requent
lyi
tis
usef
ulf
orr
api
daccess[qui
ckaccess]
FREEMEMORY:
Fr
eememor
yist
heav
ail
abl
ememor
yfort
hepr
ocesses
SWAPMEMORY:
swapmemor
yist
headdi
ti
onal
memor
ythati
susedwhent
het
otal
memor
ygotconsumed
t
hememor
ywhi
chi
sbei
ngconsumedbyi
nact
ivepageswi
l
lbepul
l
edandconsi
derasswap
memor
y
Q.howdoy
our
esol
vecpu&memor
yut
il
izat
ioni
ssues?(
or)
I
fthecpuormemor
yisv
eryl
owont
heser
verwhatki
ndofact
ionsy
ouwi
l
ltaket
obr
ingi
nto
nor
mal?
Ans:
ifi
tisr
elat
edt
omemorywecant
ypef
ree–gttocheckt
hememor
ydet
ail
s,i
fiti
srel
ated
t
ocpuwecant y
pet
opt
ocheckt
hecpu’
sut
il
izat
ions
Ascpuandmemoryut
il
izebypr
ocesser
sar
eser
vicesweneedt
ocheckf
ort
hepr
ocesser
s
thosear
econsumi
ngmorecpu’
sormemory
Byusi
ngt
opcommandwecanpul
lthepr
ocesser
sinor
deronut
il
izat
ion(
or)
psaux|
sor
t–t““–nr
k4 f
ormemor
y
psaux|
sor
t–t““–nr
k3 f
orcpu
Wi
tht
hehel
pofPI
Dwecangett
hepr
ocessnameps–ef|
grep“
pid”
Oncewehav et
heprocessnamewecancheckt
heschedul
eti
meoft
hepr
ocess[
incr
ont
abor
anyschedul
i
ngtool
]
Wecancheckt
hepr
evi
ousr
unt
imi
ngsei
theri
nlogf
il
eori
nschedul
i
ngt
ool
66
I
fthepr
ocessi
sgoi
ngtocomplet
einnextfewminut
esthenwecancloselymoni
tort
he
memoryandwecanwai
tfort
heprocesstobecomplet
edwhichwi
ll
releasethememoryorcpu
I
ftheprocessi
sgoi
ngtorunforl
ongert
imethenbychecki
ngt
hepr
ior
it
ycr
it
ical
l
yor
i
mportancewecantaket
hejudgementt
okil
lthepr
ocess
Ift
hehighestmemor ytaki
ngprocessissocr
it
ical
totheproducti
onandwear ei
nasit
uati
on
l
ikenottokil
ltheprocessthem wecanpickt
hesecondhighestprocessandper
for
mstheall
checksasabov ebefor
ekil
lingt
heprocess
I
fall
theprocesser
swhi
charetaki
ngmor
ememor
yar
eimpor
tantweneedt
osel
ectt
hel
east
pr
ior
it
yprocessamongthem t
okil
l
Q.howdoyour
esol
vedi
skspacei
ssue(
or)i
fthef
il
esyst
emsorpar
ti
ti
onal
mostf
ull
,whatki
nd
ofact
ionsy
ouwi
llt
aket
ocl
eanit(
or)makesomespace
Ans:Oncewegett
hecpuut
il
izat
ioni
ssuewecant
ypet
opcommandt
ocheckt
hehi
ghestcpu
consumpti
onpr
ocess
Wecangett
hepr
ocessi
d&gett
hepr
ocessdet
ail
sbyusi
ngps–el
f|gr
ep pi
d
Oncewehavepr
ocessdet
ail
swecancheckwhent
hepr
ocessbeenst
art
edaswel
lashowl
ong
i
thasbeenr
unni
ng
I
ftheprocessisgoi
ngt
ocompl
etei
nfewsecondsormi
nut
esoft
imewecanwai
tandcl
osel
y
monit
ortheprocess
Iftheprocessisj
uststar
tandgoingtorunforalongtimethenwecaniftheprocessisstr
uk
withsomet hi
ngthentakeitact
iontoagai
nsttheprocessi
fthepr
ocessissti
llut
il
izi
ngthemore
cpuifthereisaneedtokil
l t
heprocessweneedt ocheckt
heimpactandcrit
ical
lyofthe
process
I
ftheprocessisver
ycrit
ical
&i mpactt
othepr
oduct
ioni
fweki
l
ledi
tthenwehav
etopi
csecond
hi
ghestprocessandrepeatthesameanal
ysi
s.
Q.i
ftherei
salogfi
l
ewhichi
scurr
ent
lybei
ngusedandwri
ti
ngsomedata,butIwon’
ttoclean
upt
hel ogf
il
ewit
houtr
emovi
ngthefi
l
eforthedi
skspacewhatki
ndofact
ionsyouwil
ltake?
Ans:
wecanmaket
hef
il
easempt
yfi
l
ebyusi
ngf
oll
owi
ngopt
ions
1.catf
il
e1>f
il
e1
2.>f
il
e1
3. cpu/
dev/
nul
lfi
l
e1
4.t
runcat
e-s0f
il
e1
67
UNI
XIMPORTANTQUESTI
ONS:
Q.Whati
sthef
lav
orofoper
ati
ngsy
stem t
haty
ouar
ecur
rent
lywor
kingon?
Ans:
Redhatl
i
nux
Q.whati
sver
sionofRedhatl
i
nuxcur
rent
lyusi
ng?
Ans:
6.1
Q.Howdoy
ouf
indoutwhatf
lav
orandv
ersi
onofO.
Sthatcur
rent
lyusi
ng?
Ans:Under‘
/etc’di
rect
oryt
heyi
saf
il
ecal
l
edr
elease.Whi
chcont
ainsi
nfor
mat
ionaboutal
l
det
ail
sofcurrentrunni
ngO.S
Q.Whati
sker
nel
ver
siont
hati
srunni
ngi
nwor
kingO.
S?
Ans:
Buusi
ngcommandcal
l
ed-uname-
a
Q.Whatar
ethet
ypesofshel
l
sinuni
xO.
S?
Ans:
sh–bor
nshel
l
Bash-bar
nagai
nshel
l
Csh–cshel
l
Tcsh-t
exi
scshel
l
Q.Whati
sshel
lthatf
requent
lyuse?
Ans:
bash
Q.Whati
sthedi
ff
erenceb/
wshel
l
s?
Q.Howt
ochanget
het
imest
ampoft
hef
il
ebyr
efer
ri
ngsomeot
herf
il
e?
Ans:
touch–rr
efer
encef
il
e r
equi
redf
il
e
Q.Howt
omakeaf
il
ewhi
chcont
ainst
hedat
aasaempt
yfi
l
e?
Ans:
catabc>abc
Q.Di
ff
erenceb/
wtouchandcatcommand?
Q.Whati
stheabsol
utepat
h?
Ans:
Inuni
xabsol
utepat
hisnot
hingt
hecompl
etepat
hofanyf
il
eordi
rect
oryf
rom t
her
oot
68
Q.Whati
sthehi
ddenf
il
eorhi
ddendi
rect
ory
?
Ans:I
fwecreateanyfi
leordi
rect
orywi
thpref
ixas(
.)bef
oret
othef
il
eordi
rect
orynamet
hat
wil
lbecomehiddenfi
l
eorhiddendir
ect
ory
Ex:
touch.
abc
Q.Howt
olongl
i
stasi
ngl
efi
l
e?
Ans:
ls–l
trf
il
ename
Q.Howt
olongl
i
stadi
rect
ory
?
Ans:
ls–l
ddi
rect
oryname
Q.Howt
oli
stoutal
lthef
il
esanddi
rect
ori
esi
nal
lsubdi
rect
ori
esr
ecur
siv
ely
?
Ans:
ls–R
Q.Howt
oident
if
yei
therst
ickybi
tissetonf
il
eordi
rect
ory
?
Q.Di
spl
ayonl
ythej
obst
hatar
eschedul
efr
om 9Am t
o6PM i
ncr
ont
ab?
Ans:
cront
ab–l
|awk–F““‘
$2>=9&&$2<=18’
jobname
Q.Howt
odi
spl
ayonl
yhi
ddenf
il
esundercur
rentdi
rect
ory
?
Ans:
ls–a|
grep“
^\.
”
Q.Howt
orepl
ace‘
/’wi
thl
ett
er‘
A’i
naf
il
einal
loccur
ences?
Ans:
sed‘
s/\
//A/
g’f
il
ename
Q.Lat
estcr
eat
edf
il
eshowt
omov
ein‘
X’v
ari
abl
e?
Ans:
X=`
ls–l
tr|
tai
l-1|
awk‘
{pr
int$NF}
’`
Q.Howt
odi
spl
ayl
ast3day
sfi
l
es?
Ans:Fi
nd.t
ype–f–ct
ime+3
Q.Howt
odi
spl
ayf
ir
standl
astl
i
nei
nonef
il
e?
Ans:
sed–n‘
1p;
$p’f
il
ename
Q.Howt
odi
spl
ayno.
off
il
esi
ncur
rentdi
rect
ory
?
Ans:
ls|
wc–l
Q.Howt
odi
spl
aydomai
nname?
69
Ans:
host
name–d
Q.howt
odi
spl
ayI
paddr
ess?
Ans:
host
name–I
Q.di
spl
ayt
hel
i
nest
hosear
est
art
ingwi
thdot(
.)t
ogi
venf
il
e?
Ans:
sed–n‘
/^\
./p’
fil
ename
Q.Howt
odel
etel
ast30day
slogf
il
es?
Ans:Fi
nd–ct
ime-
30|
grep“
*.l
og”|
xar
gsr
m –f
Q.howt
odi
spl
ayl
i
nesf
rom 50t
o60i
nagi
venf
il
e?
Ans:
head-
60f
il
ename|
tai
l-10
Q.Howdoy
ouf
indouthowmanyt
imeseachst
ri
ngi
sexi
stedi
nthef
il
e?
Ans:
tr‘
‘‘\
n’<f
il
ename|
sor
t-n|uni
q-c
Q.Howt
oident
if
yweat
herhar
dli
nki
scr
eat
edont
hef
il
eornot?
Q.Howt
oident
if
yweat
hersof
tli
nki
scr
eat
edont
hef
il
eornot?
SQLQUESTI
ONS:
Q.Wr
it
eaquer
ytodi
spl
ayt
opt
hreehi
ghestsal
ary
?
Ans:
sel
ectename,
salf
rom (
sel
ectename,
sal
from empor
derbysal
desc)wher
erownum <=3:
Q.Wr
it
eaquer
ytodi
spl
aysecondhi
ghestsal
ary
?
Ans:
sel
ectmax
(sal
)fr
om empwher
esal
<(sel
ectmax(
sal
)fr
om emp)
;
Q.Wr
it
eaquer
ytodi ay3rdhi
spl ghestsal
ary
?
Ans:
selectmax
(sal
)fr
om empwher
esal
<(sel
ectmax(
sal
)fr
om empwher
esal
<(sel
ect
max(sal
))
)fr
om emp;
Q.Wr
it
eaquer
ytodi ay2ndl
spl eastsal
ary
?
Ans:
sel
ectmi
n(sal
)fr
om empwher
esal
>(sel
ectmi
n(sal
)fr
om emp)
;
Q.Howt
odi
spl
aydupl
i
cat
erowsf
rom empt
abl
e?
Ans:
sel
ectempno,
count
(*)f
rom empgr
oupbyempnohav
ingcount
(*)>1;
Q.Del
etedupl
i
cat
erecor
ds?
70
Ans:
Del
etef
rom empwher
erowi
dnoti
n(sel
ectmi
n(r
owi
d)f
rom empgr
oupbyempno)
;