Sie sind auf Seite 1von 125

Jitendra Rathi, Lecturer, Engineering College Bikaner Page No.

1
Linux Commands
Introduction: Unix is the first oerating s!ste" in the #orld, de$eloed %! &e" 'ho"son and
(ennis Ritchie in 1)*) at Bell La% %! +',' Co"an!.
FSF: -ree soft#are foundation organi.ation, the! start a ro/ect %! na"e 0NU. 'he "ain ai" of
this ro/ect is to de$elo such a 1.2. that can run on an! latfor". 3n 1))1, a student Linux
'ar$alds de$eloed a kernel na"ed Linus &ernel lus 0NU alication called Linux 1.2.
Linux is an oen source technolog!. (ifferent co"anies that ro$ide Linux in "arket are
Redhat, 2u2e, 4andrake, 'ur%o, &noix, U%untu etc.
Linux Features:
5 Linux is the fastest oerating s!ste" in the #orld. 3t runs 6 to 7 ti"es faster than #indo#s 1.2.
5 Linux is the $er! secured 1.2. Because there is no an! ro%le" of $irus.
5 Linux file for"at is text for"at and #indo#s file for"at is %inar! for"at.
5 Linux is $er! relia%le oerating s!ste" %ecause kernel of Linux is $er! sta%le as co"are
to #indo#s kernel not crashed easil!.
5 'he linux kernel is $er! s"all8 it can store in flo! disk.
5 Linux sues the x9#indo#s s!ste" #hich is ad$anced net#ork #indo#ing s!ste". Using
this s!ste" #e can disla! outut of an! #orkstation "onitor attached in the net#ork.
Linux Advantages:
5 :irus Proof
5 Crash Proof
5 Econo"ical
5 4ultiuser, 4ulti deskto and "ultitasking
What is the shell?
'he shell in Linux is the interface through #hich !ou #ill carr! out "ost of !our #ork. ;hile it
see"s in out#ard aearance to %e unsohisticated, a lot of o#er is a$aila%le to the shell user, %! its
a%ilit! to co"%ine co""ands.
Available shells in Linux
+ nu"%er of different shells are a$aila%le in Linux, #hich cater for different needs. +t a %asic
le$el, the! all allo# !ou to enter co""ands, and redirect the outut of the co""ands to the
aroriate lace, %e it a file, or !our ter"inal.
'here are t#o "a/or schools of shells8 the sh fa"il!, and the csh fa"il!. ;hen onl! using the shell
as an interacti$e tool, the! are all reasona%l! si"ilar, #ith so"e shells ro$iding facilities to "ake
interacti$e use easier <such as aliases, rogra""a%le co""and co"letion and histories=. >o#e$er,
#hen using the shell to #rite scrits, there is a $er! large difference %et#een the different fa"ilies.
Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. 6
2o"e of the co""on t!es of shells are listed %elo#.
Linux shells
Na"e -eatures 2tartu -iles
sh Basic shell and al#a!s a$aila%le .rofile
%ash Co"letion, aliasing, histor! and al"ost
al#a!s a$aila%le
.%ash?rofile
.%ashrc
.inutrc
ksh Co"letion, aliasing, histor! and Non9standard .rofile
.sh Co"etion, aliasing, histor! and Non9standard ..shen$
..rofile
..shrc
..login
csh Co"letion, aliasing, histor! and al"ost
al#a!s a$aila%le
.cshrc
.login
tcsh Co"letion, aliasing, histor! and al"ost
al#a!s a$aila%le
.tcshrc
.login
Linux Filesystem:
'he files!ste" in Linux can %e seen as a tree, or hierarchical structure. E$er!thing starts #ith the
root di r ec to r y, also kno#n as slash and /.
Example Linux ilesystem layout
@
@%in @etc @ho"e @%oot @de$ @te" @ot @"nt @usr
@ho"e@/itendra @ho"e@ra/esh @usr@local @usr@%in
@ho"e@/itendra@ro/ects @ho"e@ra/esh@ro/ects
(12 $@s Linux
Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. 7
3f !ou are a%le to na$igate through 429(12 #ill %e a%le to ick u on the na$igation of L3NUA in
the follo#ing chart #e ha$e listed se$eral of the $arious si"ilarities of (12 and L3NUA.
!"S LI#$%
attri% ch"od
%acku tar, g.i, %.i6, .i
dir ls
cls clear
co! c
del r"
deltree r" BR or r"dir
edit $i, $i", ico
for"at fdfor"at, "ount, u"ount
"o$e @ rena"e "$
t!e less CfileD
cd cd, chdir
"ore C file "ore file
"d "kdir
#in startx or xter"
ls: (isla! all the files and directories resent in the current director!.
Usages 2!ntax9
ls EotionsFGE-ilesF
1tions:9
Bl :9 (isla! all the files, directories, their "ode. Nu"%er of links, o#ner of the file, grou of
the o#ner, file si.e, "odified date and ti"e and filena"e.
9t : (isla! files list %! last "odification ti"e
9a : (isla! all the files along #ith hidden files.
9d : (isla! director! files instead of contents.
9 : Puts a <@= slash sign at the end of each director!.
9u : (isla! files list %! last access ti"e.
9i : (isla! files inode infor"ation.
9r : (isla! files list in re$erse order
9x : (isla! "ulti colu"nar outut
92 : (isla! largest file first.
9ltr : (isla! files order %! date
9l2r : List files order %! file si.e.
E /itendra c H n t s e r $ e r IFJ ls
9l total KK
dr#xr9xr9x 6 go$indc staff KL)* (ec 66 LK:KM docu"ents
9r#9r99r99 1 go$indc staff NNO Jan 1 LM:7K iaddr.l
9r#9r99r99 1 go$indc staff 6)1 Jan 1 LO:1N stars.c
lr#xr#xr#x 1 go$indc staff O Jan 1 L*:1K t 9D tutorial
dr#xr9xr9x 7 go$indc staff KL)* Jan 1 L*:6K tutorial
9r#9r99r99 1 go$indc staff 7K Jan 6 LN:L) user.sh
E go$ind c H n t s e r $ e r IFJ
Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. K
Jls &l P more :9 (isla! all the co""ands age #ise
E /itendraH n t s e r $ e r IFJ ls 9l P
"ore total OKOK
9r#9r#9r99 1 /itendra /itendra 716 Jan 1N LK:K6 addstring.c
9r#xr#xr9x 1 /itendra /itendra NLLO Jan 1N LK:K6 a.out
9r#9r#9r99 1 /itendra /itendra O7OO*LO Jan K LK:6N %acku.tar.g.
dr#x999999 6 /itendra /itendra KL)* Jan 7 L*:LO ccna
9r#9r99r99 1 /itendra /itendra *61 +r 6L L):LL client.l
9r#9r99r99 1 /itendra /itendra KK7 +r 1N LN:KM c.l
9r#9r#9r99 1 /itendra /itendra KL1 Jan 1N LK:6K distance.c
9r#9r99r99 1 /itendra /itendra 7*1 Jan 1N LN:1K factorial.c
9r#9r#9r99 1 /itendra /itendra *N1 Jan 16 LN:76 filehandling.c
9r#9r#9r99 1 /itendra /itendra 1N6 -e% 1N 16:61 file.l
9r#9r99r99 1 /itendra /itendra 61N7 Jan 1N LN:1K future$alue.c
994ore99
Jls &a : (isla! files list including hidden <. dot files=
E /itendraH n t s e r $ e r IFJ ls 9a
. .%ash?logout .canna .gtkrc stars.c user.sh ..shrc
.. .%ash?rofile docu"ents iaddr.l t .$i"info
.%ash?histor! .%ashrc .e"acs .kde tutorial .xe"acs
E go$ind c H n t s e r $ e r IFJ
Jls Bli : (isla! files list #ith inode
nu"%er. E /itendraH n t s e r $ e r IFJ ls 9li
total KK
6KO7OKK6 dr#xr9xr9x 6 go$indc staff KL)* (ec 66 LK:KM docu"ents
6KO7OKK7 9r#9r99r99 1 go$indc staff NNO Jan 1 LM:7K iaddr.l
6KO7OKK1 9r#9r99r99 1 go$indc staff 6)1 Jan 1 LO:1N stars.c
6KO7OK61 lr#xr#xr#x 1 go$indc staff O Jan 1 L*:1K t 9D tutorial
6KO7OKNL dr#xr9xr9x 7 go$indc staff KL)* Jan 1 L*:6K tutorial
6KO7OKKN 9r#9r99r99 1 go$indc staff 7K Jan 6 LN:L) user.sh
E /itendraH n t s e r $ e r IFJ
Jcd Cdirector! na"eD :9 Change the current #orking director! to secified director!, relati$e to
the current location.
Jcd'' :9 0oto the arent director! of the current director!
Jcd I or f) ke! :9 4o$e to the userQs ho"e director! #hich is R@ho"e@userna"eS. 'he TIQ
indicates the users ho"e director!.
Jcd @ :9 (irectl! go into root director!
Jcd @%in :9 Change director! to @%in as a #orking director!
Jclear :9 Clears the screen
Jm(dir Cdirector! na"eD :9 Create a ne# director!
Jm(dir Cdirna"eD Cdirna"eD Cdirna"eD : Create 4ultile (irectories at the sa"e ti"e.
Jrmdir C(irector! Na"eD :9 Re"o$e a director! %ut does not delete all those directories #hich
are not e"t!.
Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. N
Jrmdir cs@language cs@ackage cs : Re"o$e "ultile directories at the sa"e ti"e.
Jp)d :9 (isla! ath of resent #orking director!
Jlogout or *d :9 for logout the current session
+ ro"t :9 Nor"al User
, ro"t :9 2uer$isor or Root user
Jsu :9 3t is use to gain suer user ri$ilege, it asks the root
ass#ord. E /itendraH n t s e r $ e r IFJ su
Pass#ord:
E roo t Hn t s e r $ e r go$indcFU exit
exit
E /itendraH n t s e r $ e r IFJ
Jmore filena"e : (isla! file contents Page #ise <Press - to Vuit=
Jmore file1 file6 file7 : (isla! all files age #ise
Note: The file .profile contains set of instructions that are performed when a user logs in. (It is
similar to Autoexec.bat of DOS)
Jman CUN3A Co""andD :9 -or >el and ress CVD to Vuit fro" hel
Jman shutdo)n :9 >el of 2hutdo#n Co""and
Jman ls &l :9 >el of a articular co""and
.istory: 'he histor! co""and is use to "aniulate the re$iousl! entered co""ands histor! list.
3t erfor"s se$eral oerations related to re$iousl! executed co""ands recorted in the histor! list
and these recorded co""ands referred to as en e$ent. +ll the e$ents are nu"%ered starting fro" 1
#ith histor! co""and. ;e can secif! e$ent nu"%er in a ositi$e for" or in a negati$e for".
E$ent L <.ero= reresents the current e$ent and 91 reresents the re$ious e$ent, 96 reresents one
%efore that and so on.
Usages s!ntax:
Jhistor! EotionsF arg1,arg6,G.
Jhistory :9 (isla! the list of co""ands that !ou ha$e entered %efore.
Jhistory /0 :9 (isla! last entered 1L co""ands. 3f !ou enter history 10 instead of
history /0 then disla!s last entered 6L co""ands.
#ote:9 By default history stores last 1000 commands which you hae run. If you want to change
then open !i "etc"profile and set #ISTSI$% & '000
Jhistor! clear: (eletes the entire histor! or use &e otion instead of clear.
2earching a co""and fro" histor! <ctrlWr= : 'o execute a long co""and #hich is re$iousl!
executed then search that co""and fro" histor! %! using ctrlWr ke!s. 'o search tar co""and
fro" histor! then ress ctrlWr at co""and ro"t and t!e tar, then ro"t disla! as follo#s:
Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. *
E /itendra c H n t s e r $ e r IFJ
<re$erse9i9search=XtarX: tar B.c$f %acku.tar.g.. @ho"e
'here after ress enter ke! to execute the co""and or ress left or right arro# ke!s to "odif!
the co""and fro" histor! and then execute.
Execute re$iousl! entered co""and Vuickl!: 'here are "an! #a!s to execute the re$iousl!
entered co""and Vuickl! #ithout t!ing the co""and.
1. '!e 22 and ress enter ke! to execute /ust re$ious co""and again.
6. Press up arrow (ey and ress enter ke!
7. '!e 23/ and ress enter ke!.
K. Press ctrl)p and ress enter ke!. 4*p disla!s re$ious co""and at ro"t=.
'o execute an! co""and fro" histor! Vuickl! then t!e 2 and so"e ke!#ords of the co""and
and then ress enter to executes the co""and. i.e. to execute grep co""and fro" histor! then
t!e *gre and ress enter.
Echo: 'he echo co""and rints the gi$en inut string to standard outut de$ice. 'he default
%eha$ior of echo is, rints the string on to standard outut and "o$e cursor into ne#line.
Usages 2!ntax:
Jecho EotionsF
EstringF
1tions:
9n (o not "o$e cursor into ne#
line.
9e 2uorts escae seVuence characters in %ash shell. B! default %ash shell does not suort
escae
seVuence characters.
-ollo#ing escae seVuence characters used #ith echo
co""and.
Ya alert <BELL=
YY %ackslash
Y% %acksace
Yc suress trailing ne#line character
Yf for" feed
Yn ne#line
Yr carriage return
Yt hori.ontal ta%
Y$ $ertical ta%
Jecho J>14E :9 'he ."5E $aria%le is use to find out the na"e of !our
ho"e director!.
E go$ind c H n t s e r $ e r IFJ echo J>14E
@ho"e@staff@go$indc
E go$ind c H n t s e r $ e r IFJ
.o) to ma(e a !os command in Linux
Jcls<= : (efine a -unction to "ake linux eVui$alent
Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. M
co""and.
DZ
Dclear
Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. O
D[
Jcls :9 Clears the screen
Jdate :9 (isla! current s!ste" date and ti"e
W\" : (isla! onl! 4onth Nu"%er
W\h : (isla! 4onth Na"e
W\] : (isla! ]ear <in !!!! for"at=
W\d : (a! of "onth <L1..71=
W\e : (a! of "onth, %lank added <1..71=
Jdate W\" or Jdate WS\h \"S
E /itendraH n t s e r $ e r IFJ date
2at Jun N 16:76:NL 32' 6L1L
E /itendraH n t s e r $ e r IFJ date W
\"
L*
E /itendraH n t s e r $ e r IFJ date W^\h \"^
Jun L*
E /itendraH n t s e r $ e r IFJ date W\-
6L1L9L*9LN
E /itendraH n t s e r $ e r IFJ date W\!9\"9\d
1L9L*9LN
E /itendraH n t s e r $ e r IF
J
Jbc : Basic Calculator, it is used for co""and line calculator. B! using #e can do
"athe"atical calculations. <to end of %c ress CtrlW(=.
2!ntax:
J%c EotionsF
9l
Use the "ath li%rar! functions and initiali.e scale to 6L, instead of default
$alue .ero.
filena"e 2ecif! the file na"e that contains the %asic calculator co""ands to %e calculated.
9V (o not rint initial %anner
9$ Prints %c co""and $ersion nu"%er and then exit.
E /itendraH n t s e r $ e r IFJ
%c %c 1.L*
Co!right 1))191))K, 1))M, 1))O, 6LLL -ree 2oft#are -oundation,
3nc. 'his is free soft#are #ith +B21LU'EL] N1 ;+RR+N'].
-or details t!e X#arrant!_.
1L W N
1N
1L`1L
1LL
M@6
7
scalea6
M@6
7.NL
#ote: #ere cal command displays calendar of Oct. +o. and Dec. '00,. -
Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. )
Note: By default bc command can.t display decimal places
scalea6 : 2ecif! nu"%er of deci"al laces.
ibasea6 : Con$erts Binar! Nu"%er into (eci"al Nu"%er.
obasea6 : Con$erts (eci"al Nu"%er into Binar! Nu"%er.
obasea1* : Con$erts (eci"al Nu"%er into >exadeci"al Nu"%er.
E /itendraH n t s e r $ e r IFJ %c
9V i%asea6
11LL1L1L
6L6
E /itendraH n t s e r $ e r IFJ %c
9V o%asea6
1K
111L
E /itendraH n t s e r $ e r IFJ %c
9V o%asea1*
1K
E
E /itendraH n t s e r $ e r IFJ
Jcal :9 (isla! calendar of current "onth and
!ear. Usages s!ntax:
cal EotionsF E"onthF
E!earF 1tions:
9s (isla! 2unda! as first colu"n.
9" (isla! 4onda! as first colu"n.
97 (isla! re$ious@current@next "onthQs calendar.
9! (isla! 16 "onths calendar of current !ear.
E /itendraH n t s e r $ e r IFJ cal
June 6L1L
2u 4o 'u ;e 'h -r 2a
1 6 7 K N
* M O ) 1L 11 16
17 1K 1N 1* 1M 1O 1)
6L 61 66 67 6K 6N 6*
6M 6O 6) 7L
E /itendraH n t s e r $ e r IFJ cal 97 11 6LL)
1cto%er 6LL) No$e"%er 6LL) (ece"%er 6LL)
2u 4o 'u ;e 'h -r 2a 2u 4o 'u ;e 'h -r 2a 2u 4o 'u ;e 'h -r 2a
1 6 7 1 6 7 K N * M 1 6 7 K N
K N * M O ) 1L O ) 1L 11 16 17 1K * M O ) 1L 11 16
11 16 17 1K 1N 1* 1M 1N 1* 1M 1O 1) 6L 61 17 1K 1N 1* 1M 1O 1)
1O 1) 6L 61 66 67 6K 66 67 6K 6N 6* 6M 6O 6L 61 66 67 6K 6N 6*
6N 6* 6M 6O 6) 7L 71 6) 7L 6M 6O 6) 7L 71
E /itendraH n t s e r $ e r IFJ
Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. 1L
Jcal L) 1MN6 :9 (isla! calendar of secified "onth and !ears <L) a 4onth No. , 1MN6 a ]ear=
E /itendraH n t s e r $ e r IFJ cal L) 1MN6
2ete"%er 1MN6
2u 4o 'u ;e 'h -r 2a
1 6 1K 1N 1*
1M 1O 1) 6L 61 66 67
6K 6N 6* 6M 6O 6) 7L
E /itendraH n t s e r $ e r IFJ
E /itendraH n t s e r $ e r IFJ cal 9s
June 6L1L
2u 4o 'u ;e 'h -r 2a
1 6 7 K N
* M O ) 1L 11 16
17 1K 1N 1* 1M 1O 1)
6L 61 66 67 6K 6N 6*
6M 6O 6) 7L
E /itendraH n t s e r $ e r IFJ
E /itendraH n t s e r $ e r IFJ cal 9"
June 6L1L
4o 'u ;e 'h -r 2a 2u
1 6 7 K N *
M O ) 1L 11 16 17
1K 1N 1* 1M 1O 1) 6L
61 66 67 6K 6N 6* 6M
6O 6) 7L
E/itendraHntser$er IFJ
Jino CLinux Co""andD :9 (isla! hel of a co""and. <Use Space/ar0 %nter
1ey0 2g3p 2gDn ke!s for scrolling in hel=
Jcat D filena"e :9 Create a ne# file <'o sa$e the file ress *d=
Jcat filena"e :9 (isla! the contents of a file <3t is sa"e as (12 ']PE Co""and=
Jcat C2ource file Na"eD D C'arget -ile Na"eD :9 Co! the contents of source file into
'arget file. 3f target is alread! exist then o$er#rite 'arget file
#ithout asking an! Vuestion.
Jcat C2ource -ile Na"eD DD C'arget file Na"eD :9 +end source file contents in
'arget file.
Jcat a` D ne#.txt :9 Co! all the files #hich ha$e the first character is Ca D into a
ne# file ne#.txt
Jcat first.txt second.txt DD "!.txt :9 Co! the contents of -irst.txt and 2econd.txt
file into a ne# file "!.txt
r" : 'he ^r"^ co""and is used for deleting a file or director! <folder=. 'he co""and na"e
^r"^ is deri$ed fro" ^re"o$e^.
Usages s!ntax:
Jr" EotionsF EfilesGF
1tions:
9i interacti$e delete, disla! ro"t %efore deletion so that #e can delete selected files.
9r, 9R Recursi$el! delete all the files and directories fro" current director! to lo#er "ost le$el of su%
directories.
9$ $er%ose "ode, disla! #hat is %eing done.
9f Re"o$e all files including #rite9rotected also #ithout ro"ting the user
Jrm filena"e :(elete the secified filena"e.
Jrm file1 file6 file7 : (elete list of files
Jrm ` : (elete all -iles
i : (elete selected file
Jrm Bi file1 file6 file7 : +sk er"ission <]@N= %efore deletion so that #e can
delete selected files.
Note: rm can.t delete all those files which are write protected0 /ut display prompt for remoing
)hoami :9 (isla! current login status
go$indc W ts@1 Jun N 16:N1 <g
E /itendraH n t s e r $ e r IFJ
Jrm Brf `
"$ : Rena"ing a filena"e or "o$e it fro" one director! to another director!
Jmv oldfilena"e ne#filena"e : Rena"ing a -ile Na"e <+lso use for Rena"ing a
(irector! Na"e=
Jmv oldfilena"e ne#filena"e oldfilena"e ne#filena"e : -or "ultile file Rena"ings
Note: mv co""and also use for "o$ing files fro" one director! to another
director!
Jmv f1.txt f6.txt cs : 4o$e files into cs director!.
J)ho :9 (isla! all the users #hich are currentl! log on in articular "achine
9> : (isla! #ith header otion
9u : (isla! "ore detail
E /itendraH n t s e r $ e r IFJ #ho
/itendra ts@L Jun N 16:76 </itendra9c=
go$indc ts@1 Jun N 16:N1 </itendra9
c= E /itendraH n t s e r $ e r IFJ
J)ho &>u
E /itendraH n t s e r $ e r IFJ #ho 9>u
N+4E L3NE '34E 3(LE P3( C144EN'
/itendra ts@L Jun N 16:76 . 1OOM) </itendra9
c= go$indc ts@1 Jun N 16:N1 . 1O)NM
</itendra9c= E /itendraH n t s e r $ e r IFJ
J)ho &' :9 (isla! all the users infor"ation the! can recei$e or canQt recei$e !our
"essages. 'he W sing indicates for Recei$e and B sign indicates for
CanQt recei$e an! "essage.
E /itendraH n t s e r $ e r IFJ #ho 9'
J
/itendra W ts@L Jun N 16:76 </itendra9c=
E /itendraH n t s e r $ e r IFJ
#hoa"i /itendra
E /itendraH n t s e r $ e r IFJ
itendra9c=
J)rite Cuserna"e6 :9 2end a "essage to a articular user <Press bd to -inish 4essage=
E /itendraH n t s e r $ e r IFJ #ho
/itendra ts@L Jun N 16:76 </itendra9c= go$indc ts@1
Jun N 16:N1 </itendra9c= E /itendraH n t s e r $ e r
IFJ #rite go$indc
>ello
are !ou %us! or can !ou gi$e "e N "inutes right no#
E /itendraH n t s e r $ e r IFJ
#ote: 4hen a user send a message then on the receier side it.s loo(s li(e5
E go$ind c H n t s e r $ e r IFJ E /itendraH n t s e r $ e r IFJ
4essage fro" /itendraH n t s e r $ e r on ts@L at
16:N) ... >ello
are !ou %us! or can !ou gi$e "e N "inutes right no#
E1-
J)rite user1 user6 usern :9 2end "essages to "ultile users
Jmesg y7n :9 ! a +ccet "essages fro" other users
n a CanQt recei$e an! "essage fro" other users
E /itendraH n t s e r $ e r IFJ #rite go$indc
#rite: go$indc has "essages disa%led
E/itendraHntser$er IFJ
Jortune :9 (isla! Jocks rando"l!.
Jcp C2ource -ileD C'arget -ileD :9 Co! a file
Co! a (irector! along #ith all the su%directories and files.
Jc Br C2ource (irNa"eD C'arget (irNa"eD
Jc Brf C2ource (irNa"eD C'arget (irNa"eD
'he & 2#itch is use to forcefull! co!, it re"o$es existing files on destination ath. ;e also use &
8
instead of &r otion.
Jc Bi "!file !ourfile : 3f target file is alread! exist then asks for o$er#riting.
#ote:9 'he 3p <reser$e "ode= re"ains files o#nershi, grou, er"issions, ti"esta"s as it is.
J ls &l 1#ner 0rou
9r#9r99r99 1 root root O Jul ) LO:6) a%c
dr#x999999 7 root root 1L6K Jul ) LO:L1 (eskto
Links@Pointers
'he -irst %!te 2ho# Proert! d a director!
'he next 'hree B!tes r#9 2ho#s User
Rights 'he next 'hree B!tes rc2ho#s
0rou Right +nd Last 'hree B!tes rcsho#s
others
r 9 9 r 9 9 r 9 9 a K
1LL 1LL 1LL
9# 9 9 #9 9#9 a 6
L1L L1L L1L
* * K K a r a read
11L 11L 1LL 6 a # a #rite
r#9 r#9 r9 9 1 a x a execute
user grou other
N u " e r ic P e r "i ss io n s :
C>41( can also to attri%uted %! using Nu"eric Per"issions:
KLL read %! o#ner
LKL read %! grou
LLK read %! an!%od! <other=
6LL #rite %! o#ner
L6L #rite %! grou
LL6 #rite %! an!%od!
1LL execute %! o#ner
L1L execute %! grou
LL1 execute %! an!%od!
Jchmod MNN a1.txt
;hich #ould %e the follo#ing KLLWLKLWLLKW6LLWL6LW1LLWL1LWLL1 a MMN
actor : Calculate and disla! the ri"e factors of nu"%er n. 3f n is not secified, nu"%ers are read
fro" stdin, searated %! co""as, saces, or ta%s. 'his "a! take a $er! long ti"e for nu"%ers that
are the roduct of t#o ri"es.
Usages: Jfactor EoptionsF n
E roo t H r o x! IFU factor 1L 6L 7L
1L: 6 N
6L: 6 6 N
7L: 6 7 N
E roo t H r o x! IFU factor 16
16: 6 6 7
E roo t H r o x! IFU
pg : Used to disla! data one age <screenful= at a ti"e. 'he co""and can take a nu"%er
of filena"es as argu"ents.
g EotionF Efilena"eF Efilena"e6F
G.. 1tions:
9nu"%er +n integer secif!ing the si.e <in lines= of the #indo# that g is to use instead
of the default. <1n a ter"inal containing 6K lines, the default #indo# si.e is
67=.
9 string g uses string as the ro"t. 3f the ro"t string contains a \d, the first
occurrence of \d in the ro"t #ill %e relaced %! the current age nu"%er #hen
the ro"t
is issued. 'he default ro"t string is XX:__.
9c >o"e the cursor and clear the screen %efore disla!ing each age. 'his otion is
ignored if clear?screen is not defined for this ter"inal t!e in the ter"info<K=
data %ase.
9e g does not ause at the end of each file.
9f Nor"all!, g slits lines longer than the screen #idth, %ut so"e seVuences of
characters in the text %eing disla!ed <for instance, escae seVuences for
underlining= generate undesira%le results. 'he 9f otion inhi%its g fro"
slitting lines.
9n Nor"all!, co""ands "ust %e ter"inated %! a Cne# lineD character. 'his
otion causes an auto"atic end of co""and as soon as a co""and letter is
entered
9r Restricted "ode. 'he shell escae is disallo#ed. g rints an error "essage
%ut does not exit.
9s g rints all "essages and ro"ts in the standard outut "ode <usuall!
in$erse $ideo=.
Wlinenu"%er 2tart u at line nu"%er.
P@attern@ 2tart u at the first line containing the regular exression attern.
filena"e + ath na"e of a text file to %e disla!ed. 3f no filena"e is gi$en, or if it is 9,
the standard inut is read.
Jile Cfilena"eD :9 (isla! file status <'here are %asicall! three t!es of files
ordinar!, director! and de$ice file=.
Jcmp file1 file6 : Co"are t#o file are identical or not.
9l : 0i$e a detailed list of the %!te no. and the differing %!tes in octal for each character
that differ in %oth files.
Jcmp 9l a1.txt a6.txt
Jcomm file1 file6 : (isla! all the data #hich are co""on or unco""on.
Jdi file1 file6 : (isla! the file differences.
Jlpr filena"e : Print a file on rinter
Jlpr 9t SEngineering College BikanerS filena"e : Print 'itle on -irst Page
9kCnoD : 2ecif! no. of coies to %e rint
9"C4ailidD : 4ail "essage to secified "ail id
Jlpr Bk7 B" /itendra H e c % . ac . in a1.txt : Print 7 coies and also "ail docu"ent.
Jcancel 9Crinter na"eD : 'o cancel the rinting.
Jvi test.c : Create a C Progra"
Z
rintf<RYn >ello ;orldYnS=8
[
Jcc test.c Bo test.out :9 for co"iling a C Progra"
+'7test'out :9 'o execute the rogra"
#ote : To enter text in vi editor just press i.
vi 9ext Editor
$i is the standard Linux text editor that can %e used to create and "odif! text files. :i usages .exrc file to
to change the default %eha$ior. 'his file <.exrc= contains "an! ex 4ode co""ands #hich are a$aila%le in
e$er! session. :i reads the .exrc file #hich is a$aila%le into the ho"e director!, if this does not exist then
create ne# one or co! fro" different location into J>14E@.exrc. Linux also ro$ides i"ro$ed $ersion
of $i na"ed as $i". :i" usages .$i"rc file instead of .exrc file #hich is also a$aila%le into
J>14E@.$i"rc location.
'he $i editor has three "odes, co""and "ode, insert@text "ode and Ex 4ode@.
1. Command mode: 'his is the default "ode. ;hen #e oen an existing file or create a ne# one then
$i auto"aticall! goes into this "ode.
6. Insert79ext 5ode: 'ext is inserted into the docu"ent. 'his "ode is in$oked %! ressing the i
<inserts %efore cursor osition=, I <3nserts at the %eginning of the line=, a <aend after cursor
osition=, A <aends at the end of the line=, o <oen ne# line after current line= or " <1en a ne#
line a%o$e current line= co""ands. 'he ESC ke! ends insert "ode and returns !ou to co""and
"ode
7. Ex 5ode or Escape Colon 5ode: Ex 4ode oens a ro"t on the last line. 'o enter into Ex
4ode fro" co""and "ode %! ressing the : <colon sign= #hich uts the co""and line entr! at
the foot of the screen.
Starting vi: +t shell ro"t t!e vi :FILE#A5E; and then ress EEN'ERF ke! to starts the $i editor.
5 3f the -3LEN+4E does not exist, a %lank screen #ith /ust a cursor at the to follo#ed %! tildes
<I= in the first colu"n.
5 3f the -3LEN+4E alread! exists then oen the file contents on screen.
5 'he status line at the %otto" of the screen sho#s error "essages and also ro$ides feed%ack
infor"ation include filena"e.
Exiting rom vi: 'o exit fro" $i !ou "ust %e co""and "ode, if not then ress EE2CF ke! and then go into
Ex 4ode %! ressing : <colon= ke!.
-ollo#ing co""ands are used into Ex94ode
:#V 2a$e file onto disk and Vuit fro" $i.
:x 2a$e file and Vuit fro" $i.
:V Exit fro" $i if file has not %een changed.
:Vd euit fro" file #ithout sa$ing the changes.
:# ;rite to the file and continue editing
:# filena"e 2a$e file contents into the secified filena"e. <3t is sa"e as :/<+) filena"e=
: .# filena"e 2a$e current line to the secified filena"e.
: .,J# filena"e 2a$e text fro" current line to end of file into secified filena"e
:1L# filena"e 2a$e 1L
th
line into secified filena"e.
:N,1N# filena"e 2a$e lines fro" N
th
to 1N
th
into secified filena"e
#ote: If specified filename already e6ists with w command the i displays warning message to use 7w*
filename8 to oerwrite e6isting file.
ff ;rite to the file in Vuit fro" $i
Cursor movement: 'he follo#ing ke!s are used in co""and "ode to "o$e current cursor osition.
h k / l
=eystro(es Action
h 4o$e cursor one character left k
4o$e cursor one line u
1Lk 4o$e cursor ten lines u
/ 4o$e cursor one line do#n
l 4o$e cursor one character right #
4o$e one #ord right
N# 4o$e cursor ahead N #ords
% 4o$e cursor %ack a #ord at a ti"e
B 4o$e cursor %ack a #ord at ti"e
N% 4o$e cursor %ack N #ords
e 4o$e cursor to end of #ord
Ne 4o$e cursor ahead to the end of the Nth #ord
L<.ero= 4o$e cursor to %eginning of line
J 4o$e cursor to end of line
\ 4o$e cursor to the "atching %racket. Place cursor on Z[EF<= and t!e ^\^.
W@9 4o$e cursor do#n@u in first colu"n
> 4o$e to the first line on the screen
4 4o$e to the "iddle line on the screen
L 4o$e to the last line on the screen.
:fx 4o$es to the cursor to the secified character x in the for#ard direction.
:-x 4o$es to the cursor to the secified character x in the %ack#ard direction.
8tx 4o$e cursor /ust %efore the secified character x in the for#ard direction.
:'x 4o$es the cursor /ust after the secified character x in the %ack#ard direction. 0
4o$e cursor to the %eginning of the last line in the file
U0 4o$e cursor to the %eginning of the Uth line in the file
CtrlWd 2croll do#n one half of a age
CtrlWu 2croll u one half of a age. CtrlWf
2croll for#ard one age CtrlW%
2croll %ack#ard one age
_. 4o$e cursor to re$iousl! "odified line.
Ta 4o$e cursor to line "ark ^a^ generated %! "arking #ith ke!stroke ^"a^
T+ 4o$e cursor to line "ark ^a^ <glo%al %et#een %uffers= generated %! "arking #ith
ke!stroke ^"+^
FQ 4o$e cursor to next lo#er case "ark.
ET 4o$e cursor to re$ious lo#er case "ark.
5oving cursor by sentences: 3n $i editor a sentence ends #ith d or .<eriod= or g. 'hese characters aear
in the "iddle of a sentence follo#ed %! %lanks.
< 4o$e cursor to the %eginning of the current sentence.
= 4o$e cursor to the %eginning of the next sentence.
5oving cursor by paragraphs: Positioning the cursor %! aragrahs then first "ake sure each
aragrah %egins after a %lank line. 'he %lank line indicates to starts a ne# aragrah.
Z 4o$e cursor to the %eginning of the aragrah.
[ 4o$e cursor to the %eginning to the next aragrah.
!eleting 9ext: 'o delete text fro" $i editor then $i co""and line "ode ro$ides the
follo#ing co""ands to delete text to #ord seed u.
x (elete character under cursor osition and the text on the right hand side shifted to
left to fill u sace. 3f cursor ositioned at the end of line then delete character fro"
left.
Nx Reeat factor, it delete fi$e character fro" right hand side and text shifted to left.
A (elete character %efore cursor osition.
dd (elete the entire line #here cursor is ositioned.
1Ldd (eletes current line and %elo# nine lines.
Udd (elete U nu"%er of lines fro" cursor osition.
CtrlW# (elete entire #ord fro" cursor osition to
left. ( or dJ (elete fro" cursor osition to end of line.
d# (elete a #ord fro" cursor osition.
Kd# (elete K ;ords
8epeating Character: 'o reeat a character "ultile ti"es then in the insert "ode t!e a
character i.e. 7> and then ress ESC ke! and then enter ?0a> <reeat *L ti"es ` and a a aend
into file= and ress ESC ke! then !ou #ill *L `Qs disla!s.
@````````````````````````````````````````````````````````````
#ote: 9 super/ te6t completion feature is aaila/le in im i.e. press c then press ^p to display all
the words aaila/le starting from c with header file. To iew a list of /ac(wards then press ^n.
Escape to Linux Shell 4sh and *@A : 'here are t#o #a!s to te"oraril! exit fro" $i editor.
aA 3n Ex 4ode t!e :sh:E#9E8; then i""ediatel! return to shell ro"t. 'o again return into
$i editor ress C98LBd or t!e exit.
bA Press C98LB@ to susend /o% $i editor and return to shell ro"t. 'here after use g
co""and to return to foreground into $i editor.
Coining 9ext 4CA : to re"o$e ne# line character %et#een t#o or "ore lines to ull u the lines
%elo# it. i.e. DC : /oin fi$e lines into single line.
" p e r a t o r s: 9 'he strongest feature of is editor is that the co"%ination of co""and "ode. 'he
oerator are as :9
d9 (elete !9 !ank <co!=
c9 Change d9 filter
Note5 : 9n operator a/oe cannot perform any function /ut wor(s with a command or used itself
twice. 4hen we use operators twice then only wor( on current line. e.g. dd deletes the entire line.
!eleting text 4xA:9 'o delete the certain ortion of text fro" file then use oerator #ith a co""and.
e.g. dJ
d#
(elete fro" cursor osition to end of line
(eletes the entire #ord
1Ld#
d0
(eletes 1L #ords fro" current cursor osition to for#ard
direction
(eletes fro" cursor osition to end of file
1Ldd (eletes ten lines fro" current osition to for#ard of direction.
Easte deleted text 4E and EA:9 'o lace the deleted text at different location then P and P co""and
are used. 'he P astes the deleted text %elo# or after the cursor osition and P astes the deleted text
a%o$e or %efore the cursor osition.
Copying7Fan(ing text 4yA:9 'he ! oerator !anks@coies text and it #orks in the sa"e #a! as oerator
d #orks, and the P or P co""and are used to astes coied text at current cursor osition. E.g.
1L!! !ank@co! 1L lines fro" cursor osition to for#ard direction and then "o$e cursor at aroriate
lace and then ress O or P co""and to aste the copied text.
Changing text 4cA:9 'o change the text then <c= oerators is used. 3t #orks sa"e as <d= oerator %ut the
onl! difference is that #hen use <c= oerator then #e auto"aticall! "o$es fro" co""and "ode into inut
"ode. e.g. cc change<or delete= entire line and also goes into inut "ode, to again go into co""and
"ode, ress EEscF ke!.
cJ or C: 9 change text fro" cursor osition to end of
line.
1Lcc:9 change ten lines in for#ard direction c@Engineering college Bikaner@EEnterF change all text
starting
fro" current cursor osition to first "atch of secified attern<Engineering college
Bikaner=.
Filtering text 42A:9 'o filtering text #ithin $i editor then <d= filter oerator is used, it reVuires three things
<a= 4o$e cursor to %eginning of the osition <%= 4o$ing cursor to ending of the location using <0=
co""and
<c= + Linux co""and #hich act on the %eginning , ending of the
location.
Exa"le:
d 10: 9 4o$e cursor to %eginning of file.
d 0 2ort: 2orts the entire file.
Note5 : 4e can also use (*) filter operator in e6
mode.
: D< 1D2 Sorts :Enter; 2orts lines fro" N
th
to 6N
th
so"e co"%ination of co""and and oerator.
;orking #ith 4ultile files :9 'he ex 5ode ro$ides the facilities to handle "ultile files. 'his feature
is not ro$ided %! co""and "ode. 'he :e co""and is use to #orks #ith "ultile files.
Exa"le:
:e matrix'c :9 'e"oraril! lea$es the current file and oens "atrix.c.
:e, or :C98LBn; :9 2#itch %et#een files.
"pening multiple iles :9 $i ro$ides the facilit! to oen "ultile files at the sa"e ti"e and it loads first
file contents into the %uffer.
Exa"le:
Jvi irst'c second'c third'c : 1en 'hree files and load first.c file contents into %uffer.
:n : 2#itch into next file #ithout lea$ing the editor.
:re) : Re#inding the first file. +t an! stage #e can "o$e %ack to first file.
Note 5: To switch /etween files n editor displays warning message to sae data /efore leaning
it.
:e2 : 3gnore all unsa$ed data. 3t is sa"e as :- co""and #e can also use :n2 or :re)2
to discard changes into current file and s#itch into another file.
Inserting ile G command output into existing ile:9 'o inserts the contents of a file at certain
location into currentl! oened file then in ex"ode <:r= co""and is used.
:r my'txt : 3nserts "!.txt file at cursor osition.
:r 2ls 3l : 3nserts ls 9l co""and outut into file.
Note5: To switch /etween files then unsaed te6t is deleted so that use 5 set auto write or 5set aw
command to sae automatically while switching /etween files.
Splitting )indo):9 $i editor ro$ides the facilit! to slit a #indo# into "ultile #indo#s. +
#indo# can %e e"t! #indo#s or slit a sa"e file into searate #indo#s.
:sEEnterF 'o slit existing #indo# into t#o #indo#s.
:ne#EEnterF 1en a ne# %lank #indo#.
Note5 : The CTRL+W is use to switch /etween windows and CTRL-W+ is use to increase the si;e
of current window and CTRL-W- is use to decrease the si;e of current window.
:on : 4ake current #indo# in full screen , re"o$e all other #indo#.
Note5: ! is use to <uit from current window and close it and !a <uit from all windows without
saing.
2 o " e e x 4 o de c o "" a n d s e x a " le s to h a n d ling file s .
:xa : Exit fro" all #indo#s after sa$ing
:r "!:txt : 3nserts "!.txt contents %elo# current line.
:r dhead 97 "!.txt : 3nserts first 7 lines fro" "!.txt %elo# current line.
:e "!.txt : +end %uffered text into "!.txt
:ed "!.txt : ;ithout sa$e oen file "!.txt
:ed : 3gnore all unsa$ed data and loads last sa$ed text.
:eU : Returns to editing "ost recentl! edited file.
:n : Edits next file <if "ore than one files are oened
:re# : Re#ind file list to starts editing fro" first file.
#amed Huers: B! default $i editor stores the deleted text into an unna"ed %uffer so that #e can
use onl! one %uffer at a ti"e and #hen #e "o$ing text fro" one file into another <using :e
filena"e=, 'he contents of the default %uffer auto"aticall! lost. 'o o$erco"e this ro%le" $i
ro$ides 6* secial na"ed %uffers na"ed fro" a to @. 'o use na"ed %uffers then I <dou%le Vuote=
and %uffer na"e is used.
Exa"le:
RaN!! : Coies N lines into %uffer a.
R%6L!! :Coies 6L lines into %uffer %.
Ra : Paste text fro" %uffer a at cursor osition
Note5 If a named /uffer already contains te6t into the /uffer then i oerwrite the e6isting contents.
i usages uppercase letter to append te6t into e6isting /uffer. e.g. "#$%&& instead of "b$%&&.
Exa"le:
Rc6L!! : Co! 6L lines into na"ed %uffer c.
:e ne#file.c : 2#itch into ne#file.c
0 : 4o$e cursor at %otto" of file
Rc : Paste text 6L lines fro" na"ed %uffer c.
$ndo multiple deletions using numbered buers: 'he undo co""and <u= onl! undoing the last
editing section. :i also ro$ides nine nu"%ered %uffers <1 to )= to restore last nine co"lete
deletions. 'he "ost deleted text stored into %uffer nu"%er 1 and the next9"ost deletion into %uffer
nu"%er 6 and so on. 2o these %uffers are accessed %! using R <dou%le Vuote= and %uffer nu"%er.
Exa"le:
R1 : Restore recentl! deleted text.
R6 : Restore re$iousl! deleted text.
Note5 The num/ered /uffer only wor(s for entire line0 does not wor( for partial line or words. i.e.
'd(0 it deletes fie words and can.t possi/le to restore fie words using num/ered /uffers.
(ot <.= co""and to restore re$ious deleted line: 0enerall! the dot <.= co""and is to use to reeat
the re$iousl! entered co""and %ut it %eha$es differentl! #hen used #ith nu"%ered %uffers. E$er!
ti"e #hen it is ressed, it stes one %! one.
Exa"le:
R1u.u.u. : Restores %uffer contents fro" 1
st
%uffer to K
th
%uffer.
Entering Control Character Ectrl9$F: ;hen #e #rite shell scrit and send so"e escae seVuence
character to ter"inal or rinter then #e reVuires control characters. :i usages ctrl9$ to recede
control character. -or exa"le to enter Ectrl9"F, then first ress Ectrl9$F and then ress Ectrl9"F then
#e #ill see on screen like:
b4 : >ere b4 onl! a single character.
#ote: 3f #e ut * <caret= 4 then %oth are different9different characters. 2o that to co"%ine
%oth characters into a single character then #e reVuire control character.
Search a Character: $i ro$ides the facilit! to search a text #ithin current line using the and t
ke!s. 'he ke! uts the cursor onto fist "atch of character #ithin the current line in for#ard
direction and t ke! also #orks sa"e as %ut t uts the cursor %efore a character of first "atch of the
character into current line.
'he 9 and F ke! #orks in oosite direction as and t ke! #orks.
'o reeat the sa"e character then J and < ke!s are used. 'he J reeats the search attern in sa"e
direction as and t ke! #orks and < ke! #orks in oosite direction along #hich re$ious search
#as "ade #ith and t ke!s.
Labeling 9ext Eositions: $i ro$ides the facilit! to "ark u to 6* ositions to "o$ing cursor
osition faster <la%eled as a to .=. 'o "ark the text then m co""and is used and to locate the "arked
text then
K <single Vuote= co""and is used.
Exa"le:
-irst "o$e cursor at aroriate lace i.e. 1L0, 4o$e cursor at 1L
th
line.
"a 4ark #ith la%el na"e a
NL0 4o$e cursor at NL
th
line of the
file. "% 4ark location #ith la%el
na"e %.
Ta 4o$e cursor at "arked location
a
T% 4o$e cursor at "arked location
%
Note: $i also ro$ides dou%led TQ <single Vuote= to s#itch %et#een to "arked
locations.
TQ 4o$e cursor at "arked la%el na"e
a.
TQ 4o$e cursor at "arked la%el na"e
%.
Customi@ing vi: 'he .exrc file a$aila%le in users ho"e director! is use to change the %eha$ior of
$i editor. :i reads the startu file na"ed as .exrc and $i" reads .$i"rc file at startu. 'he set, "a
and a%%r co""ands are used to change $i or $i" %eha$e, these co""ands can %e used in $i ex
"ode.
:help topic 9 3f the toic na"e is unkno#n, then '+B co"letion #ill c!cle through the
$arious otions gi$en the first fe# letters. Ctrl3d #ill rint the co"lete list of ossi%ilities.
:set all 9 (isla! all settings of $i
session.
:set ic 9 Change default to ignore case for text searches. (efault is changed fro"
noignorecase to ignorecase. <ic is a short for" other#ise t!e set ignorecase=
-ollo#ing Co""on otions used #ith set: 'he $aria%les are in the for" of
$aria%lea$alue.
Full LsetL Command Short orm !escription
autoindent@noautoindent ai@noai ZCR[ returns to starts next line at re$ious
indented le$el
auto#rite@noauto#rite a#@noa# 2a$e file auto"aticall! #hen s#itch %et#een file
using :n or :e
error%ells@noerror%ells e%@noe% 2ilence error %ee sound
flash@noflash fl@nofl 2creen flashes uon error <#hen noerror%ells is
set=
ta%stoaN ts 'a% ke! disla!s N saces
nu"%er@nonu"%er nu@nonu (isla! line nu"%ers on screen
ignorecase@noignorecase ic@noic 3gnore case #hen search a attern
sho#"atch@nosho#"atch Cursor sho#s "atching ^=^ and ^[^
sho#"ode@nosho#"ode Editor "ode is disla!ed at %otto" of screen
taglength tl (efaultaL. 2et significant characters
lineli"ita6LKON*L 4axi"u" file si.e to edit
#rascan@no#rascan #s@no#s Breaks line if too long
#ra"arginaL@no#ra"argin #"@no#" (efine right "argin for line #raing.
list@nolist (isla! all 'a%s@Ends of lines.
%gadark
%galight
:34: choose color sche"e for ^dark^ or ^light^
console %ackground.
5apping (eys o (eyboard 4mapA : 'he "a co""and is use to assign a ke! #ith a seVuence
of co""ands. 3t is useful to con$ert a seVuence of ke!strokes into a "acro.
'o "a the ke! t #ith :):Enter; #hich is use to sa$e %uffered text onto disk.
:"a t :#b4 b4 reresents the EEN'ERF ke!
:"a UK :dcc \b4 4a function ke! -K to co"ile the current c rogra". <\ relaced
#ith current file na"e.
:"a UN :d.@a.outb4 4a function ke! -N to execute the a.out file.
:"a U* :d\b4 4a function ke! -* to executes the current shell scrit or erl
rogra".
Note- To map a se<uence of commands with function (eys then ) (sign) and function (ey num/er
is used to map the appropriate function (ey. =i automatically understands the current file as *
(sign).
#ote:3 'he :map co""ands disla!s all "aed en$iron"ent and :unmap cancels a co""and
"ode "a and :unmap2 Cancels all an inut "ode "a.
Abbreviating 9ext Input 4abbrA:9 'he a%%re$iate co""and is use to exand short string into
long #ords.
:a% ec% Engineering College Bikaner
;hen enter the #ord ec% and then ress sace %ar it disla!s the long string as secified a%o$e.
Note: Store all set0 map0 ab commands in >#O?%".e6rc (or .imrc for im) file so that they
are always aaila/le on i or im startup.
;3L(C+R(2 :9 'here are t#o #ildcards, na"el! g and `. Unix shell ro$ides so"e "ore
#ildcards. Ea%cF 4atch one character #hich should %e either a,% or c
Eda%cF 4atch one character #hich is not a,% or c.
E9tF 4atch one character #hich falls #ithin the range 9t
Ed9tF 4atch one character #hich does not fall #ithin the range 9t.
eg. Jls 3id uni?:/MN; or J ls my:203O;
eg. Jmv uni:x3@;:9)elve; 7north
9o Change File Writes:
Jchmod *LL filena"e
K a read, 6 a ;rite a KW6 a * for user and re"aining t#o %!tes LL for grou and others
<the 0rous and others ha$e no #rites=
Jchmod LLL a1.txt :9 'here are no #rites for user,grou and others
Jcat a1.txt :9 (isla!s 4essage Per"ission (enied %ecause user canQt ha$e #rites to excess
this file.
5ultiple Shell in Linux
1. %ash Bourne shell : 'his is the (efault shell
6. %sh %ash shell
7. ksh korn shell
K. csh c shell
Note5 @S# shell generally use for @ programming and in uni6 the default shell is BS#
Ctrl B Alt B F/ 0o into CU3 <Character User 3nterface= or ress 'er"inal %utton fro"
'ask BarCtrl B Alt B FP 0o into 0U3 <0rahical User 3nterface=
Jsh : 2tarts a ne# shell <Press Ctrl ( or t!e exit to exit fro" ne# shell=
Jvi de"o.c : Create a c rogra"
Z
int i8
for<8 8=8 @@infinite loo
[
Jcc de"o.c
Jdemo'outG : 2ends outut in %ackground. <'o send outut in Background /ust lace G
sing at end.=
Jps : (isla! rocess status to see the rocesses #hich are acti$ated in %ackground.
3t disla!s P3( <Process 3dentification No.=, ''], 'i"e, C4(
Jps au : (isla! s!ste" acti$it!. Linux is a "ulti9user oerating s!ste", Linux is also a "ultitasking
s!ste". 4ultitasking "eans that "an! rogra"s can %e running at the sa"e ti"e. +n
instance of a running rogra" is referred to as a rocess. Es au co""and disla!s all
running rocesses, "onitoring s!ste" usage.
J(ill 9) O7LO : 'o ter"inate the %ackground rocess. O7LO is P3( No.
Jps Ba : (isla! all rocess e$en hidden also
Create t)o shells
Jsh
Jsh
Jps Ba
.o) to run multiple commands at the same time:
Jdate8 )ho8 ls Bl : Just t!e co""ands searated %! se"icolon.
J)c filena"e : Count the no. of Lines, #ords characters and saces
J)c Bl filena"e : Counts the no. of lines
J)c Bc filena"e : Counts the no. of characters
J)c B# filena"e : Counts the no. of #ords
Jxterm : or
Jstartx : 0o into 0U3 <0rahical User 3nterface= 4ode
Jshutdo)n Br no# : 'urn off the co"uter
Jinit L : or
J Ctrl +lt (el : 'o Re%oot
Jnetcon : 'o Configure Net#orking
Jiconig ethL : 'o check the 3 +ddress
Jsc( @de$@hdaN : Check , rectif! the disk integrit!
Je1sc( @de$@hdaN : Check , rectif! the disk integrit!
Note: The fsc+ and e$fsc+ /oth commands are same /ut e$fsc+ is more powerful.
Jinit L@1@* : L a >alt the s!ste"
1 a Boot s!ste" into single user "ode
* a Re%oot the 2!ste"
Jpass)d : 'o change the Pass#ord
Jlinuxcon : 'o configure e$er!thing in Linux <i.e net#orking, users, file s!ste" etc.=
Jmount @de$@flo! : 4ounts the -lo! disk, so that #e can access flo! dri$e
Jmount Bt $fat @de$@hda1 @"nt@#in?c : 'o access #indo#s artition in Linux.
Jstab : (isla! 4ount oints
Note 5 In fstab file specify all the deices which are mounted in linu6 at startup.
Jbanner CtextD : (isla! a oster
.o) to Spell Chec( in Linux:
Jispell Cfilena"eD : Checks the selling of secified file and disla! suggestion of
"isselled #ords.
Jgrep RstringS filena"e : -ind the secified string fro" file
Jgrep Rco"uterS a1.txt : -ind computer #ord fro" a1.txt file
Jhead 96 e".txt : (isla! first t#o lines fro" to to %otto" <96 is nu"%er of lines to %e
disla!ed=
Jtail 96 e".txt : (isla! last t#o lines fro" %otto" to to.
Jcut 9c191L e".txt : (isla! first 1L characters starts fro" colu"n no. 1 to 1L.
9c1 a 2tarts fro" colu"n nu"%er
1L a End of colu"n nu"%er
Jcut 9f6 e".txt : (isla! onl! 6
nd
colu"n
Jcut 9f1 e".txt : (isla! onl! 1
st
colu"n
Jcut 9f1,7 Bd RPS e".txt : (isla! first and third fields <9d a deli"inator=
Jg@ip a%c.txt : Co"ress file <3t is sa"e as 429;indo#s )in@ip co""and=
Jgun@ip a%c.txt.g. : Unco"ress file <un.i file=
.o) to go to rom one user prompt to another user prompt. <#e can change onl! six user ro"ts=
AL9 B F/ : Change first user
AL9 B F1 : Change second user
.
.
AL9 B F? : Change sixth user
Jecho Linux 1erating 2!ste" : 3t Re"o$e 2aces
Linux 1erating 2!ste"
Jecho RLinux 1erating 2!ste"S : CanQt Re"o$e 2aces
Linux 1erating 2!ste"
Jod filena"e : (isla! +2C33 1ctal $alue
Jod 3b filena"e : (isla! octal $alue of each character
Jod 3bc filena"e : (isla! octal $alue of each character along #ith corresonding character.
Jsplit filena"e : Breaku a long file into s"all files
Jsplit 3?0 a1.txt : Breaku file and each file contains *L lines
Jsplit a1.txt s"all : Breaku file and create files called s"allaa, s"alla%, s"allac etc.
grep :9 grep is use to search a attern fro" file and then disla! on standard outut
de$ice. Usages: Jgrep options pattern ilename4sA
Jgre R"arketingS sales.txt :9 3t searches the attern "arketing and then disla! all those lines
the! contains the attern.
#ote:9 'he attern can also secified #ithout Vuotes. 'he Vuotes onl! reVuired #hen attern
contains "ultile #ords.
Jgre TJitendra 2inghQ
e".txt gre otions:9
9i : 3gnore case for attern "atching.
9$ : 3n$erse, 2elect all those lines the! do not contains attern.
9n : (isla! Line nu"%ers the! contains attern.
9c : Counting total nu"%er of lines the! contains attern.
9l : (isla!ing file na"es the! contains the "atched attern.
9e : 4atches "ultile attern.
9f : 'aking attern fro" a file. 'he attern "a! %e secified one er line.
Jgre Bc T"anagerQ e".txt
N
Jgre Bc "anager e"`.txt
e"1.txt:K
e"7.txt:*
e"M.txt:7
Jgre Bl "anager `.txt
e".txt
e"1.txt
e"N.txt
Jgre Be R"anagerS Be Rsales"anS BeS directorS e".txt
Jgre Bf atternfilena"e e".txt
Jgre Bn T"anagerQ e".txt
Jgre B$ T"anagerQ e".txt
Jgre REa+FgEarFEarF#alS e".txt :9 Regular exression is used to secif! a grou of
character enclosed #ithin a air of rectangular %rackets:;.
Asteris( > :9 'he #ild card > is used to searches a attern #ith gre. i.e. s> searches s ss sss ssss
GG. 'he ` "arks the re$ious character occurred .ero or "ore ti"es.
Jgre RE+aFg`EarFEarF#alS e".txt
9he ' !ot :9 'he ' "atches a single character like shell g. i.e. DQ' it "atches fi$e attern
%eginning #ith a N #hich is eVuilent to shellQs Ngggg.
'he . along #ith ` <.`= are also used continuousl!. 'he! signifies an! nu"%er of characters or none.
Jgre Rra/.`choudhar!S e".txt 3t searches ra/ choudhar! or ra/ ku"archoudhar! etc.
Speciying pattern location 4* and +A :9 'he * <care= "atch at the %eginning of a line and +
"atching at the end of a line.
Jgre RbNS e".txt
NLL1PJitendra 2inghPCo"uter 2cienceP4.'ech.POLLL
NLL6PRa/ &u"ar Choudhar!P3nfor"ation 'echnolog!PB.'ech.POLLL
NLL7PNarendra &u"arPCo"uter 2cienceP4.2c.P*LLL
NL1LP+/a! Choudhar!P3nfor"ation 'echnolog!PB.E.POLLL
'o select all those records #here salar! lies %et#een OLLL to O)))).
Jgre ROGJS e".txt
NLL1PJitendra 2inghPCo"uter 2cienceP4.'ech.POLLL
NLL6PRa/ &u"ar Choudhar!P3nfor"ation 'echnolog!PB.'ech.POLLL
NL1LP+/a! Choudhar!P3nfor"ation 'echnolog!PB.E.POLLL
#ote:9 grep is also a filter so that it can search its standard inut for the attern and store the outut
in a file.
J#ho P gre /itendra D users.txt 3t searches the user /itendra is logged in or not, if logged in then
stores the userna"e into file users.txt.
Sed:9 S98EA5 E!I9"8:9 3t is a "ultiurose tool #hich #orks of se$eral filters. 2ed
usages instructions #hich #orks on text. 'he usages of sed is as follo#s:9
sed options Kaddress actionR iles4sA
#ote:9 'he address and action are enclosed #ithin single Vuotes. 'he address can %e secified in
t#o #a!s:9
1. secif! one or t#o lines like 7,K
6. 2ecif! a 7 <for#ard slash= attern= #hich occurs in a line <e.g. 7pattern:7=
'he first attern secifies that to select a line or a set of "ultile lines i.e. <6,*= to select a grou of
contiguous lines and the second for" uses one or t#o atterns. 'he action art can %e use to
disla! <rint= or can %e used as a function like insertion, deletion or su%stitution of text.
Usages of sed:9
J sed KD-R std'txt
#ote:9 ;ith sed #e can use p4printA co""and to disla! lines -4-uitA to rint lines on screen
and then Vuit fro" file. 3t is sa"e as >ead co""and i.e. head &n D'
Jsed Bn T*,11Q std.txt :9 Prints Lines fro" line no * to 11.
#ote:9 ;ith p co""and use &n s#itch other#ise p co""and rints the selected lines as #ell as all
the lines so that the selected lines rints t#ice. 'he + s!"%ol is used #ith sed to select the last line
fro" file.
Jsed Bn TJQ std.txt :9 Prints the last line fro" std.txt file.
Selecting multiple groups o line :9 'o select "ultile lines then secif! line nu"%ers searated %!
a sace #ithin a single Vuote.
Jsed Bn T7,* 11,1N JQ std.txt :9 3t rints fro" line no. 7 to *, 11 to 1N and the last line fro" file.
#egating the action 42A :9 sed has a negation oerator <2=, #hich can %e used #ith an! action.
Jsed Bn Q1L,JdQ std.txt :9 3t rints fro" line no. 1 to 1L. 3t is sa"e as sed Bn T1,1LQ std.txt.
5ultiple instructions )ith sed :9 'he &e otion used to secif! "ultile instructions and the 3
otion is used to get the instructions fro" file.
Jsed Bn Be T6,KQ Be T),11Q Be T1*,1)Q Be TJQ std.txt
Jcat D inst1.txt
6,K
),11
1*,1)
J
Jsed Bn Bf inst1.txt std.txt :9 3t takes instructions fro" inut file na"ed as inst1.txt and then
rints fro" file std.txt.
#ote :9 ;e can also secif! "ultile inut instruction files #ith & otion and #e can also co"%ine
the
&e and & otions.
Jsed Bn Bf inst1.txt Bf inst6.txt std.txt
Jsed Bd Be T@director@Q Bf inst1.txt Bf inst6.txt std.txt
Context Addressing :9 'he attern "ust %e %ounded %! a 7 on either side and #e can also secif! <
<co""a= searated air of context addressing to select the grou of lines.
Jsed Bn T@choudhar!@Q std.txt
Jsed Bn T@choudhar!@,@chaudhar!@Q std.txt
Jsed Bn TN,@choudhar!@Q std.txt :9 Co"%ine Line and context addresses.
8egular Expressions :9 sed also usages to use regular exressions.
Jsed Bn T@Ea+Fgg`EarFEarF#al@Q std.txt :9 3t rints all the agar#als.
Jsed Bn T@saEkxFs`ena@ @guta@Q std.txt :9 Prints either saxenas or guta.
#ote:9 sed also usages anchoring characters * and +, as art of of the regular exression.
Jsed Bn T@MLG.J@Q std.txt :9 3t rints all the eoles %orn in the !ear 1)ML.
Storing selected lines into a ile 4)A :9 'he # <#rite= co""and #rites the selected lines into
a searated file.
Jsed Bn T@director@# director.txtQ std.txt 3t sa$e the lines of directors in director.txt file.
Jsed Bn T@director@# director.txt @"anager@# "anager.txt @suer$isor@# suer$isor.txtQ std.txt :9
3t sa$es the selected lines into the searated secified files.
Jsed Bn T1,NL# fist N1,1LL# second 1L1,J# thirdQ std.txt :9 3t sa$es first NL lines in first and next
NL lines into second and rest of the lines into third file.
#ote:9 ;ith ) co""and the &n s#itch is used other#ise it stores selected lines as #ell as all
the lines.
9ext Editing :9 sed can insert text and change existing text in a file. ;e use i<3nsert=, a <+end=, c
<Change= and d <(elete=.
3nserting 'ext :9
Jsed T1iY
D Uinclude Cnetinet@in.hDY
D Uinclude Cs!s@socket.hD
D T ser$er.c D JJ
#ote:9 'he 1i first inserts a line nu"%er at 1. 'he Y 3ndicates sed to this is not a last line.
J "$ JJ "!.c 8 head 96 "!.c 3t first "o$es JJ file into "!.c and then disla!s first 6 lines
fro" "!.c
Uinclude
Cnetinet@in.hD
Uinclude Cs!s@socket.hD
3nserting a %lnak line #ithin each
line.
Jsed TY
T"!.c 3t inserts a %lank line #ithin each line in "!.c
file. (eleting Lines <d= :9
Jsed T@"anager@dQ std.txt :9 3t delete all those lines the! contains the #ord "anager fro"
file.
Finding G 8eplacing text :9
Jsed Ts@cat@dog@Q ets :9 'he ets file #ill %e sent to standard outut #ith the string RcatS
%eing relaced #ith string RdogS.
#ote:9 B! default sed "akes a "axi"u" one change er line so that to "ake "ultile changes er
line then use g <0lo%al= co""and.
Jsed Ts@cat@dog@gQ ets
Jsed Ts@ECcFcat@dog@gQ ets :9 3t searches #ith regular exress and then erfor" relace"ent.
3t searches %oth Cat and cat ke!#ords.
#ote:9 B! default sed #orks on strings not %! #ords, 'o #orks on #ords then use
anchors.
Jsed Ts@YCECcFatYD@dog@gQ ets
#ote:9 B! default sed #orks on all lines in the file. 3t is also ossi%le to #orks on selected
lines.
Jsed TN,6Ns@cat@dog@Q ets :9 3n this case the cat relaced #ith dog ke!#ord onl! fro" line nu"%er N
to
6N and rest of lines are unchanged.
Jsed Be Ts@cat@dog@gQ Be Ts@co#@%ull@gQ ets :9 3t searches "ultile #ord #ith "ultile
relace"ents.
8unning Erocess in bac(ground :9 3n the "ultitasking s!ste" can do "ore than one /o% at a ti"e.
2ince on /o% can %e running run in foreground and rest of the /o%s can %e running in %ackground.
'he
G oerator and nohup co""ands are used to done this
/o%s.
Jsort Bo std.txt e".txt , :9 'he shell i""ediatel! returns the P3( and then returns to shell ro"t
to accet an! other co""and.
8unning Sobs ater Log "ut 4nohupA :9 ;hen a user logged out, <in C shell and Bash 2hell= the
shell is killed. 'he nohup <no hangu= co""and is used to run the rocess the continuousl! e$en if
the user is logged out.
Jnohu .@ser$er.out , :9 'he shell i""ediatel! returns the P3( and disla!s a "essage
2ending outut to nohu.out.
#ote:9 3f #e run "ore than one co""and in a ieline, then use nohup co""and at the %eginning
of each co""and.
Jnohu .@ser$er.out , P nohu gre RLecturerS e".txt ,
Cob Execution )ith Lo) Eriority 4niceA :9 +ll the /o%s in Unix nor"all! executed #ith eVual
riorit!. ;hich is not desira%le %ecause high9riorit! /o%s "ust %e co"leted at the earliest. 'he
nice co""and used #ith , oerator to reduce the riorit! of /o%s.
Jnice .@ser$er.out ,
'he nice $alues are s!ste"9deendent and t!icall! range fro" / to /O. B! default nice $alues
usages "iddle le$el $alue, usuall! /0. + higher nice $alue has a lo#er riorit!. 'he nice $alues
secified #ith the &n s#itch.
Jnice Bn K .@ser$er.out ,
#ote:9 + nonri$ileged user can not increase the riorit! of a rocess, onl! sueruser can change. 'he
nice $alue is disla!ed #ith the ps &o nice co""and.
Controlling Cobs:9 + /o% is the na"e gi$en to a grou of rocesses. 3f a /o% is running and #e
exect to co"lete that /o% #ithin N "inutes and it goes on for half an hour. 3f #e kill the /o% no#
#e #ill lose lot of #ork. 3f #e using the C shell, Bash or &orn 2hell then #e can use /o% control
facilities to "aniulate /o%s.
5 2ends the current foreground /o% into %ackground <bg=
5 Bring the last %ackground /o% into foreground <g=
5 List all the acti$e /o%s <Sobs=
5 2usend a foreground /o% <CtrlB@=
5 &ill a /o% <(ill=
'he g and bg co""ands are also used #ith the /o% nu"%er, /o% na"e or a string as argu"ents,
refixed %! the T s!"%ol.
Jfg \1 Brings first /o% into foreground.
Jfg \sort Brings the shortest /o% into foreground.
J%g \6 2ends the second /o% into %ackground.
J%g \gstaff 2ends to %ackground /o% containing string staff
;e can ter"inate a /o% #ith the kill co""and using the sa"e "anner as a%o$e. i.e. (ill T/ kills
the first %ackground /o%.
Cob Scheduling 4at and batchA :9 Unix ro$ides the sohisticated facilit! to schedule a /o% to run
at the secified ti"e eriod of da!.
"ne 9ime Execution 4atA :9 at takes as an argu"ent ti"e on #hich the /o% is executed and
then disla!s the at6 ro"t.
Jat 1):6N
atD.@ser$er.out
ECtrlWdF 'o exit fro" the at ro"t then at sho#s the /o% nu"%er in the for" of nu"%er of
seconds that ha$e elased since the Eoch.
'he /o% goes in the Vueue and executed at M:6N" toda!.
#ote:9 at does not indicate the na"e of the /o% to %e executed so that the user "ust has to
re"e"%er the at /o%s. 'he standard outut or standard error of the /o% #ill %e "ailed to the user or
a user can alternati$el! redirect the outut of the co""and.
Jat 1):6N
atD.@ser$er.out D reort.txt
'he & otion is used to take co""ands fro" a file. 'he &m otion is used to send /o%
co"letion reort to the user.
'he at also offers "an! ke!#ords no#, noon, toda!, "idnight, to"orro# and it also accets the W
s!"%ol to act as an oerator.
Jat 1O 6K hour for"at assu"ed
Jat *"
Jat *:1N"
Jat noon +t 16:LL hours toda!
Jat no# W 1 !ear +t the current ti"e after one !ear
Jat N:1N" W 1 da! +t N:1N" to"orro#
Jat 1*:LN (ece"%er 6N, 6LL)
Jat 1La" to"orro#
#ote:9 'he "onth na"e and the da! of the #eek #hen used then the! "ust %e either full! selled
out a%%re$iated to first three letters.
#ote:9 'he /o%s list is disla!ed #ith the at &l co""and and re"o$ed #ith at &r co""and.
+#k :9 Na"ed after its de$eloers Aho, Wein%erger, and =ernighan
'he a#k utilit! is a pattern scanning and processing language. 3t searches one or "ore files to see
if the! contain lines that "atch secified patterns and then erfor" associated actions, such as
#riting the line to the standard outut or incre"enting a counter each ti"e it finds a "atch.
2o"e of the features of a#k are:
5 3ts a%ilit! to $ie# a text file as "ade u of records and fields in a textual data%ase.
5 3ts use of $aria%les to "aniulate the data%ase.
5 3ts use of arith"etic and string oerators.
5 3ts use of co""on rogra""ing constructs such as loos and conditionals.
5 3ts a%ilit! to generate for"atted reorts.
'he usages of a#k is as follo#s:9
Ja)( options KselectionUcriteria VactionWR iles4sA
'he selectionUcriteria and action art %oth included in a single Vuotes and these can %e secified
in one line or can also secified into "ultile lines. 3f selectionUcriteria is "issing, then action
art alies for all the lines of the file and if action art is "issing then the entire line is rinted.
#ote:9 Both selection?criteria and action art %oth are otional %ut not %oth at the sa"e
ti"e. 3n the action section Z rint [ is used to rints the entire line.
Ja#k T@"anager@Q e".txt : B! default it rints the entire line
those "atches the string.
Ja#k T@"anager@Z rint [Q e".txt : Prints the entire line those "atch the string.
Ja#k T@"anager@ Z rint JL [Q e".txt : JL reresents the entire line, so that all of
the a%o$e co""ands are sa"e.
8egular Expressions: ;e can use sed st!le regular exressions.
Ja#k T@saEkxFs`ena@Q e".txt
'he &F otion is used to secif! the -ield searator. B! default the field searator is a #hite
sace instead of a single sace or ta%.
Ja#k B-SPS Q@saEkxFs`ena@ Z rint [Q e".txt
Split a line into ields :9 a#k usages the secial ara"eter JL #hich reresents the entire line and
also identifies the fields J1,J6,J7 and so on. <J1 reresents first field, J6 "eans second field and so
on=.
Ja#k B-SPS T@co"uter@ Z rint J6,JK,J* [Q e".txt : 'he , <co""a= is used as a field deli"it.
'his "eans each field is searated to each others %! a sace.
#ote:9 3f #e o"it the , <co""a= then the fields glued together.
Select Line #umbers: 'he a#k has an in9%uilt $aria%le NR #hich reresents the line nu"%ers.
Ja#k B-SPS TNR aa N, NR aa1L Z rint NR, J7,JK,J* [Q e".txt : 3t rints fro" line nu"%er N to 1L
#hich is sa"e as sed co""and sed Bn T*,11Q e".txt
#ote:9 NR aa N is not assign"ent oerator %ut it is a condition #hich is tested.
-or"atted 1utut <rintf= :9 'he C function rintf used #ith a#k to rints the for"atted outut. 'he
\s for"at is used #ith string and \d is used #ith nu"eric data.
Ja#k B-SPS T@saEkxFs`ena@ Z rintf R\7d \96Ns \91Ls \dYnS,NR,J6,J7,J* [Q e".txt
#ote:9 B! default character $alues are right /ustified so that B <"inus= sign is used to rint
left /ustified. 'he Yn is used for ne#line
8edirecting Standard "utput:9 E$er! rint and rintf state"ent can %e redirected #ith 6 and X
s!"%ol and the filena"e or co""and "ust %e enclosed #ithin dou%le Vuotes.
Ja#k B-SPS T@saEkxFs`ena@ Z rintf R\7d \96Ns \91Ls \dYnS,NR,J6,J7,J* P RsortS [Q e".txt
'he a%o$e state"ent sorts the outut of rintf
state"ent.
Ja#k B-SPS T@saEkxFs`ena@ Z rintf R\7d \96Ns \91Ls \dYnS,NR,J6,J7,J* D RsortfileS [Q
e".txt 'he a%o$e state"ent redirect the outut into a searate file na"ed as sortfile.
Comparision7!ecision ma(ing:9
Ja#k B-SPS TJ7 aa RlecturerS PP J7 aa RrofessorS Z rintf R\96Ls \916s \dYnS,J6,J7,J* [Q
e".txt
3t disla!s all those records the! contains the secified "atch on third field. 'he logical oerators
PP ,
,, and da #orks sa"e as used in C.
J7 da RlecturerS ,, J7 da
RrofessorS
Note:9 ;hen a secified "atch field contains trailing saces then a#k #ont founds erfect
"atch. 4atch <Y= and Negate <2Y= 1erators also used #ith regular exressions:
J6 I @ECcFhoE#uFdhgur!@ PP J6 I @ECcFhaE#uFdhgr!@ 4atches on second field
J6 I @ECcFhoE#uFdhgur! P ECcFhaE#uFdhgr!@ 3t is also sa"e as re$ious
J7 dI @lecturerProfessor@ Neither lecturer nor
rofessor
#ote:9 'o "atch a string e"%edded in a field the use Y instead of ZZ and to negate a "atch then use 2
Y
instead of 2Z.
#ote:9 3f #e #ant to search a attern #hich is e"%edded into the string. i.e. to search onl! g.". %ut
it also e"%edded into d.g.". a#k usages * <"atch at %eginning of field= and + <"atch attern at the
end of the field= characters to "atch at %eginning and end of a field.
Ja#k B-SPS TJ7 I@bg.".@ Z rintf J6,J7,J* [Q e".txt 3t searches onl! g.". and discarded
d.g.".
Storing a)( program into a ile 4 3 A :9 ;hen the rogra" is stored into a file then the
stored rogra" is not enclosed #ithin Vuotes. 'he single Vuotes onl! used #hen rogra" is
#ritten at co""and ro"t.
J$i e".a#k
J7 aa RlecturerS ,, J7 aa RrofessorS Z
rintf R\96Ls \916s \dYS,J6,J7,J* [
#umber Erocessing :9 ;ith a#k co""and #e can use all the relational oerators <C, Ca, D, Da,
aa,
da, I "atch a regular exression, dI donQt "atch a regular exression= and arith"etic oerators
<W,9,`,@
\= #hich are used in C
language.
Ja#k B-SPS 9f e".a#k e".txt 'he Bf filena"e is used to secif! rogra" file
na"e.
Ja#k B-SPS TJ* D OLLL Z rintf R\96Ls \916s \dYnS, J6,J7,J* [Q
e".txt
a#k handles %oth integer and floating t!e nu"%ers. ;e can also co"%ine regular exression
#ith nu"eric co"arisons. Locate all those records the! %orn in 1)ON or the! dra#ing %asic a!
greater than OLLL.
Ja#k B-SPS TJ* D OLLL PP JN I@ONJ@Q e".txt
Ja#k B-SPS TJ7 aa RlecturerS Z rintf R\96Ls \916s \d \d \dS,J6,J7,J*,J*`L.K,J*`L.1N [S e".txt
'he a%o$e co""and calculates the dearness allo#ance < H KL\ of %asic a!= and house rent < H 1N\
of %asic a!=.
[ariables :9 a#k has certain %uilt9in $aria%les i.e. NR,JL and it also er"its the user to define
user9 defined $aria%les. 'he user defined $aria%les has t#o secial features.
5 No data t!e declarations reVuired.
5 B! default $aria%les are initiali.ed to .ero or a null string deending on its t!e.
Ja#k B-SPS TJ7 aa RlecturerS , J* D OLLL Z ctr a ctr W 1, rintf R\7d \96Ls \916s
\dYnS, ctr,J6,J7,J* [Q e".txt
Ja#k B-SPS TJ7 aa RlecturerS , J* D OLLL Zrintf R\7d \96Ls \916s \dYnS, WWctr,J6,J7,J* [Q
e".txt
'he initial $alue of ctr is L <%! default=. ;e can also use C st!le i.e. ctrWW, ctr Wa 6, WWctr
'he HE\I# and E#! 2ection:9 'he a#k state"ents are alied for all the lines selected %! the
address. But if #e #ant to rint so"ething %efore and after the rocessing then the BE03N and
EN( sections are used.
BE03N Z action [ Both reVuires curl! %races and %oth are otional
EN( Z action [
J$i e"6.a#k
BE03N Z
Printf RYtYtYtE"lo!ees RecordYnYnS
[ J* D OLLL Z
ctrWW 8 total Wa J*
rintf R\7d \96Ls \916s \dYnSctr,J6,J7,J*
[
EN( Z
Printf RYnYtYt'he +$erage Basic Pa! is a \*dYnS,total@ctr
[
Ja#k B-SPS Bf e"6.a#k e".txt
#ote:9 +l#a!s starts the oening %race in the sa"e line #ith the section BE03N or EN(
other#ise a#k generate so"e strange "essages.
Huilt3In [ariables:9 a#k has se$eral %uilt9in $aria%les and all are assigned auto"aticall!.
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9 :aria%le -unction
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9 NR Cu"ulati$e nu"%er of lines read
-2 3nut -ield 2earator
1-2 1utut -ield 2earator
N- Nu"%er of -ields in the current line
-3LEN+4E Current inut file na"e
+R0C Nu"%er of argu"ents in co""and line
+R0: List of argu"ents
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9he FS [ariable:9 'he a#k usages the sace as the default field deli"iter. -2 redefines this field
searator and it "ust occur in the BE03N section. 'his is an alternati$e to the B- otion used in
the co""and. BE03N Z -2aSPS [
9he "FS [ariable:9 3n the rint state"ent co""a9searated argu"ents usages the field searator is
a sace. 'o change it then #e use 1-2 and it also "ust occur in the BE03N section. BE03N Z
1-2aSPS[
9he #F [ariable:9 3t contains the total nu"%er of fields in the line.
Ja#k TBE03N Z -2 a RPS [ N- da * Z
rint RRecord No R, NR, Rhas R, N-, R -ieldsS [Q e".txt
9he FILE#A5E variable:9 3t stores the current file na"e #hich is rocessed. Like gre, sed,
a#k also handle "ultile filena"es in the co""and line. B! default a#k does not rint the
filena"e
TJ* C NLLL Z rint -3LEN+4E, JL [Q 3t rints the filena"e also.
Creating a variable:
Cvariable nameDaCvalueD
JnameaSJitendraS
Jecho Jna"e : 'o e$aluate the $alue of a $aria%le, Just refix a + sign %efore $aria%le
Jitendra na"e
Simple arithmetic on shell variables:
Jexpr KW1L : expr can %e used to e$aluate arith"etical co"utations on the shell $aria%les
1K ha$ing integer $alue.
Jexpr O96 U 3t rints *
Jexpr KN@N U 3t rints O
Jsu"aQexr 6NWNQ
Jecho Jsu" U 3' rints 7L
Jxa16
J!aOL
Jecho su" is JxWJ!
su" is 16 W OL
Jecho su" is Texr Jx W J!Q U 3t rints su" is )6
Jsu"aQexr JxWJ!Q
Jecho Jsu"
)6
+ si"le shell rogra" to read t#o nu"%ers and rint su" of t#o nu"%ers
vi sum'sh
echo Be RYn Enter -irst Nu"%er : YcS
read a
echo Be RYn Enter 2econd Nu"%er : YcS
read %
let Rsu" a Ja W J%S
echo Be RYn 'he 2u" of t#o nu"%ers a Jsu"S
9999999999999999999999999999999999999999999999999999999999999999
#ote:3 let co""and is used for calculation in shell scrit and #e can use arith"etic oerators
B 3 > 7 and T'
+let sumZDB? ,'here is no #hite sace after $aria%le na"e
Jecho Jsu" U 3t rints 11
Jlet su"aS 6 ` * W * @ 6 R
+echo Jsu" U3t rints 1N
Jlet xa7 !aN .aK "8 Jlet xa7 !aN .aK U 'he J sign not reVuired %! let
Jlet .axW!WJ. Jlet aaxW!W.
Jecho J. Jecho J.
'he second for" uses the 4 4 A A oerators that relace the let state"ent
itself e.g.
Jlet xa6 !a7 . aN
J<<. axW! W.== U 'he #hite sace is uni"ortant
Jecho J. U 3t rints 1L
J<<.a.W1== U ;e can also use <<.Wa1==
Jecho J. U 'he result is 11
#ote:9 let and its twin , ,- - also allow you to use then as control commands in any of the
shell.s programming constructs. This will certainly speed up script e6ecution.
#ote:9 Bash shell can.t support escape se<uence characters i.e. .n .c .t etc0 so that /e option is
used for supporting an escape se<uence characters.
Relational 1erators:9 Relational oerators are start #ith a "inus <3= sign.
9eV EVual to
9ne Not EVual to
9gt 0reater 'han
9ge 0reater than EVual to
9lt Less 'han
9le Less than EVual to
+ssign"ent of $aria%les:
JxaN8 !aK8 .a7
Conditons:9
if E condition F or if test condition
then then
C2tate"entD
else
C2tate"entD
else
C2tate"dntD
fi
C2tate"entD
fi
e.g.
if E Ja Bgt J% F
then
echo Be RYn :alue of a is greater than $alue of %S
else
echo Be RYn :alue of % is greater than $alue of aS
fi
333or333
if test Ja Bgt J%
then
echo Be RYn :alue of a is greater than $alue of %S
else
echo Be RYn :alue of % is greater than $alue of aS
fi
#ote :9 test can %e used to co"are strings and logical oerators <Z and 2Z= are used.
#ote:9 3@ and &n otions are used to check for a null
string e.g.
vi stchec('sh
echo Be R -ind ;hat: YcS
read J#ord
if E 9. RJ#ordS F 8 then
echo R]ou could not entering a #ord #hich !ou #ant to findS
exit 1
else
echo Be REnter filena"e fro" #hich !ou to find : YcS
read filena"e
if E d Bn RJfilena"eS F 8 then
echo R-ile na"e cant secifiedGdddS
exit 6
else
gre RJ#ordS RJfilena"eS PP echo R2ecified #ord canQt foundS
fi
fi
#ote: 'o check "ore then one condition, the test er"its &a <+N(= &o <1R=
oerators e.g.
if E 9n RJ#ordS 9a Bn RJfilena"eS F 8 then
gre RJ#ordS RJfilena"eS PP echo RNot -ound..ddS
else
echo R+t least one $alue of a $aria%le #as a null stringS
exit 1
fi
Note: 3a otion is used as A#! oerator and &o otion is used as "8 oerator.
e.g.
if E RJchoiceS a R!S Bo RJchoiceS a R]S F
String 9ests:3
9n string :9 'rue if string is not a null string
9. string :9 'rue if string is a null string
$1 a $6 :9 'rue if string $1 a $6
$1 da $6 :9 'rue if string $1 is not eVual to $6
string :9 'rue if string CstringD is secified and not null
Case Conditional
Case CexressionD in
Pattern1= Cstate"entD
88 Pattern6=
Cstate"entD 88
GG
esac
e.g.
echo R 4ENUS
echo R1. (isla! director! listS
echo R6. (isla! current dateS
echo R7. (isla! free "e"or! saceS
echo RK. ExitS
read choice
case RJchoiceS in
1= ls Bl 88
6= date 88
7= df 88
K= exit
esac
'esting -iles :9 'he & otion used #ith 2
oerator e.g.
if E 9f a%c.txt F 8 then
echo R-ile is an ordinar! fileS
fi
vi test'sh
if E d Be J1 F 8 then
echo R-ile does not existS
elif E d Br J1 F 8 then
echo R -ile is not reada%leS
elif E d B# J1 F 8 then
echo R-ile is not #rita%leS
else
echo R-ile is %oth reada%le and #rita%leS
fi
Jsh test'sh xy@'doc @@ to Execute the shell scrit, x!..doc is relaced #ith J1
1tions used for checking files:
9e filena"e : 'rue if file exist
9f filena"e : 'rue if file exist and is a regular file
9r filena"e : 'rue if file exist and is a reada%le
9# filena"e : 'rue if file exist and is a #rita%le
9x filena"e : 'rue if file exist and is a executa%le
9d filena"e : 'rue if file exist and is a director!
9s filena"e : 'rue if file exist and has a si.e greater than .ero
slee Cno.of secondsD : (ela! te"orar! ause
slee 7L : Pauses for 7L seconds
Iterations 7 Loops
;hile E Condition F
do
done
C2tate"entsD
C2tate"entsD
GGG
]. ;rite a shell scrit #hich #ill read ite" code and ite" na"e and store into a file called
ite""aster.
vi item'sh
"orereca!
#hile E RJ"orerecS a R!S F
do
echo Be RYnEnter 3te" Code and 3te" Na"e: YcS
read ite"code ite"na"e U 3t Reads %oth $aria%les
echo RJite"code P Jite"na"eS DD ite""aster U +end a ne# line into ite""aster
file echo Be R(o !ou #ant to add "ore records <!@n=g YcS
read "orerec
case J"orerec in
!`P]`= "orereca! 88 U 3t accets !, ], !es, ]E2
n`PN`= "orerecan 88 U 3t accets n, N, no, N1
`= "orereca! 88 U ;hen ressing an! other character "eans !
esac
done
Jsh item'sh , 'o execute the shell scrit
Note: 3nstead of !` P ]`= and n` P N` , #e can also #rite:
E!]FEeEF`= 88 U 3t 4atches ]E2, !es, ]es, !E2, etc
EnNFEo1F= 88 U 3t 4atches No, no, n1, N1, etc.
Setting up an Ininite loop
;hile true U 'rue co""and al#a!s returns a true $alue
do
date U +fter e$er! 7LL seconds disla!s date on
screen slee 7LL
done , U G sign after execution done runs loo in %ackground
Note5 There is also a command false that always returns a false alue. The brea+ command is use
to terminate the loop.
e ;rite a function that takes a ath as a co""and9line argu"ent, creates all the directories in
the ath and changes the current director! to the last director! in the ath.
+ns:9 Usage createath CPathD
echo J1 D an!file
set Xsed Ts@Y@@ @gQ an!fileX
"kdir J`
aaJ`
iaJU
#hile E Ji Bge 1 F
do
set Ja
shift Xexr Ji 9 6X
"$ J6 J1
3aXexr Ji 9 1X
done
e. ;rite a shell scrit #hich #ill recei$e the file na"e or its full ath as the co""and line
argu"ents. 'he scrit #ill o%tain infor"ation a%out this file fro" the ls Bl co""and and disla!
this infor"ation in a user9friendl! "anner.
+ns :9 Usage: (isla! Cfile or athD, 2tored in file Rdisla!S
ls Bl J1 J1 D an!file
set Xsed Xsed Ts@9@@Q an!fileX
echo R-ile er"ission: J1S
echo R'here are J6 linksS
echo R1#ner of the file is J7S
echo R0rou o#ner is JKS
echo R3t occuies JN %locksS
echo R'he file #as created on J* JM at JOS
e ;rite a shell scrit that #ill accet a string fro" the user. 'he scrit #ill relace all %lank
saces #ith a T9T. 'here should %e not "ore than one Q9T , as the deli"iter %et#een the #ords.
+ns:9
Echo REnter a string
read str
if E 9. str F
then
exit
else
else Jstr P sed Ts@ @9@gQ
fi
e ;rite a co""and to disla! the u%lisher and author of the RCo"uter 1rgani.ationS %ook
#hich #as "ost recentl! urchased <use the file %ook.lst=.
+ns:9 ;e #ill reVuire four co""ands in a ieline to ha$e the reVuired outut as
follo#s:9 gre R1rgani.ationS %ook.lst P sort 9tSPS W7.N 9r P cur 9dSPS 9f7,N P head 91
Note: 'he gre co""and #ill select lines containing the attern R1rgani.ationS
'he sort co""and #ill sort the lines on the date9of9urchase field. BtSPS secifies that the field
deli"iter is ie <P=. W7 secifies to sort after skiing first three fields <i.e. sort the fourth field=.
7.N is used to indicate to start sorting after skiing first fi$e characters in the fourth field <i.e. that
date field=. Br otion re$erses the sort <i.e. sorts in the decreasing order of date=.
cut BdSPS Bf7,N #ill select the u%lisher na"e and author na"e fields fro" the selected
lines. >ead 91 #ill disla! the to"ost line in the list, i.e. the "ost recentl! u%lished
%ook.
e. ;rite a sed co""and to insert t#o saces at the end of each line of a file Rtext.txtS
+ns :9 sed Ts@J@ @Q text.txt.
2hell -unctions :9 Like in other rogra""ing languages, !ou can create and use functions in
shell scrits.
e.g.
Ufile func?sh
user<= U defining function
Z
echo RCurrentl! logged users areS
#ho
[
echo R(o !ou #ant to see user9listS
read ch
if E Jch a T!Q F
then
user U function is called
fi
e. ;rite a 2hell scrit to rint a file in re$erse order.
U re$erse.sh
U Printing file in re$erse order
U Count total no. of lines and then extract line fro" file and store into
ne#file naQcat J1 P #c BlQ
"a1
#hile test Jn Bgt L
do
done
tail 9J" J1 D ne#file
h1aQhead 91 ne#fileQ
echo RJh1S
let naJn91
let "aJ"W1
Note: 3t is also ossi%le to rint a file in re$erse order using a#k.
Ure$erse.sh
Uusages: sh re$erse.sh "!file.txt
if test JU 9ne 1
then
else
echo RUsages: X%asena"e JLX -ileNa"e?to rint in re$erse orderS
exit 1
a#k TZ lineENRF a JL [ EN( Z for <i a NR8 i D L8 i99= rint lineEiF [Q J1
fi
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
e. ;rite a 2hell scrit to "odif! cal co""and to accet "ore than one "onth
U cal1.sh
U +ccet "onth nu"%ers as co""and line
argu"ents if test JU 9ge 1
then
let naL
let "onthaJU
#hile test J"onth 9ne Jn
do
done
let naJnW1
cal J1 6LL)
shift
else
fi
echo ^Usages: X%asena"e JLX 4onth no.Qs as co""and line argu"ent^
E /itendraH n t s e r $ e r shellscritsFJ sh cal.sh LLK L* L)
+ril 6L1L
2u 4o 'u ;e 'h -r 2a
1 6 7
K N * M O ) 1L
11 16 17 1K 1N 1* 1M
1O 1) 6L 61 66 67 6K
6N 6* 6M 6O 6) 7L
June 6L1L
2u 4o 'u ;e 'h -r 2a
1 6 7 K N
* M O ) 1L 11 16
17 1K 1N 1* 1M 1O 1)
6L 61 66 67 6K 6N 6*
6M 6O 6) 7L
2ete"%er 6L1L
2u 4o 'u ;e 'h -r 2a
1 6 7 K
N * M O ) 1L 11
16 17 1K 1N 1* 1M 1O
1) 6L 61 66 67 6K 6N
6* 6M 6O 6) 7L
E /itendraH n t s e r $ e r shellscritsFJ
e. + shell scrit to erfor" real nu"%ers. <2tore real nu"%ers and then ut real nu"%er $aria%les
into %c to erfor" real nu"%ers oeration=.
aaN.*N
%a7.KN
caXecho Ja W J% P %cX
echo RJa W J% a JcS
e. + shell scrit to count total no. of lines, #ords and characters #ithout using #c co""and.
Uscrit.sh
UUsages: -ilena"e as an argu"ent
if test JU 9ne 1
then
echo RUsages: X%asena"e JLX -ileNa"e to count Lines,;ords and CharactersS
exit 1
else
a#k _BE03N Z
rint ^Counting Lines ;ords and Characters^[ Z charWalength 8 #ordsWaN- 8 linesaNR
[
EN( Z
rintf ^\16d \*d \11d Yn^,lines,#ords,char
[_ J1
-i
E /itendraH n t s e r $ e r shellscritsFJ sh rg).sh "!.txt
Counting Lines ;ords and Characters
* 1* 6OL
E /itendraH n t s e r $ e r shellscritsF
J
e. ;rite a shell scrit to rinting stars.
Ustars.sh
echo RPrinting 2tarsGGGS
for << ia18 1CN8 iWW==
do
for << /a18 /Ca38 /WW==
do
done
echo 9n R `S
done
echo R S
for <<iaK8 iDa18 i99==
do
for <</a18 /Cai8 /WW==
do
done
echo Bn R `S
done
echo R R
E /itendraH n t s e r $ e r shellFJ sh stars.sh
Printing 2tars.........
`
` `
` ` `
` ` ` `
` ` ` ` `
` ` ` `
` ` `
` `
`
E /itendraH n t s e r $ e r shellFJ
e + 2hell scrit to rint stars <for loo different uses=
Uforloo.sh
4+AaL
echo Bn REnter Nu"%ers %et#een < 7 and )= : R
read 4+A
if d E J4+A 9ge 7 Ba J4+A Ble ) F 8 then
echo R3 ask to enter nu"%ers %et#een 7 and )S
exit 1
fi
clear
for << ia18 iCa4+A8 iWW==
do
for << /a4+A8 /Dai8 /99 ==
do
done
echo Bn R R
for << ka18 kCai8 kWW = =
do
done
echo Bn R `S
done
echo RS
UU 2econd 2tage UU
for << ia4+A918 iDa18 i99 ==
do
for << /ai8 /Ca 4+A8 /WW ==
do
done
echo Bn R R
for << ka18 kCai8 kWW==
do
done
echo Bn R `S
done
echo RS
E /itendraH n t s e r $ e r shellFJ sh forloo.sh
Enter Nu"%ers %et#een <7 and )= : *
`
` `
` ` `
` ` ` `
` ` ` ` `
` ` ` ` ` `
` ` ` ` `
` ` ` `
` ` `
` `
`
E /itendraH n t s e r $ e r shellFJ
What is a system Call :9 + s!ste" call is a call to the oerating s!ste" that reVuests the kernel
to carr! out certain lo#9le$el oerations. Progra""ers can use the s!ste" calls read<= and #rite<= to
erfor" 3@1 oerations.
#IS :9 Net#ork 3nfor"ation 2er$ice #as created %! 2un 4icros!ste"s as a #a! of "anaging
infor"ation that is shared a"ong a grou of host co"uters on a net#ork. B! using N32
Co"uters can share a co""on set of user accounts, user grous and 'CP@3P host na"es, as #ell
as other infor"ation.
+ote 5: +IS was originally called Aellow 2ages0 /ut sun had to change this name /ecause it
was trademar(ed.
'he grou of co"uters that the "aster N32 ser$er suorts is referred to as an N32 do"ain.
Setting up 8edhat Linux as an #IS Client :9 ;e needs follo#ing infor"ation to setu N32
clients a= #IS !omain #ame :9 0rou of hosts that use the co""on set of N32 files.
%= #IS 5aster Server #ame :9 Na"e of the co"uter on the net#ork that "aintains the N32
(ata%ases and resonds to reVuests fro" the net#ork for that infor"ation.
1. !eine #IS !omain #ame :9 'he domainname co""and is used to setu N32 do"ainna"e.
i.e. domainname ecb.ac.in
+ote 5: To erify that +IS domain name is set0 Bust type domainname then it returns +IS
domain name. 9s soon as when you re/oot the computer0 it is gone.
'o "ake the do"ain na"e er"anent then #e need the do"ainna"e co""and run
auto"aticall! each ti"e #hen s!ste" %oots. 'hen edit the 7e t c 7i n it' d 7n e t )o r ( file and add the
follo#ing line:9
domainname ecb'ac'in
+ote5: If the domain name is wrong then yp/ind daemon is failure.
6. Setting up the 7etc7yp'con ile :9 !%ind dae"on needs infor"ation a%out N32 do"ain
and N32 ser$ers for it to #ork. 3- N32 do"ain na"e is ec%.ac.in , the "aster ser$er na"e
is ec%ser$er then the follo#ing entr! #ill %e in 7e t c 7y p ' c o n file:
domain ecb'ac'in server ecbserver
7. Conigure #IS Client daemon :9 +fter N32 client infor"ation is set u, #e need to run N32
as a client is start the ypbind and yp)hich dae"ons.
'he "aster !%ind rocess handles reVuests for infor"ation fro" the N32 ser$er. 'he yp)hich
dae"on finds the N32 "aster ser$er.
K. 'o setu an existing run9le$el scrit called !%ind to start auto"aticall! at %oot ti"e.
'!e follo#ing co""and as root ,ch(conig ypbind on
%oot.
1r #e can also t!e the follo#ing co""ands to link the !%ind run le$el scrit so it starts at
,ln &s 7etc7init'd7ypbind 7etc7rcM'd7S/Mypbind
,ln &s 7etc7init'd7ypbind 7etc7rcD'd7S/Mypbind
N. Enter the follo#ing co""and to i""ediatel! starts the ypbind ser$ice.
,service ypbind start
or
,7etc7init'd7ypbind start
+ote 5 Instead of start we can also use stop (to stops the serice)0 restart (to restart the serice)0 status
(To find out the current status of a serice i.e. serice is running or stoped)
*. Chec(ing that #IS is )or(ing or not :
,yp)hich It returns the #IS Server #ame'
,ypcat hosts Chec( the maps are being shared'
M. #IS 5aps :9 'o generate the N32 "as then configure the 7etc7nss)itch'con file to
include in the search ath.
ass#d: files nis
shado#:
grou:
files
files
nis
nis
hosts: files nis
Note5 Cor each of these entries0 the original files are chec(ed first ,0etc0pass(d1 0etc0s2ado( and
so on)0 then the nis serer is chec(ed.
Note5: 9s soon as the 0etc0nss(itc2.conf file is changed0 the data from the +IS maps are
accessi/le0 there is no need to restart the +IS serice.
Note5 4e can also use authconf to configure +IS
Setting up #IS 5aster Server :9 9o conigure linux system as #IS master server< you
should irst conigure it as #IS client. 'hen create the N32 "as and configure the N32 "aster
ser$er
dae"on rocess <ypserv and rpc'yppass)dd=.
,service ypserv start or ,7etc7init'd7ypserv start
,service yppass)dd start or ,7etc7init'd7yppass)dd start
1. Create #IS maps :9 3n 7var7yp director! a 5a(eile ena%les !ou to configure #hich files
are %eing shared #ith N32.
a= Choose iles to map :9 2ecif! all the files #hich !ou #ant to "as in the all entr!: e.g.
all: pass)d group hosts rpc services netid protocols mail ^
U netgr shado# u%licke! GGGGGGGGGG Y
+ote 5: To /uild +IS maps0 your system must hae a(+1 ma+e 3 umas+ commands. The locations of
these commands are 0usr0bin04a(+1 0usr0bin04ma+e and umas+ ( The umas+ command is a shell
/uilt in command0 so that we don.t hae to loo( for its location).
6. !eine #IS client access :9 B! default an! co"uter on an! net#ork that can reach N32
"aster, can access "as.
7. \enerate #IS 5aps :9 Enter the follo#ing co""and to generate "as :
,7usr7lib7yp7ypinit &m
+dd a ser$er na"e at a ti"e and then press *d then $erif! that the list of ser$ers is correct <press
y=. 'he data%ase is %uilt at this oint. + ne# director! na"ed N32 do"ain na"e is created in
@$ar@! director!.
K. Conigure #IS server daemons :9 Enter follo#ing co""ands to configure N32
ser$er dae"ons:
,ch(conig ypserv on
,ch(conig yppass)dd on
Setting up #FS Server :9 'here are 7 "ain configuration files !ou #ill need to edit to setu N-2
ser$er. 7etc7exports< 7etc7hosts'allo)< 7etc7hosts'deny. ]ou onl! need to edit the 7etc7exports to
get N-2 #orks.
3n the 7etc7exports file ut an entr! in the follo#ing for"at :
!irectory machine/4option//<option/1A machine14option1/<option11A
!irectory :9 'he director! that !ou #ant to share. 3t "a! %e an entire $olu"e though it need not
%e.
5achine/ G 5achine1 :9 Client "achines that #ill ha$e access to the director!. 'he "achines
"a! %e listed %! their (N2 address or their 3P address <e.g. La%N91.ec%.ac.in or 1)6.1*O.N.*=. Using
3P address is "ore relia%le and "ore secure. 3f !ou need to use (N2 addresses, and the! do not
see" to %e resol$ing to the right "achine.
"ptionxx :9
ro :9 'he director! is shared read onl!. 'he client "achine #ill not %e a%le to #rite to it. 'his
is the default.
r) :9 'he client "achine #ill ha$e read , #rite access to the director!.
noUrootUs-uash :9 B! default, an! file reVuest "ade %! user root on the client "achine is
treated as if it is "ade %! user no%od! on the ser$er, if no?root?sVuash is selected, then root on
the client "achine #ill ha$e the sa"e le$el of access to the files on the s!ste" as root on the
ser$er.
noUsubtreeUchec(:9 3f onl! art of a $olu"e is exorted, a routine called su%tree checking
$erifies that a file that is reVuested fro" the client is in the aroriate art of the $olu"e. 3f the
entire $olu"e is exorted, disa%le this check #ill seed u transfers.
sync:9 B! default all $ersion of exports co""and #ill use async
%eha$ior. i.e. 7etc7exports
@usr@local 1)6.1*O.L.1<ro= 1)6.1*O.L.6<ro=
@ho"e 1)6.1*O.L.1<r#= 1)6.1*O.L.6<r#=
+ote 5: #ere we share "usr"local read:only to slae1 and slae'0 /ecause it pro/a/ly contains our
software D there may /e /enefits to allowing slae1 D slae' to write to it that outweigh
security concern. The "home directory need to /e e6ported read write if users are to sae wor(
on them.
"home 1,'.1EF.0.0"'GG.'GG.'GG.0(rw) :9 +ll the client net#ork co"uter the!
are resent on net#ork 1)6.1*O.x.x can access the ser$ers ho"e director!.
9o orce nsd to re read the 7etc7exports ile< give the ollo)ing command :3
,exports &a &v
Setting up #FS Clients :9 4odif! the 7etc7stab file to "ount the ser$ers shared director! #hen
the s!ste" is %ooting :9
Enter the follo#ing entr! in 7etc7stab file.
2er$erna"e:@ho"e @ho"e nfs defaults L L
!eleting $ser Accounts :9 'he userdel co""and is use to delete an user account.
Uuserdel username :9 3t deletes the user account %ut canQt delete users ho"e director!.
Uuserdel 3r username :9 (elete user account as #ell as his ho"e director! also.
Searching :9 'o find out a user #hich is alread! exist or not.
Uind 7 3user username &print :9 2earch all the files starting fro" @ <root director!= for all files ,
directories o#ned %! secified user and rint the filena"e on screen.
Uind 7home 3user username &exec rm VW ^J :9 2earch all files and su%directories under the
@ho"e that are o#ned %! userna"e. 'hen run the r" co""and to delete each of those files.
Uind 7 3user oldusername 3exec cho)n ne)username VW ^J :9 2earch all files and directories
under @ root that are o#ned %! user olduserna"e and run the cho#n co""and to change each file,
so that it is o#ned %! ne#user instead.
Uind 7 3uid uid3no cho)n ne)username VW ^J :9 2a"e as re$ious co""and %ut it usages the
user id nu"%er instead of olduser na"e, to identif! the "atching files. 'his is useful #hen #e
deleted a user %efore con$erting her files.
3print :9 Lists the "atching files.
VW :9 'he VW characters designate #here the "atching filena"e should %e filled in #hen find runs
the Bexec otion.
^J :9 'ells linux #here the co""and ends.
Installing Applications :9 1. 'o install RP4 -iles :9 'he rpm co""and has these "odes
of oerations:9
9i a 3nstall 9U a Ugrade ackage 9V a euer!
9$ a :erif! 9e a Uninstall 99seter"s a -ix
Per"issions
9% a Build 99checking a 2ignature Check
99re%uildd% a Re%uild data%ase.
e.g.
Urpm 3i :options; pac(age:9 'o install RP4 archi$e files.
+ote5: 9long with Hi option0 we can use these options to /et feed/ac(.
3vv Prints the de%ugging infor"ation during installation.
3h Prints NL hash "arks <U= as the ackage is unacked.
3percent Prints the ercentage of the total ackage that has %een installed.
+ote 5: rpm chec(s /efore installing a pac(age to ma(e sure that it is not oerwriting newer files
or installing a pac(age that has dependencies on other pac(ages that are not installed.
i.e. U rpm 3ivv pac(agename'rpm
+ote5: The following options can /e used to oerride conditions that may otherwise cause
the installation to fail.
33orce :9 -orces the contents of the current ackage to %e installed, e$en if the current
ackage is older than the one alread! installed <it is sa"e as oldackage, relacefiles, relacekgs
otions=
33oldpac(age :9 'he ackage to %e installed, e$en if the current ackage is older than the one
alread! installed.
33replaceiles :9 'he ackage to %e installed, e$en if the files #ere laced there %! other ackage.
33nodeps :9 2ki ackage deendenc! checks and installs the ackage, e$en if ackages
it deends on or not installed.
33ignorearch :9 'he ackage to %e installed, e$en if the %inaries in the ackage donQt "atch
it deends on or not installed.
33ignoreos :9 'he ackage to %e installed, e$en if the %inaries in the ackage donQt "atch
the architecture of !ou oerating s!ste".
i.e. Urpm 3$ 33oldpac(age pac(age3name'rpm
8emoving Eac(ages :9
Urpm 3e pac(age3name :9 Re"o$e the ackage if there are no deendencies on
this ackage, it is silentl! re"o$ed.
Urpm 3evv pac(age3name X more :9 'his sho#s the files that are %eing re"o$ed one age
at a ti"e.
Urpm 3evv 33test pac(age3name :9 'his test "ode sho#s !ou e$er!thing that
#ould
haen in the uninstall #ithout actuall! uninstalling. ]ou can al#a!s run the uninstall in test "o$e <
99 test = %efore !ou do the real uninstall.
]uerying Eac(age :9
Urpm 3-a pac(age3name :9 Lists all installed ackage.
3-i :9 Lists lots of infor"ation a%out a ackage <i.e. :ersion no.,
Co"an!, (ate, 2i.e etc.=
3-l :9 Lists all the files contained in the ackage
3-c :9 Lists all configuration files that co"es in the ackage
3-d :9 Lists all docu"entation files that co"es in the ackage.
Using "k%ootdisk in Red>at and deri$ati$es to create a ne# %ootdisk:
1. Look in @li%@"odules and select the aroriate kernel $ersion.
6. Place a flo! in the dri$e.
7. U"k%ootdisk 99de$ice @de$@fdL 6.x.!9. <the latter nu"%er should %e !our kernel
$ersion=
K. Re"o$e !ou ne# %oot flo! and test it.
``````````````````````````````````````````````````````````````````````````
!#S :9 + static 3P address is necessar! to assign the ser$er a host na"e in do"ain na"e s!ste". ]ou
#ants one static i address for each co"uter that !ou "ake u%licl! accessi%le to the internet.
Chec(ing domain name availability :9 3n Linux the )hois co""and is use to checks the
do"ain na"e a$aila%ilit!.
i.e. U)hois ecb'ac'in
Add !#S Server Inormation :9 'he other co"uters on !our L+N oint to !our (N2 ser$ers
to resol$e do"ain na"es to 3P addresses <'he 7etc7resolv'con file is #here !ou identif! !our
(N2 ser$ers=.
!#S Server $sages the Eort #o' DM. 'o see #hich orts are assigned to #hich ser$ices %!
default see the 7etc7services file.
'he (o"ain Na"e 2!ste" (N2 is essentiall! a distri%uted data%ase that translates host na"es into
3P
addresses. <and 3P addresses %ack to hosts na"es.=
!#S Coniguration Files :9 <@etc@na"ed.conf , @$ar@na"ed@`=
1' vi 7etc7named'con :9 'o +dd the (N2 fone entr!.
i.e. .one Rec%.ac.inS 3N Z
t!e "aster8
file Rec%.ac.in..oneS8
[8
1' vi 7var7named7ecb'ac'in'@one
J''L
8na"e
O*KLL
class t!e full! Vualified +d"inistrator E"ail
8 do"ain na"e address
H 3N 21+ ns1.ec%.ac.in. root.ns1.ec%.ac.in. <
1 8 2erial
6OOLL 8 Refresh
1KKLL 8 Retr!
7*LLL 8 Exire
O*KLL = 8 4ini"u"
8 Na"e 2er$ers
3N N2 ns1.ec%.ac.in.
3N N2 ns6.ec%.ac.in.
8 4ail 2er$ers for (o"ain
3N 4A 1L "ail.ec%.ac.in.
3N 4A 6L cse.ec%.ac.in.
8 Pu%lic 2er$ers
ns1 3N + 167.KN.*1.1
ns6 3N + 167.KN.*1.6
"ail 3N + 167.KN.*1.7
### 3N + 167.KN.*1.6
``````````````````````````````````````````````````````````````````````````
+99L M! :9 fone 'i"e to Li$e <''L= $alue, ''L is to reduce the nu"%er of (N2 Vueries
the authoritati$e (N2 ser$er has to ans#er.
#ame :9 'he root na"e of the .one. 'he H sign is a shorthand reference to the current origin <.one=
Class:9 'here are no. of different (N2 classes 3N or 3nternet Classes.
9ype :9 'he t!e (N2 resources record. i.e. 21+ is resource record, N2, 4A, +, CN+4E, P'R
#ame Servers:9 -ull! Vualified na"e of !our ri"ar! na"e ser$er.
Serial :9 3ncrease the 2erial No. to alert other ser$ers that the! need to get fresh data a%out
!our do"ain.
8eresh :9 (efine ho# often the sla$e (N2 for the .one checks for changes.
8etry :9 3f the sla$e canQt reach the "aster retr! again after 1KKLL seconds.
Expire :9 3f sla$e canQt contact the "aster #ithin the exire ti"e, the sla$e discards the data.
5inimum:9 (efines the cache ti"e to li$e for negati$e ans#er.
'he <N2= define the na"e ser$ers that reresent this .one. N2 record define hosts #ith the na"es ns1
, ns6 in ec%.ac.in.
'he <4A= record indicates the location of the "ail ser$er for the do"ain, so that the (N2 ser$er
can direct e"ail to users in ec%.ac.in.
9o Chec( the @one ile is correctly ormed'
i.e. Unamed3chec(@one ecb'ac'in 7var7named7ecb'ac'in'@one
'o starting the na"ed <(N2=
dae"on. i.e. ,7etc7init'd7named
start
9o Chec(ing that !#S is )or(ing'
Udig ecb'ac'in or Unsloo(up ))) ' ec b ' a c ' in
Uhost ))) ' ec b ' a c ' in or Uhost /1M'ND'?/'1
Hind :9 Bind is an acron!" for the Berkele! 3nternet Na"e (o"ain ro/ect, #hich is a grou that
"aintains the (N2 related soft#are suite that runs under linux.
Samba :9 2a"%a is a soft#are ackage #hich is use to share file s!ste" and rinters on a net#ork
#ith co"uters that use the 2ession 4essage Block <24B= rotocol. 2a"%a configuration file
resent in @etc@sa"%a@s"%.conf.
(ae"on rocesses consist of s"%d < the 24B dae"on = , n"%d <the NetB312 na"e ser$er=.
;e can check the configuration file using testar" , testrns co""ands. 'he s"%status
co""and #ill tell !ou #hich co"uters are currentl! connected to !our shared resources.
Using the n"%looku co""and, #e can Vuer! for NetB312 na"e <'he na"es used to identif!
host co"uters in sa"%a=.
2a"%a usages the NetB312 ser$ice to share resources #ith 24B
client. Eglo%alF
na"e resol$e order a #ins %cat hosts
#orkgrou a ECB
net%ios na"e a CCL+B
Eho"eF
2er$er 2tring a 2a"%a ser$er on \$
hosts allo# a 1)6.1*O.L. 1)6.1*O.1.
share "odes a !es
ass#d rogra" 9 @usr@%in@ass#d \u
"ax disk si.e a 1LLLL
dns rox! a no
logon scrit a \U.%at
local "aster a !es
os le$el a 77
securit! a user
Printca na"e a @etc@rintca
Load Printers a !es
Printing a cus
Log file a @$ar@log@sa"%a@\".log U\" auto"aticall! relaced #ith each host na"e.
4ax log si.e a L
Encr!t ass#ords a !es
2"%ass#d file a @etc@sa"%a@s"%ass#d
(ns rox! a no
add "achine scrit a @usr@s%in@useradd 9s @%in@false 9d @t" T\uQ
add user scrit a @usr@s%in@useradd 9" T\uQ
delete user scrit a @usr@s%in@userdel 9r T\uQ
add grou acrit a @usr@s%in@grouadd T\gQ
delete grou scrit a @usr@s%in@groudel T\gQ
add user to grou scrit a @usr@s%in@user"od 90 T\gQ T\uQ
logon dri$e a f:
userna"e "a a @etc@sa"%a@s"%users
do"ain "aster a !es
encr!t ass#ords a !es
logon ho"e a YY \ L Y\ U
#ins rox! a !es
#ins suort a !es
ser$er string a ECB 2er$er
ath a @$ar@sool@sa"%a
unix ass#ord s!nc a !es
logon ath a YY \ L YP ro file s Y\ U
referred "aster a !es
a" ass#ord change a !es
do"ain logon a !es
"ax log si.e a NL
log file a @$ar@log@sa"%a@\".log
rinter a h)LLL
"a acl inherit a !es
Co""ent a >o"e (irectories
Bro#sa%le a no
Create "ode a L**K
(irector! "ode a LMMN
4ax connections a K
;rita%le a !es
ErintersF
Co""ent a +ll Printers
Path a @$ar@sool@sa"%a
Bro#sa%le a no
0uest ok a no
Printa%le a !es
EnetlogonF
co""ent a Net#ork Logon 2er$ices
ath a @ho"e@share@netlogon
guest ok a no
#rita%le a no
%ro#sea%le a no
share "odes a no
root reexec a @ho"e@share@scrits@"akelogonscrit.1 \U \L \0
root ostexec a r" @ho"e@share@netlogon@\u.%at
EProfilesF
ath a @ho"e@share@rofiles
%ro#sea%le a no
guest ok a !es
#ritea%le a !es
root reexec a @%in@"kdir @ho"e@share@rofiles@\U8 Y
@%in@cho#n \U @ho"e@share@rofiles@\U8 Y
@%in@ch"od MLL @ho"e@share@rofiles@\U
ELearningF
co""ent a -ile Pro$ided %! 'eachers to 2tudents
ath a @ho"e@share@learning
#ritea%le a no
%ro#sea%le a !es
read onl! a !es
u%lic a !es
force create "ode a **K
force director! "ode a MMN
EPrintersF
co""ent a >P )LLL Printer in Co"uter La%
ath a @$ar@sool@sa"%a
%ro#sea%le a !es
guest ok a no
rinta%le a !es
use client dri$ers a !es
Installing Hoot Image When boot loader is crupted
1. Boot fro" Linux C( 1
1' Choose Linux 8escue : Select #e)t)or(ing F7# to #"
M' Uchroot 7mnt7sysimage
N' Ugrub3install 7dev7hda
D' Ureboot
9o conigure A!SL Eac(age : 3nstall r9oe Package and the configure
follo#ing ara"eters:9
1. userid 6. Net#ork 3nterface <ethL or G.=
7. (e"and :alue <Nor"all! !ou can lea$e it %lank.
K. (N2 3nfor"ation <Pri"ar! , 2econdar!=
Note5 +ormally D+S information leae it /lan( (automatically accepted)
Uadsl3setup
Enter UserNa"eGGg
i. Enter !ou PPPLE UserNa"eGg
ii. Enter the Ethernet 3nterface connected to the +(2L 4ode"Gg EthL
iii. (N2 G.g *1.1.16O.N *1.L.L.N
i$. Pass#ordG.g
$. -ire#allGg L a None, 1 a 2tandalone 6 a 4asVuerade <Choose 6 a t!e of -ire#all=
$i. +ccet these settings <!@n=Gg ]
+d/ustingG.. @etc@@Le.conf , @etc@resol$.conf
Uadsl3start : 'o start the connection
Uadsl3status : Check status of connection
Uadsl3stop : 'o sto the connection.
Ulsmod : Listing Loaded 4odules. i.e
Co"1 : @de$@tt!@2L
Co"6 : @de$@tt!@21
!ierence bet)een Linux and $nix
LI#$% $#I%
What is it? Linux is an exa"le of 1en
2ource soft#are de$elo"ent
and -ree 1erating 2!ste"
<12=.
Unix is an oerating s!ste"
that is $er! oular in
uni$ersities, co"anies, %ig
enterrises etc.
Cost Linux can %e freel! distri%uted
do#nloaded freel!, distri%uted
through "aga.ines, Books etc.
'here are riced $ersions for
Linux also, %ut the! are
nor"all! cheaer than
;indo#s.
(ifferent fla$ors of Unix ha$e
different cost structures
according to $endors
$ser E$er!one. -ro" ho"e users to
de$eloers and co"uter
enthusiasts alike.
Unix oerating s!ste"s #ere
de$eloed "ainl! for
"ainfra"es, ser$ers and
#orkstations excet 12A,
;hich is designed for
e$er!one. 'he Unix
en$iron"ent and the client9
ser$er rogra" "odel #ere
essential ele"ents in the
de$elo"ent of the 3nternet
5anuacturer Linux kernel is de$eloed %!
the co""unit!. Linus
'or$alds o$ersees things.
'hree %iggest distri%utions are
2olaris <1racle=, +3A <3B4= ,
>P9UA >e#lett Packard. +nd
+le 4akes 12A, an unix
%ased os..
$sage Linux can %e installed on a
#ide $ariet! of co"uter
hard#are, ranging fro"
"o%ile hones, ta%let
co"uters and $ideo ga"e
consoles, to "ainfra"es and
suerco"uters.
'he UN3A oerating s!ste" is
used in internet ser$ers,
#orkstations , PCs.
Back%one of the "a/orit! of
finance infrastructure and
"an! 6Kx7*N high a$aila%ilit!
solutions.
!evelopment and
!istribution
Linux is de$eloed %! 1en
2ource de$elo"ent i.e.
through sharing and
colla%oration of code and
features through foru"s etc
and it is distri%uted %! $arious
$endors.
Unix s!ste"s are di$ided into
$arious other fla$ors, "ostl!
de$eloed %! +',' as #ell as
$arious co""ercial $endors
and non9rofit organi.ations.
\$I Linux t!icall! ro$ides t#o
0U3s, &(E and 0no"e. But
there are "illions of
alternati$es such as LA(E,
Afce, Unit!, 4ate, t#", ect.
3nitiall! Unix #as a co""and
%ased 12, %ut later a 0U3 #as
created called Co""on
(eskto En$iron"ent. 4ost
distri%utions no# shi #ith
0no"e.
File system support Ext6, Ext7, ExtK, Jfs,
Reiser-2, Afs, Btrfs, -+',
-+'76, N'-2
/fs, gfs, hfs, hfsW, ufs, xfs, .fs
for"at
9ext mode interace
B+2> <Bourne +gain 2>ell=
is the Linux default shell. 3t
can suort "ultile
co""and interreters.
1riginall! the Bourne 2hell.
No# it_s co"ati%le #ith
"an! others including B+2>,
&orn , C.
Erice
-ree %ut suort is a$aila%le
for a rice.
2o"e free for de$elo"ent
use <2olaris= %ut suort is
a$aila%le for a rice.
Security Linux has had a%out *L91LL
$iruses listed till date. None of
the" acti$el! sreading
no#ada!s.
+ rough esti"ate of UN3A
$iruses is %et#een ON 916L
$iruses reorted till date
9hreat detection and
solution
3n case of Linux, threat
detection and solution is $er!
fast, as Linux is "ainl!
co""unit! dri$en and
#hene$er an! Linux user
osts an! kind of threat,
se$eral de$eloers start
#orking on it fro" different
arts of the #orld
Because of the rorietar!
nature of the original Unix,
users ha$e to #ait for a #hile,
to get the roer %ug fixing
atch. But these are not as
co""on.
Erocessors (o.ens of different kinds. xO*@x*K, 2arc, Po#er,
3taniu", P+9R32C, Po#erPC
and "an! others.
Examples U%untu,-edora,Red >at,
(e%ian, +rchlinux,+ndroid
etc.
12 A, 2olaris, +ll Linux
Architectures
1riginall! de$eloed for
3ntel_s xO* hard#are, orts
a$aila%le for o$er t#o do.en
CPU t!es including +R4
3nsired %! 43N3A <a Unix9
like s!ste"= and e$entuall!
after adding "an! features of
0U3, (ri$ers etc, Linus
is a$aila%le on P+9R32C and
3taniu" "achines. 2olaris also
a$aila%le for xO*@x*K %ased
s!ste"s.12A is
Po#erPC<1L.L9
1L.N=@xO*<1L.K=@x*K<1L.N9
1L.O=
Inception
'or$alds de$eloed the
fra"e#ork of the 12 that
%eca"e L3NUA in 1))6. 'he
L3NUA kernel #as released
on 1Mth 2ete"%er, 1))1
3n 1)*), it #as de$eloed %! a
grou of +',' e"lo!ees at
Bell La%s and (ennis Ritchie.
3t #as #ritten in RCS language
and #as designed to %e a
orta%le, "ulti9tasking and
"ulti9user s!ste" in a ti"e9
sharing configuration
$#I% "perating System #ames
+ fe# oular na"es:
1. >P9UA
6. 3B4 +3A
7. 2un 2olairs
K. 4ac 12 A
N. 3R3A
Linux !istribution 4"perating SystemA #ames
+ fe# oular na"es:
1. Redhat Enterrise Linux
6. -edora Linux
7. (e%ian Linux
K. 2use Enterrise Linux
N. U%untu Linux
Common 9hings Het)een Linux G $#I%
Both share "an! co""on alications such as:
1. 0U3, file, and #indo#s "anagers <&(E, 0no"e=
6. 2hells <ksh, csh, %ash=
7. :arious office alications such as 1en1ffice.org
K. (e$elo"ent tools <erl, h, !thon, 0NU c@cWW co"ilers=
N. Posix interface
!ierence bet)een Linux and Windo)s
Linux Windo)s
What is it?
Linux is an exa"le of 1en
2ource soft#are de$elo"ent
and -ree 1erating 2!ste"
<12=.
;indo#s is the fa"il! of
oerating s!ste" <12= fro"
4icrosoft, #hich is the "ost
fa"ous 12 in the #orld.
Cost Linux can %e freel!
distri%uted, do#nloaded
freel!, distri%uted through
"aga.ines, Books etc. 'here
are riced $ersions for Linux
also, %ut the! are nor"all!
cheaer than ;indo#s.
-or deskto or ho"e use,
;indo#s can %e exensi$e. +
single co! can cost around
JNL to J KNL deending on the
$ersion of ;indo#s
$ser
E$er!one. -ro" ho"e users to
de$eloers and co"uter
enthusiasts alike.
E$er!one. -ro" ho"e users to
de$eloers and co"uter
enthusiasts alike.
5anuacturer Linux kernel is de$eloed %!
the co""unit!. Linus
'or$alds o$ersees things.
4icrosoft created the
;indo#s oerating s!ste",
%ut allo#s other co"uter
"anufactures to distri%ute
their o#n co"uters #ith
;indo#s re9installed.
$sage Linux can %e installed on a
#ide $ariet! of co"uter
hard#are, ranging fro"
"o%ile hones, ta%let
co"uters and $ideo ga"e
consoles, to "ainfra"es and
suerco"uters.
1n PC_s desktos, latos,
ser$ers and so"e hones.
!evelopment and
!istribution
Linux is de$eloed %! 1en
2ource de$elo"ent i.e.
through sharing and
colla%oration of code and
features through foru"s etc
and it is distri%uted %! $arious
$endors.
;indo#s is de$eloed and
distri%uted %! 4icrosoft.
\$I Linux t!icall! ro$ides t#o
0U3s, &(E and 0no"e. But
there are "illions of
alternati$es such as LA(E,
Afce, Unit!, 4ate, t#", ect.
'he ;indo#s 0U3 is an
integral co"onent of the 12
and is not relacea%le. 'his
can %e a con #hen it co"es to
;indo#s O_s 4etro
File system support Ext6, Ext7, ExtK, Jfs,
Reiser-2, Afs, Btrfs, -+',
-+'76, N'-2 -+'
-+'76, N'-2, ex-+'
9ext mode interace B+2> <Bourne +gain 2>ell=
is the Linux default shell. 3t
can suort "ultile
co""and interreters.
;indo#s uses a co""and
shell and each $ersion of
;indo#s has a single
co""and interreter #ith dos9
like co""ands, recentl! there
is the addition of the otional
Po#er2hell that uses "ore
Unix9like co""ands.
Erice -ree %ut suort is a$aila%le
for a rice.
JNL9JKNL
Security Linux has had a%out *L91LL
$iruses listed till date. None of
the" acti$el! sreading
no#ada!s.
+ccording to (r. Nic Peeling
and (r Julian 2atchell_s
R+nal!sis of the 3"act of
1en 2ource 2oft#areS there
ha$e %een "ore than *L,LLL
$iruses in ;indo#s. +nti
:irus cost a%out J6L to JKLL
9hreat detection and
solution
3n case of Linux, threat
detection and solution is $er!
fast, as Linux is "ainl!
co""unit! dri$en and
+fter detecting a "a/or threat
in ;indo#s 12, 4icrosoft
generall! releases a atch that
can fix the ro%le" and it can
#hene$er an! Linux user
osts an! kind of threat,
se$eral de$eloers start
#orking on it fro" different
arts of the #orld
take "ore than 6@7 "onths.
2o"eti"es sooner, 4icrosoft
releases atches and udates
#eekl!.
Erocessors (o.ens of different kinds. Li"ited %ut "ost <OL\=
Examples U%untu, -edora, Red >at,
(e%ian, +rchlinux, +ndroid
etc.
;indo#s O, O.1, M, :ista, AP
\aming :er! fe# ga"es a$aila%le
nati$el!. 2o"e ga"es can %e
la!ed through ;ine, %ut
often not all features are
a$aila%le.
+l"ost all ga"es are
co"ati%le #ith ;indo#s.
2o"e CPU intensi$e and
grahics intensi$e ga"es are
exclusi$e to ;indo#s PC_s.
$ser experience +lthough there are "an! 0U3
alications, "ost of the #ork
is done through 'er"inal <a
console #indo#=, and if a
ro%le" arrises 0U3 is rarel!
usa%le to fix the".
E$er!thing can %e controlled
through 0U3 and
inco"ati%ilit! ro%le"s are
rare
\raphics perormance Because hard#are
"anufacturers, such as
N:idia, often does not ro$ide
docu"entation for linux
de$eloers, dri$ers can not use
full card erfor"ance.
Co"%ined #ith ne#est
(irectA $ersions and full
grahics card suort the
erfor"ance is al"ost as good
as it can get.
Company 7 developer Linus 'or$alds 4icrosoft
Introduction 4rom
Wi(ipediaA
Linux is a Unix9like and
P123A9co"liant co"uter
oerating s!ste" asse"%led
4icrosoft ;indo#s is a series
of grahical interface
oerating s!ste"s de$eloed,
under the "odel of free and
oen source soft#are
de$elo"ent and distri%ution.
'he defining co"onent of
Linux is the Linux kernel, an
oerating s!ste" kernel first
released
"arketed, and sold %!
4icrosoft. 4icrosoft
introduced an oerating
en$iron"ent na"ed ;indo#s
on No$e"%er 6L, 1)ON as a
grahical oerating s!ste"
shell for 429(12.
Supported platorms
+ll Po#erPC: $ersions 1.L 9 N'
K.L8 (EC +lha: $ersions 1.L 9
N' K.L8 43P2 RKLLL:
$ersions 1.L 9 N' K.L8 3+976:
$ersions 1.L 9 O8 3+9*K:
$ersion AP8 xO*9*K: $ersions
AP 9 O8 +R4: $ersion R'8
Source model 1en 2ource Closed @ 2hared source
9erminal 4ulti 'er"inal ;indo#s 99999999
Components of Linux System
Linux 1erating 2!ste" has ri"aril! three co"onents
=ernel 9 &ernel is the core art of Linux. 3t is resonsi%le for all "a/or acti$ities of this
oerating s!ste". 3t is consists of $arious "odules and it interacts directl! #ith the underl!ing
hard#are. &ernel ro$ides the reVuired a%straction to hide lo# le$el hard#are details to
s!ste" or alication rogra"s.
System Library 9 2!ste" li%raries are secial functions or rogra"s using #hich alication
rogra"s or s!ste" utilities accesses &ernel_s features. 'hese li%raries i"le"ents "ost of the
functionalities of the oerating s!ste" and do not reVuires kernel "odule_s code access rights.
System $tility 9 2!ste" Utilit! rogra"s are resonsi%le to do seciali.ed, indi$idual le$el
tasks.
Kernel Mode vs User Mode
&ernel co"onent code executes in a secial ri$ileged "ode called (ernel mode #ith full access to
all resources of the co"uter. 'his code reresents a single rocess, executes in single address sace
and do not reVuire an! context s#itch and hence is $er! efficient and fast. &ernel runs each rocesses
and ro$ides s!ste" ser$ices to rocesses, ro$ides rotected access to hard#areQs to rocesses.
2uort code #hich is not reVuired to run in kernel "ode is in 2!ste" Li%rar!. User rogra"s and
other s!ste" rogra"s #orks in $ser 5ode #hich has no access to s!ste" hard#ares and kernel
code. User rogra"s@ utilities use 2!ste" li%raries to access &ernel functions to get s!ste"_s lo# le$el
tasks.
Basic Features
-ollo#ing are so"e of the i"ortant features of Linux 1erating 2!ste".
Eortable 9 Porta%ilit! "eans soft#ares can #orks on different t!es of hard#ares in sa"e
#a!.Linux kernel and alication rogra"s suorts their installation on an! kind of hard#are
latfor".
"pen Source 9 Linux source code is freel! a$aila%le and it is co""unit! %ased de$elo"ent
ro/ect. 4ultile tea"Qs #orks in colla%oration to enhance the caa%ilit! of Linux oerating
s!ste" and it is continuousl! e$ol$ing.
5ulti3$ser 9 Linux is a "ultiuser s!ste" "eans "ultile users can access s!ste" resources
like "e"or!@ ra"@ alication rogra"s at sa"e ti"e.
5ultiprogramming 9 Linux is a "ultirogra""ing s!ste" "eans "ultile alications can
run at sa"e ti"e.
.ierarchical File System 9 Linux ro$ides a standard file structure in #hich s!ste" files@ user
files are arranged.
Shell 9 Linux ro$ides a secial interreter rogra" #hich can %e used to execute co""ands
of the oerating s!ste". 3t can %e used to do $arious t!es of oerations, call alication
rogra"s etc.
Security 9 Linux ro$ides user securit! using authentication features like ass#ord rotection@
controlled access to secific files@ encr!tion of data.
Architecture
Linux 2!ste" +rchitecture is consists of follo#ing la!ers
.ard)are layer 9 >ard#are consists of all eriheral de$ices <R+4@ >((@ CPU etc=.
=ernel 9 Core co"onent of 1erating 2!ste", interacts directl! #ith hard#are, ro$ides lo#
le$el ser$ices to uer la!er co"onents.
Shell 9 +n interface to kernel, hiding co"lexit! of kernel_s functions fro" users. 'akes
co""ands fro" user and executes kernel_s functions.
$tilities 9 Utilit! rogra"s gi$ing user "ost of the functionalities of an oerating s!ste"s.
What is inger?
finger co""and is used to looku infor"ation a%out an user.
Syntax
finger E9l"sF Euser1 user6 G.. F
/' [ie) detail about a particular user
finger co""and #ill disla! login, userna"e, ho"e director!, shell infor"ation a%out a articular
user as sho#n %elo#.
+ inger sathiya
Login: sathiya #ame: 4nullA
!irectory: 7home7sathiya Shell: 7bin7bash
"n since 5on #ov / /_:ND 4IS9A on :0 4messages oA
"n since 5on #ov / /_:N? 4IS9A on pts70 rom :0'0
#e) mail received Fri 5ay P /0:MM 10/0 4IS9A
$nread since Sat Cun P /1:DO 100_ 4IS9A
#o Elan'
1' [ie) login details and Idle status about an user
]ou can use finger 9s otion to $ie# the login detail for a articular user.
+ inger 3s root
Login #ame 9ty Idle Login 9ime "ice "ice Ehone
root root >/ /Od Wed /P:ND
root root >1 Md Fri /?:DM
root root >M 5on 10:10
root root >ta 1 9ue /D:NM
root root >tb 1 9ue /D:NN
Syntax and Options
Short
Option
Option Description
-s
!isplay the userRs login name< real name< terminal name and )rite status idle time<
login time< and either
oice location and oice phone number< or the remote host'
-p
Erevent the 3l option o inger rom displaying the contents o the 'or)ard< 'plan<
'proSect and 'pub(ey
iles'
-m
Erevent matching o user names' $ser is usually a login nameJ ho)ever< matching )ill
also be done on the usersR
real names< unless the 3m option is supplied'!isplay the userRs login name< real name<
terminal name and )rite
status idle time< login time< and either oice location and oice phone number< or the
remote host'
-o
When used in conSunction )ith the 3s option< the oice location and oice phone
inormation is displayed
instead o the name o the remote host'
S!O"S#S
$n%er |-lmsp | |user ... | |user@host ... |
1tions are:
&s
Fin%er dspays the user's ogn name, rea name, termna name and wrte status
(as a ``*'' after the termna name f wrte permsson s dened), de tme, ogn
tme, omce ocaton and omce phone number.
Login ti"e is disla!ed as "onth, da!, hours and "inutes, unless "ore than six "onths ago, in
#hich case the !ear is disla!ed rather than the hours and "inutes.
Unkno#n de$ices as #ell as nonexistent idle and login ti"es are disla!ed as single asterisks.
&l
Produces a mut-ne format dspayng a of the nformaton descrbed for the -s
opton as we as the user's home drectory, home phone number, ogn she, ma
status, and the contents of the es ``.pan '' ``.pro|ect '' ``.pgpkey '' and
``.forward '' from the user's home drectory.
Phone nu"%ers secified as ele$en digits are rinted as XXWN9NNN9NNN9NNNN__. Nu"%ers
secified as ten or se$en digits are rinted as the aroriate su%set of that string. Nu"%ers
secified as fi$e digits are rinted as XXxN9NNNN__. Nu"%ers secified as four digits are
rinted as XXxNNNN__.
3f #rite er"ission is denied to the de$ice, the hrase XX<"essages off=__ is aended to the line
containing the de$ice na"e. 1ne entr! er user is disla!ed #ith the 9l otion8 if a user is
logged on "ultile ti"es, ter"inal infor"ation is reeated once er login.
4ail status is sho#n as XXNo 4ail.__ if there is no "ail at all, XX4ail last read ((( 444 UU
>>:44 ]]]] <'f=__ if the erson has looked at their "ail%ox since ne# "ail arri$ing, or
XXNe# "ail recei$ed ...__, XX Unread since ...__ if the! ha$e ne# "ail.
&p
Prevents the -l opton of $n%er from dspayng the contents of the ``.pan ''
``.pro|ect '' and ``.pgpkey '' es.
&m
Prevent matchng of user names. User s usuay a ogn name; however, matchng
w aso be done on the users' rea names, uness the -m opton s supped. A
name matchng performed by $n%er s case nsenstve.
3f no otions are secified, inger defaults to the 9l st!le outut if oerands are ro$ided, other#ise to
the 9s st!le. Note that so"e fields "a! %e "issing, in either for"at, if infor"ation is not a$aila%le for
the".
3f no argu"ents are secified, inger #ill rint an entr! for each user currentl! logged into the s!ste".
Finger "a! %e used to look u users on a re"ote "achine. 'he for"at is to secif! a user as
XXuser`host __ or XX`host __ #here the default outut for"at for the for"er is the 9l st!le, and the
default outut for"at for the latter is the 9s st!le. 'he 9l otion is the onl! otion that "a! %e assed to
a re"ote "achine.
3f standard outut is a socket, inger #ill e"it a carriage return <b4= %efore e$er! linefeed <bJ=. 'his
is for rocessing re"ote finger reVuests #hen in$oked %! fingerd<O=.
'he Linux finger co""and disla!s infor"ation a%out the s!ste" users. ;e can $ie# all infor"ation
a%out user if #e kno# the user account login na"e. Belo# are so"e exa"les of the Linux finger
co""and #ith useful otions that !ou can use to $ie# user infor"ation.
'!e _inger_ at the co""and ro"t #ithout an! otion #ill gi$e an outut of users currentl! log in
the s!ste":
bill@slackware:~$ finger
Login Name Tty Idle Login Time Office Office Phone
bill billy adon tty! "#r !$ !%:%&
root tty' "#r !$ !(:%&
bill@slackware:~$
'he outut is the sa"e if #e issue Linux finger co""and #ith 3s otion, %ut this ti"e #e are looking
at a secific user:
bill@slackware:~$ finger )s bill
Login Name Tty Idle Login Time Office Office Phone
bill billy adon tty! "#r !$ !%:%&
bill@slackware:~$
'his is #hat each colu"n "eans:
'he colu"n Login is user_s login na"e.
'he colu"n Na"e is user_s full na"e.
'he colu"n 't! is ter"inal user_s login in.
'he colu"n 3dle sho#s idle ti"e.
'he colu"n Login 'i"e sho#s date and ti"e #hen user login in.
'he colu"n 1ffice sho#s user_s office location.
'he colu"n 1ffice Phone sho#s user_s office hone nu"%er.
No#, tr! Linux finger co""and #ith 9l otion:
bill@slackware:~$ finger )l bill
Login: bill Name: billy adon
*irectory: /home/bill +hell: /bin/bash
On since ,on "#r !$ !%:%& -,.T/ on tty!
No mail0
No Plan0
bill@slackware:~$
;hen Linux finger co""and is issued #ith 9l otion, it roduces a "ulti9line for"at disla!ing the
sa"e result as 9s #ith extra user_s ho"e director!, ho"e hone nu"%er, shell, "ail status, and the
contents of the files XX.lan__, XX.ro/ect__, XX.gke!__ and XX.for#ard__ fro" the user_s ho"e director!.
Re"e"%er that the Linux finger co""and also can %e a threat to the Linux s!ste" if not roerl!
secured. +ttacker can /ust guess a userna"e and #ith infor"ation gains fro" finger co""and, it /ust a
"atter of ti"e %efore !our s!ste" %eing co"ro"ised. 3f !ou can li$e #ithout the finger co""and,
/ust disa%le the dae"on.
n Linux oerating s!ste", !ou can si"l! check the infor"ation of an! user fro" re"ote or local
co""and line interface. 'hat is TfingerQ co""and. 'o use this co""and, !our Linux "achine need
ha$e TfingerQ utilit! installed on it. 'his feature is a $er! %asic #ith Linux s!ste", so !ou can easil!
find install ackage roer #ith !ou Linux s!ste". 'his article #ill focus on usage of TfingerQ
co""and and its otions #ith de"onstration co""and run on U%untu Linux.
2!ntax
finger E9l"sF Euser1 user6 G.. F
Fin%er command 'ith option &s
;ith otion Bs TfingerQ disla!s the userQs login na"e, real na"e, ter"inal na"e and #rite status < the
asterisk %efore ter"inal na"e "ean that !ou donQt ha$e #rite er"ission #ith that de$ice =, idle ti"e,
login ti"e, office location and office hone nu"%er. 'he login ti"e is disla!ed #ith for"at 44 ((
>>:"". 3f the ti"e exceeds six "onths, the !ear is disla!ed rather than the hours and "inutes.
Unkno#n de$ices as #ell as nonexistent idle and login ti"es are disla!ed as single asterisk.
Fin%er command 'ith option &l
'he otion Bl follo# the TfingerQ co""and #ith roduces a "ulti9line for"at disla!ing all of the
infor"ation descri%ed for the 9s otion as #ell as the userQs ho"e director!, ho"e hone nu"%er,
login shell, "ail status, and the contents of the files R.lanS, R.ro/ectS, R.gke!S and R.for#ardS fro"
the userQs ho"e director!.
'he hrase R<"essages off=S "ean that user Tharr!Q donQt ha$e #rite er"ission to TrootQ on the
de$ices ts@K and ts@M. 1ne entr! er user is disla!ed #ith the Bl otion8 if a user is logged on
"ultile ti"es, ter"inal infor"ation is reeated once er login.
4ail status is sho#n as RNo 4ail.S if there is no "ail at all, R4ail last read ((( 444 UU >>:44
]]]] <'f=S if the erson has looked at their "ail%ox since ne# "ail arri$ing, or RNe# "ail recei$ed
GS, RUnread since GS if the! ha$e ne# "ail.
Fin%er command 'ith option &p
'he otion B is co"letel! sa"e #ith otion Bl, excet it doesnQt includeR.lanS, R.ro/ectS and
R.gke!S files of users in returned result.
Fin%er command 'ith option &m
;ith the otion B" TfingerQ #ill re$ent "atching of user na"es in returned result. User is usuall! a
login na"e8 ho#e$er, "atching #ill also %e done on the usersQ real na"es, unless the 9" otion is
sulied. +ll na"e "atching erfor"ed %! finger is case insensiti$e. -or exa"le, our s!ste" has t#o
users na"ed Tharr!Q and Tharr!1Q. ;ithout otion B", TfingerQ #ill return infor"ation of %oth users
and onl! return infor"ation of user Tharr!Q if there B" follo#.
;ith otion T9"Q
;ithout otion T9"Q
3f no otions are secified, finger defaults to the 9l st!le outut if oerands are ro$ided, other#ise to
the 9s st!le. Note that so"e fields "a! %e "issing, in either for"at, if infor"ation is not a$aila%le for
the".
3f no argu"ents are secified, finger #ill rint an entr! for each user currentl! logged into the s!ste".
- See more at: http://noxde.com/nux-command/nger-command-user-
detas/#sthash.XsZAO2LU.dpuf
' (Unix)
The command ' on many Unx-ke operatng systems provdes a quck summary of
every user ogged nto a computer,
|1|
what that user s currenty dong, and what oad a
the actvty s mposng on the computer tsef. The command s a one-command
combnaton of severa other Unx programs: who, 1#time, and #s )a.
*xample
2a"le outut <this "a! $ar! %et#een s!ste"s=:
$ w
!!:!'am 1# 2$& day-s/3 !4:523 2 1sers3 load a6erage: $0%23 $0%23 $0%7
8ser tty login@ idle what
smith #ts/5 &:5'am w
onesm #ts/'% '$"#r$2 '& )bash
harry #ts/!& 4:$!am 4 #ine
#eterb #ts/!4 '!"#r$2 emacs )nw html/inde90html
anetmc: #ts/& !$:!'am %days )csh
singh #ts/!' !2"#r$2 5:'4 /1sr/bin/#erl )w #erl/test/#rogram0#l
'his co""and sho#s #ho is logged on and #hat the! are doing.
!escription:
# disla!s infor"ation a%out the users currentl! on the "achine, and their rocesses. 'he header
sho#s, in this order, the current ti"e, ho# long the s!ste" has %een running, ho# "an! users are
currentl! logged on, and the s!ste" load a$erages for the ast 1, N, and 1N "inutes.
'he follo#ing entries are disla!ed for each user: login na"e, the tt! na"e, the re"ote host, login
ti"e, idle ti"e, JCPU, PCPU, and the co""and line of their current rocess.
'he JCPU ti"e is the ti"e used %! all rocesses attached to the tt!. 3t does not include ast
%ackground /o%s, %ut does include currentl! running %ackground /o%s.
'he PCPU ti"e is the ti"e used %! the current rocess, na"ed in the R#hatS field.
Synopsis :
# 9Ehusif:F EuserF
"ptions:
3h
(onQt rint the header.
3u
3gnores the userna"e #hile figuring out the current rocess and cu ti"es. 'o de"onstrate this, do a
RsuS and do a R#S and a R# 9uS.
3s
Use the short for"at. (onQt rint the login ti"e,JCPU or PCPU ti"es.
3
'oggle rinting the fro" <re"ote hostna"e= field. 'he default as released is for the fro" field to not
%e rinted, although !our s!ste" ad"inistrator or distri%ution "aintainer "a! ha$e co"iled a
$ersion in #hich the fro" field is sho#n %! default.
3i
(isla! 3P address instead of hostna"e <if ossi%le=
3[
(isla! $ersion infor"ation.
user
2ho# infor"ation a%out the secified user onl!.
Exa"les :
$ w
$$:5&:!( 1# % min3 ' 1sers3 load a6erage: $0523 $0(!3 $0!&
8+;< TT. =<O, LO>IN@ I*L; ?@P8 P@P8 AB"T
1sername tty7 +1n$% '!:$4m (05(s $0'!s gnome)session )
1sername #ts/$ :$ +1n$% $0$$s $0'!s $0$$s w

$ w )s
!$:!2:$( 1# !% min3 ' 1sers3 load a6erage: $0$&3 $0!53 $0'$
8+;< TT. =<O, I*L; AB"T
mohakkat tty7 :$ !!:!5m gnome)session ))sessionC1b1nt1
mohakkat #ts/' :$ !!:!(m w )s

$ w )h
mohakkat tty7 :$ '%:$! !!:!5m %07&s $0!4s gnome)session )
mohakkat #ts/' :$ '%:$! !!:!(m $0$&s $0$$s w )h
A+out '
'he ) co""and is a Vuick #a! to see #ho is logged on and #hat the! are doing.
Syntax
w DoptionsE user D000E
Description
) disla!s infor"ation a%out the users currentl! on the "achine, and their rocesses.
'he header of the the outut sho#s <in this order=: the current ti"e, ho# long the s!ste" has %een
running, ho# "an! users are currentl! logged on, and the s!ste" load a$erages for the ast 1, N, and
1N "inutes.
'he follo#ing entries are disla!ed for each user: login na"e, the tt! na"e, the re"ote host the! are
logged in fro", the a"ount of ti"e the! ha$e %een logged in, their idle ti"e, JCPU, PCPU, and the
co""and line of their current rocess.
'he JCPU ti"e is the ti"e used %! all rocesses attached to the tt!. 3t does not include ast
%ackground /o%s, %ut does include currentl! running %ackground /o%s.
'he PCPU ti"e is the ti"e used %! the current rocess, na"ed in the ^#hat^ field.
Options
&h, &&no&
header
Don't prnt the header.
&u, &&no&
current
Ignores the username whe gurng out the current process and cpu tmes. (To
see an exampe of ths, swtch to the root user wth "su" and then run both "'"
and "' &u".)
&s,
&&short
Dspay abbrevated output (don't prnt the ogn tme, |CPU or PCPU tmes).
&f,
&&from
Togge prntng the from (remote hostname) ed. The defaut as reeased s for
the from ed to not be prnted, athough your system admnstrator or
dstrbuton mantaner may have comped a verson n whch the from ed s
shown by defaut.
&&help Dspay a hep message, and ext.
&,,
&&versio
n
Dspay verson nformaton, and ext.
&o,
&&old&
Od stye output (prnts bank space for de tmes ess than one mnute).
style
user Show nformaton about the speced user user ony.
*nvironment
"-OC"S.US*-
L*!
The vaue of ths envronment varabe, f set, w overrde the defaut
wdth (/) of the username coumn.
"-OC"S.F-O
ML*!
The vaue of ths envronment varabe, f set, w overrde the defaut
wdth (16) of the from coumn.
Files
0
var0run0ut
mp
Ths e stores the nformaton about who s
currenty ogged on.
0proc System process nformaton.
*xamples
w
Running the ) co""and #ith no argu"ents #ill sho# a list of logged on users and their rocesses.
w cho#e
2ho# infor"ation for the user na"ed chope.
+%out #ho
(isla!s #ho is logged on to the s!ste".
2!ntax
who D OPTION E000 D FILE E D am i E
(escrition
'he )ho co""and rints infor"ation a%out all users #ho are currentl! logged in.
1tions
&a, &&all Same as usng the optons &+ &d &&lo%in &p &r &t &1 &u.
&+,
&&+oot
Dspay the tme of the ast system boot.
&d,
&&dead
Dspay dead processes.
&2,
&&headin
%
Prnt a ne of coumn headngs.
&&ips
Prnt IP addresses nstead of hostnames. wth &&loo3up, canoncazes based on
stored IP, f avaabe, rather than stored hostname.
&l,
&&lo%in
Prnt system ogn processes.
&&loo3up Attempt to canoncaze hostnames va DNS.
&m
Ony prnt nformaton about the user and host assocated wth standard nput
(the termna where the command was ssued). Ths method adheres to the
POSIX standard.
&p,
&&proces
s
Prnt actve processes spawned by init.
&4,
&&count
Dspays a ogn names, and a count of a ogged-on users.
&r,
&&runlev
el
Prnt the current runeve.
&s,
&&short
Prnt ony name, ne, and tme eds. Ths s the defaut.
&t,
&&time
Prnt the ast tme the system cock was changed, f the nformaton s
avaabe.
&1, &',
&&mes%
Add a character whch ndcates the state of the termna ne: "5" f the
termna s wrtabe, "&" f t s not, or "6" f a bad ne s encountered.
&u,
&&users
Prnt the de tme for each user, and the process ID.
&&
messa%
e
Same as &1.
&&
'rita+le
Same as &1.
&&help Dspay a hep message, and ext.
&&
version
Dspay verson nformaton, and ext.
Linux / Unix Command: w
Command Library
!AM*
w - show who s ogged on and what they are dong
S!O"S#S
' & |&husf,| |user|
D*SC-#"1#O!
' dspays nformaton about the users currenty on the machne, and ther processes.
The header shows, n ths order, the current tme, how ong the system has been
runnng, how many users are currenty ogged on, and the system oad averages for the
past 1, 5, and 15 mnutes.
'he follo#ing entries are disla!ed for each user: login na"e, the tt! na"e, the re"ote host, login
ti"e, idle ti"e, JCPU, PCPU, and the co""and line of their current rocess.
'he JCPU ti"e is the ti"e used %! all rocesses attached to the tt!. 3t does not include ast
%ackground /o%s, %ut does include currentl! running %ackground /o%s.
'he PCPU ti"e is the ti"e used %! the current rocess, na"ed in the ^#hat^ field.

COMMA!D&L#!* O"1#O!S
&h
Don't prnt the header.
&u
Ignores the username whe gurng out the current process and cpu tmes. To
demonstrate ths, do a "su" and do a "w" and a "w -u".
&s
Use the short format. Don't prnt the ogn tme, |CPU or PCPU tmes.
&f
Togge prntng the from (remote hostname) ed. The defaut f for the from ed
to be prnted, athough your system admnstrator or dstrbuton mantaner may
have comped a verson n whch the from ed s not shown by defaut.
&,
Dspay verson nformaton.
user
Show nformaton about the speced user ony.
W."
+%out #ho
(isla!s #ho is logged on to the s!ste".
2!ntax
who D OPTION E000 D FILE E D am i E
(escrition
'he )ho co""and rints infor"ation a%out all users #ho are currentl! logged in.
1tions
&a, &&all Same as usng the optons &+ &d &&lo%in &p &r &t &1 &u.
&+,
&&+oot
Dspay the tme of the ast system boot.
&d,
&&dead
Dspay dead processes.
&2,
&&headin
%
Prnt a ne of coumn headngs.
&&ips
Prnt IP addresses nstead of hostnames. wth &&loo3up, canoncazes based on
stored IP, f avaabe, rather than stored hostname.
&l,
&&lo%in
Prnt system ogn processes.
&&loo3up Attempt to canoncaze hostnames va DNS.
&m
Ony prnt nformaton about the user and host assocated wth standard nput
(the termna where the command was ssued). Ths method adheres to the
POSIX standard.
&p,
&&proces
s
Prnt actve processes spawned by init.
&4,
&&count
Dspays a ogn names, and a count of a ogged-on users.
&r,
&&runlev
el
Prnt the current runeve.
&s,
&&short
Prnt ony name, ne, and tme eds. Ths s the defaut.
&t,
&&time
Prnt the ast tme the system cock was changed, f the nformaton s
avaabe.
&1, &',
&&mes%
Add a character whch ndcates the state of the termna ne: "5" f the
termna s wrtabe, "&" f t s not, or "6" f a bad ne s encountered.
&u,
&&users
Prnt the de tme for each user, and the process ID.
&&
messa%
e
Same as &1.
&&
'rita+le
Same as &1.
&&help Dspay a hep message, and ext.
&&
version
Dspay verson nformaton, and ext.
Notes
3f CII% is secified, )ho gathers its infor"ation fro" this file. 1ther#ise, it reads fro" a default file
location <usuall! 7var7run7utmp=.
3f the argu"ents ^am i^ are secified, )ho assu"es the 3m otion.
Exa"les
who
(isla!s the userna"e, line, and ti"e of all currentl! logged9in sessions. -or exa"le:
l1cy #ts/! '$!()$!)!7 '':(' -:$0$/
#smith #ts/' '$!()$!)!& $4:%$ -:$0$/
alan #ts/% '$!%)!')'5 $&:5' -:$0$/
neil #ts/( '$!()$!)$5 !5:%% -:$0$/
martha #ts/$ '$!%)$4)$( '':$5 -:$0$/
who am i
(isla!s the sa"e infor"ation, %ut onl! for the ter"inal session #here the co""and #as issued, for
exa"le:
alan #ts/% '$!%)!')'5 $&:5' -:$0$/
#ho 9a>
(isla!s ^all^ infor"ation, and headers a%o$e each colu"n of data, for exa"le:
N",; LIN; TI,; I*L; PI* @O,,;NT ;FIT
'$!()$!)!7 $7:$$ !5( idCsi termC$ e9itC$
system boot '$!()$!)!7 $7:$$
r1n)le6el ' '$!()$!)!7 $7:$$ lastC+
'$!()$!)!7 $7:$! !2$7 idCl' termC$ e9itC$
LO>IN tty2 '$!()$!)!7 $7:$! '&$4 idC2
LO>IN tty5 '$!()$!)!7 $7:$! '&$& idC5
LO>IN tty( '$!()$!)!7 $7:$! '&$7 idC(
LO>IN tty' '$!()$!)!7 $7:$! '&$5 idC'
LO>IN tty! '$!()$!)!7 $7:$! '&$( idC!
LO>IN tty% '$!()$!)!7 $7:$! '&$2 idC%
#ts/$ '$!()$!)!7 !!:%! '&!! idCts/$ termC$ e9itC$
l1cy G #ts/! '$!()$!)!7 '':(' 0 22$4 -:$0$/
#ts/' '$!()$!)!& $':!( $ idC/' termC$ e9itC$
#ts/% '$!()$!)!& $':$& $ idC/% termC$ e9itC$
#ts/( '$!()$!)!7 '!:%$ $ idC/( termC$ e9itC$
l1cy G #ts/$ '$!()$!)!7 '':$! $!:$( 2%%$ -:$0$/
As a Lnux user, sometmes t s requred to know some basc nformaton ke :
Tme of ast system boot
Lst of users ogged-n
Current run eve etc
Though ths type of nformaton can be obtaned from varous es n the Lnux system
but there s a command ne utty 'who' that does exacty the same for you. In ths
artce, we w dscuss the capabtes and features provded by the 'who' command.
The basc syntax of the who command s :
who DOPTIONE000 D =IL; H "<>! "<>' E

*xamples of 7'ho7 command

89 :et the information on currently lo%%ed in users
Ths s done by smpy runnng the 'who' command (wthout any optons). Consder the
foowng exampe:
$ who
himansh1 tty7 '$!')$&)$7 $5:%% -:$/
himansh1 #ts/$ '$!')$&)$7 $2:(7 -:$0$/
himansh1 #ts/! '$!')$&)$7 $7:5& -:$0$/

;9 :et the time of last system +oot
The s done usng the -b opton. Consder the foowng exampe:
$ who )b
system boot '$!')$&)$7 $5:%'
So we see that the above output gves the exact date and tme of ast system boot.

<9 :et information on system lo%in processes
Ths s done usng the - opton. Consder the foowng exampe:
$ who )l
LO>IN tty( '$!')$&)$7 $5:%' !%$4 idC(
LO>IN tty5 '$!')$&)$7 $5:%' !%!% idC5
LO>IN tty' '$!')$&)$7 $5:%' !%'' idC'
LO>IN tty% '$!')$&)$7 $5:%' !%'( idC%
LO>IN tty2 '$!')$&)$7 $5:%' !%'7 idC2
LO>IN tty! '$!')$&)$7 $5:%' !(4' idC!
So we see that nformaton reated to system ogn processes was dspayed n the
output.

=9 :et the hostname and user associated 'ith stdin
Ths s done usng the -m opton. Consder the foowng exampe:
$ who )m
himansh1 #ts/! '$!')$&)$7 $7:5& -:$0$/
So we see that the reevant nformaton was produced n the output.

>9 :et the current run level
Ths s done usng the -r opton. Consder the foowng exampe:
$ who )r
r1n)le6el ' '$!')$&)$7 $5:%'
So we see that the nformaton reated to current run eve (whch s 2) was produced n
the output.

?9 :et the list of user lo%%ed in
Ths s done usng the -u opton. Consder the foowng exampe:
$ who )1
himansh1 tty7 '$!')$&)$7 $5:%% old !2!4 -:$/
himansh1 #ts/$ '$!')$&)$7 $2:(7 $$:%! '%%2 -:$0$/
himansh1 #ts/! '$!')$&)$7 $7:5& 0 '%%2 -:$0$/
So we see that a st of ogged-n users was produced n the output.

@9 :et num+er of users lo%%ed&in and their user names
Ths s done usng the -q opton. Consder the foowng exampe:
$ who ):
himansh1 himansh1 himansh1
I 1sersC%
So we see that nformaton reated to number of ogged-n users and ther user names
was produced n the output.

/9 :et all the information
Ths s done usng the -a opton. Consder the foowng exampe:
$ who )a
system boot '$!')$&)$7 $5:%'
r1n)le6el ' '$!')$&)$7 $5:%'
LO>IN tty( '$!')$&)$7 $5:%' !%$4 idC(
LO>IN tty5 '$!')$&)$7 $5:%' !%!% idC5
LO>IN tty' '$!')$&)$7 $5:%' !%'' idC'
LO>IN tty% '$!')$&)$7 $5:%' !%'( idC%
LO>IN tty2 '$!')$&)$7 $5:%' !%'7 idC2
LO>IN tty! '$!')$&)$7 $5:%' !(4' idC!
himansh1 G tty7 '$!')$&)$7 $5:%% old !2!4 -:$/
himansh1 G #ts/$ '$!')$&)$7 $2:(7 0 '%%2 -:$0$/
himansh1 G #ts/! '$!')$&)$7 $7:5& 0 '%%2 -:$0$/
So we see that a the nformaton that 'who' can prnt s produced n output.
Linux 0 UnixA 'ho Command *xamples 1o List Users on
1he Systems
%! Nix Craft on Januar! 6M, 6L17 h L co""entsh L+2' UP(+'E( Januar! 6M, 6L1K
in Co""ands, Linux, UN3A
3 a" a ne# Linux and Unix s!ste" user. >o# do 3 disla! #ho is logged on "! Linux or Unix9like
oerating s!ste" using shell ro"tg
]ou need to use who co""and to disla! users #ho are currentl! logged in !our ser$er.
'ho command
details
Descrpton
Fnd who s on the
system
Category User Informaton
Dmcuty Easy
Root prveges No
Estmated competon
tme
5m
Contents
Syntax
Exampes
Show st of user ogged n
Fnd tme of ast boot
Lst dead processes
Lst ogn processes
Count a ogn names
Show current runeve
Show a nfo about ogged on users
Optons
Vdeo
See aso
Ths command s usefu to nd out the foowng nformaton:
1. Tme of ast system boot.
2. Current run eve.
3. Lst of ogged n users and more.
"urpose
!isplay )ho is on the system'
Syntax
'he %asic s!ntax is as follo#s:
who
who am i
who Do#tionsE D=ileE
who ))hel#
who ))6ersion
who H gre# J1serNameBereJ
;here,
If no non-optons provded, who dspays the foowng nformaton for each user
currenty ogged on:
o ogn name
o termna ne
o ogn tme
o remote hostname or X dspay
If you gve one non-opton argument, who uses that nstead of a defaut system-
mantaned e such s /var/run/utmp as the name of the e contanng the record
of users ogged on.
If gven two non-opton arguments, who prnts ony the entry for the user runnng
t preceded by the hostname. Tradtonay, the two arguments gven are 'am ', as
n 'who am '.
'ho command examples
'o sho# a list of all the users currentl! logged in to the s!ste", t!e:
$ who
2a"le oututs:
-ig. L1: 3dentif!ing #ho is logged on !our ser$er
The sampe output n ths exampe shows that the user vvek s ogged n on pts/0, and
has been on snce 14:10 on 27 |anuary. To dspay ne of coumn headngs pass the )B
opton:
$ who )B
To show ony hostname and user assocated wth stdn (usuay keyboard), enter:
$ who )m
To show actve processes spawned by nt:
$ who )#
To show user's message status as +, - or ?, enter:
$ who )T
Sho' or list users lo%%ed in
'!e the co""and:
$ who )1
Sho' time of last system +oot
'o disla! ti"e of last s!ste" %oot ass the )b otion to #ho co""and:
$ who )b
2a"le oututs:
system boot '$!()$!)$5 !$:$'
'he outut in this exa"le, sho#s that the s!ste" #as %ooted since 1L:L6 on LN Januar!.
Sho' dead processes on the system
]ou need ass the )d otion to #ho co""and:
$ who )d
1R
$ who )d )B
2a"le oututs:
N",; LIN; TI,; I*L; PI* @O,,;NT ;FIT
#ts/! '$!()$!)!! $4:!7 52$4( idCts/! termC$ e9itC$
#ts/' '$!()$!)$5 !5:(2 !!$7$ idCts/' termC$ e9itC$
#ts/' '$!()$!)$& $%:%! %2!( idC/' termC$ e9itC$
#ts/! '$!()$!)!! !2:5( 2(554 idC/! termC$ e9itC$
#ts/% '$!()$!)!! !7:!% !5&!& idC/% termC$ e9itC$
#ts/( '$!()$!)'5 !!:$' (2&$7 idCts/( termC$ e9itC$
Sho' system lo%in processes
'o /ust disla! s!ste" login rocesses ass the )l otion:
$ who )l
1R
$ who )l )B
2a"le oututs:
N",; LIN; TI,; I*L; PI* @O,,;NT
LO>IN tty' '$!()$!)$5 !$:$% &75$ idC'
LO>IN tty! '$!()$!)$5 !$:$% &7(& idC!
LO>IN tty% '$!()$!)$5 !$:$% &75' idC%
LO>IN /de6/tty+! '$!()$!)$5 !$:$% &7(7 idC6/tt
LO>IN tty( '$!()$!)$5 !$:$% &75( idC(
LO>IN tty5 '$!()$!)$5 !$:$% &752 idC5
LO>IN tty2 '$!()$!)$5 !$:$% &75& idC2
Count all lo%in names and num+er of users lo%%ed on the system
'o count all login na"es and nu"%er of users logged on:
$ who ):
2a"le oututs:
-ig.L6: (isla!ing and counting all users logged on
Display the current runlevel
'o disla! the current s!ste" runle$el, t!e:
$ who )r
2a"le oututs:
r1n)le6el % '$!()$!)$5 !$:$'
]ou can co"%ine )r and )b otions as follo#s:
$ who )r )b
2a"le oututs:
system boot '$!()$!)$5 !$:$'
r1n)le6el % '$!()$!)$5 !$:$'
Display all
'he )a is sa"e as sa"e as )bd#rtT1 otions as discussed earlier:
2a"le oututs:
N",; LIN; TI,; I*L; PI* @O,,;NT ;FIT
system boot '$!()$!)$5 !$:$'
r1n)le6el % '$!()$!)$5 !$:$'
LO>IN tty' '$!()$!)$5 !$:$% &75$ idC'
LO>IN tty! '$!()$!)$5 !$:$% &7(& idC!
LO>IN tty% '$!()$!)$5 !$:$% &75' idC%
LO>IN /de6/tty+! '$!()$!)$5 !$:$% &7(7 idC6/tt
LO>IN tty( '$!()$!)$5 !$:$% &75( idC(
LO>IN tty5 '$!()$!)$5 !$:$% &752 idC5
LO>IN tty2 '$!()$!)$5 !$:$% &75& idC2
root G #ts/$ '$!()$!)'7 $%:%7 0 !!!(4 -!$0!020!'$/
#ts/! '$!()$!)!! $4:!7 52$4( idCts/! termC$ e9itC$
#ts/' '$!()$!)$5 !5:(2 !!$7$ idCts/' termC$ e9itC$
#ts/' '$!()$!)$& $%:%! %2!( idC/' termC$ e9itC$
#ts/! '$!()$!)!! !2:5( 2(554 idC/! termC$ e9itC$
#ts/% '$!()$!)!! !7:!% !5&!& idC/% termC$ e9itC$
#ts/( '$!()$!)'5 !!:$' (2&$7 idCts/( termC$ e9itC$
'ho command options
Opto
n
Descrpton
-a
Same as -b -d --ogn -p -r -t -T -u
-b
Tme of ast system boot
-d
Prnt dead processes
-H
Prnt ne of coumn headngs
-l
Prnt system ogn processes
-m
Ony hostname and user assocated
wth stdn
-p
Prnt actve processes spawned by nt
-q
A ogn names and number of users
ogged on
-r
Prnt current runeve
-t
Prnt ast system cock change
-T
Add user's message status as +, - or ?
-u
Lst users ogged n
Linux )ho co""and sho#s #ho is logged on to the s!ste". 'his is a useful co""and for a Linux
s!ste" ad"inistrator %ecause the! can check ho# "an! users currentl! logged in the s!ste" and #ho
the! are. 'he Linux #ho co""and offers so"e otions that user can use to see "ore details a%out
users such as login ti"e, ter"inal used and rocess id. >o#e$er that is not the onl! things the #ho
co""and can do. ;e can also use Linux #ho co""and to check #hen #as the Linux s!ste" last
%ooted and the current s!ste"_s run le$el.
Linux 'ho command examples
;e alread! kno# #hat Linux #ho co""and can do, no# it_s ti"e to see so"e exa"les. Belo# are
the Linux #ho co""and exa"les run #ith otions regularl! used %! s!ste" ad"inistrator.
Pro%a%l! the #ell kno#n Linux #ho co""and_s otion is the am i. ;hen in$oke )ho am i fro" a
Linux co""and line ter"inal <and unix as #ell=, the who co""and rints onl! the infor"ation a%out
user #ho runs the co""and.
l1Kar@1b1nt1:~$ who am i
l1Kar #ts/$ '$$4)$7)$2 '':%4 -:$0$/
;hen #e run who #ith no otion in Linux co""and line ter"inal, #e_ll get the result si"ilar to the
exa"le %elo#:
l1Kar@1b1nt1:~$ who
root tty! '$$4)$7)$2 '':$2
l1Kar tty7 '$$4)$7)$2 !4:!7 -:$/
l1Kar #ts/$ '$$4)$7)$2 '!:'& -:$0$/
'he exa"le a%o$e sho#s t#o users logged in the Linux s!ste". ;e can see current users in the
s!ste"_s userna"e are root #ho logged in tt!1 and lu;ar #ho_s using ter"inal M <tt!M=, #hich #e
kno# it_s the x9#indo# s!ste". 'he other ter"inal is ts@L also %! a user na"ed lu.ar, #hich "eans
he oened a ter"inal fro" x9#indo#. ;e also see the co"lete date and ti"e the! logged into the
Linux s!ste" in tt!1, tt!M and e$en #hen the! oened a co""and line ter"inal fro" x9#indo#. 2o,
#hen #e in$oke Linux #ho co""and #ithout an! otion, it rints login na"e, ter"inal line, login
ti"e, and re"ote hostna"e or A disla! infor"ation.
Linux #ho 9l co""and exa"le:
l1Kar@1b1nt1:~$ who )l
LO>IN tty% '$$4)$7)$2 !4:!7 ((%4 idC%
LO>IN tty5 '$$4)$7)$2 !4:!7 ((%' idC5
LO>IN tty( '$$4)$7)$2 !4:!7 ((%! idC(
LO>IN tty2 '$$4)$7)$2 !4:!7 (((! idC2
LO>IN tty' '$$4)$7)$2 !4:!7 ((%& idC'
Linux #ho co""and rint s!ste" login rocesses. (on_t get confuse #ith this otion. ;hen running
who :l, _#ho_ list onl! the entries that corresond to rocesses $ia #hich the s!ste" is #aiting for a
user to login. 'he user na"e is al#a!s IOJI+.
Linux #ho 9" co""and exa"le:
l1Kar@1b1nt1:~$ who )m
l1Kar #ts/$ '$$4)$7)$2 '!:'& -:$0$/
'he Linux #ho 9" co""and rints onl! hostna"e and user associated #ith stdin. 3t the sa"e as
running who am i co""and.
Linux #ho 9V co""and exa"le:
l1Kar@1b1nt1:~$ who ):
root l1Kar l1Kar
I 1sersC%
'he Linux #ho 9V co""and rints all login na"es and the nu"%er of users logged on. Using 9V
otion #ill o$errides all other otions.
Linux #ho 9r co""and exa"le:
l1Kar@1b1nt1:~$ who )r
r1n)le6el ' '$$4)$7)$2 !4:!7 lastC
'he Linux #ho 9r co""and rints s!ste"_s current runle$el.
Linux #ho 9' co""and exa"le:
l1Kar@1b1nt1:~$ who )T
root ) tty! '$$4)$7)$2 '':$2
l1Kar G tty7 '$$4)$7)$2 !4:!7 -:$/
l1Kar G #ts/$ '$$4)$7)$2 '!:'& -:$0$/
+fter each login na"e, Linux #ho 9' co""and rints a character indicating the user_s "essage status,
#hich:
+ means aowng `wrte' messages.
- means dsaowng `wrte' messages.
? means cannot nd termna devce.
Linux #ho 9u co""and exa"le:
l1Kar@1b1nt1:~$ who )1
root tty! '$$4)$7)$2 '':$2 $$:$7 5(25
l1Kar tty7 '$$4)$7)$2 !4:!7 old 55$2 -:$/
l1Kar #ts/$ '$$4)$7)$2 '!:'& 0 25$4 -:$0$/
'he Linux #ho 9u co""and lists users logged in. +fter the login ti"e, the #ho co""and rints the
nu"%er of hours and "inutes that the user has %een idle.
9 means the user was actve n the ast mnute.
old means the user has been de for more than 24 hours.
Linux #ho 9% co""and exa"le:
l1Kar@1b1nt1:~$ who )b
system boot '$$4)$7)$2 !4:!7
'he Linux #ho 9% co""and rints the date and ti"e of last s!ste" %oot.
Linux #ho 9a co""and exa"le:
l1Kar@1b1nt1:~$ who )a
system boot '$$4)$7)$2 !4:!7
r1n)le6el ' '$$4)$7)$2 !4:!7 lastC
LO>IN tty% '$$4)$7)$2 !4:!7 ((%4 idC%
LO>IN tty5 '$$4)$7)$2 !4:!7 ((%' idC5
LO>IN tty( '$$4)$7)$2 !4:!7 ((%! idC(
LO>IN tty2 '$$4)$7)$2 !4:!7 (((! idC2
LO>IN tty' '$$4)$7)$2 !4:!7 ((%& idC'
root ) tty! '$$4)$7)$2 '':$2 $$:%' 5(25
l1Kar G tty7 '$$4)$7)$2 !4:!7 old 55$2 -:$/
l1Kar G #ts/$ '$$4)$7)$2 '':%4 0 24%& -:$0$/
'he Linux #ho 9a co""and is the sa"e as in$oke )ho 3b 3d 33login 3p 3r 3t 39 3u.
Linux / Unix Command: who
Command Library
!AM*
who - show who s ogged on
S!O"S#S
'ho |OPTION|... | FILE | ARG1 ARG2 |
D*SC-#"1#O!
&a, &&all
same as &+ &d &&lo%in &p &r &t &1 &u
&+, &&+oot
tme of ast system boot
&d, &&dead
prnt dead processes
&2, &&headin%
prnt ne of coumn headngs
&i, &&idle
add de tme as HOURS:MINUTES, . or od (deprecated, use &u)
&&lo%in
prnt system ogn processes (equvaent to SUS &l)
&l, &&loo3up
attempt to canoncaze hostnames va DNS (- s deprecated, use &&loo3up)
&m
ony hostname and user assocated wth stdn
&p, &&process
prnt actve processes spawned by nt
&4, &&count
a ogn names and number of users ogged on
&r, &&runlevel
prnt current runeve
&s, &&short
prnt ony name, ne, and tme (defaut)
&t, &&time
prnt ast system cock change
&1, &', &&mes%
add user's message status as +, - or ?
&u, &&users
st users ogged n
&&messa%e
same as &1
&&'rita+le
same as &1
&&help
dspay ths hep and ext
&&version
output verson nformaton and ext
3f -3LE is not secified, use @$ar@run@ut". @$ar@log@#t" as -3LE is co""on. 3f +R01 +R06 gi$en,
3m resu"ed: Xa" i_ or X"o" likes_ are usual.
1he 'hatis Command
'he whatis co""and ro$ides $er! %rief descritions of command line
programs <i.e., all9text "ode rogra"s= and other toics related to Linux and
other Unix9like oerating s!ste"s.
3t acco"lishes this %! searching the short descritions in the whatis
data/ase for each ke!#ord ro$ided to it as an argu"ent <i.e., inut data=.
'his data%ase contains /ust the title, section nu"%er and descrition fro" the
N+4E section of each age in the man "anual that is %uilt into "ost Unix9
like s!ste"s.
'he s!ntax for #hatis is:
whatis keyword-s/
-or exa"le, the follo#ing ro$ides a single line su""ar! of the head
co""and <#hich %! default disla!s the first ten lines of each file that is
ro$ided to it as an argu"ent=:
whatis head
#hatis can %e used to si"ultaneousl! search for infor"ation a%out "ultile
toics. -or exa"le, the follo#ing #ould ro$ide infor"ation a%out %oth
head and tail <#hich %! default reads the final ten lines of files=:
whatis head tail
'he outut of #hatis is li"ited %! the fact that it ro$ides onl! a single line
for each ke!#ord found in the data%ase8 thus it sulies inco"lete
infor"ation a%out e$en "oderatel! co"lex co""ands. -or exa"le, the
follo#ing use of #hatis to o%tain infor"ation a%out the cat co""and
generates the outut ^concatenate files and rint on the standard outut^:
whatis cat
>o#e$er, this o"its so"e i"ortant infor"ation a%out cat, articularl! the
facts that it is $er! con$enient to use for reading files and that it is also used
to create and #rite to files.
#hatis is si"ilar to the apropos co""and. >o#e$er, aroos is "ore
o#erful in that its argu"ents are not li"ited to co"lete #ords %ut can also
%e strings <i.e., an! finite seVuences of characters= #hich co"rise arts of
#ords. Both co""ands are unusual in that the! ha$e no otions.
'he man co""and <#hich is used to read the %uilt9in "anual ages=, #hen
used #ith its :f otion, roduces the sa"e outut as #hatis. 'hus, for
exa"le,
man )f cat
is eVui$alent to
whatis cat
'he whatis data/ase is a plain te6t <i.e., hu"an9reada%le characters= file that
is generated auto"aticall! %! the ma(ewhatis rogra". 3ts location $aries
according to the articular s!ste"8 in the case of Red >at Linux ), for
exa"le, its full ath is @$ar@cache@"an@#hatis.
3f desired, the data%ase can %e $ie#ed using a co""and such as the
follo#ing:
cat /6ar/cache/man/whatis H less
3n this co""and the outut of cat "ar"cache"man"whatis is piped <i.e., sent=
to the less co""and in order to "ake it easier to read %! disla!ing onl! a
single age at a ti"e rather than scrolling do#n the screen at high seed.
A+out 'hatis
)hatis disla!s short "anual age descritions.
Syntax
whatis D)dlh6LE D)rH)wE D)s listE D)m systemD3000EE D), pathE D)L localeE
D)@ fileE name 000
Each "anual age has a short descrition a$aila%le #ithin it. )hatis searches the "anual age na"es
and disla!s the "anual age descritions of an! na"e "atched.
name "a! contain #ildcards <3)= or %e a regular exression <3r=. Using these otions, it "a! %e
necessar! to Vuote the na"e or escae <^= the secial characters to sto the shell fro" interreting
the".
index data%ases are used during the search, and are udated %! the "and% rogra". (eending on
!our installation, this "a! %e run %! a eriodic cron /o%, or "a! need to %e run "anuall! after ne#
"anual ages ha$e %een installed. 'o roduce an old st!le text #hatis data%ase fro" the relati$e index
data%ase, issue the co""and:
whatis ), manpath )w JMJ H sort N man#ath/whatis
#here manpath is a "anual age hierarch! such as 7usr7man.
Options
&d, &&de+u% Prnt debuggng nformaton.
&v, &&ver+ose Prnt verbose warnng messages.
&r, &&re%ex
Interpret each name as a reguar expresson. If a name matches any
part of a page name, a match w be made. Ths opton causes
whats to be somewhat sower due to the nature of database
searches.
&', &&'ildcard
Interpret each name as a pattern contanng she stye wdcards. For
a match to be made, an expanded name must match the entre page
name. Ths opton causes whats to be somewhat sower due to the
nature of database searches.
&l, &&lon% Do not trm output to the termna wdth. Normay, output w be
truncated to the termna wdth to avod ugy resuts from poory-
wrtten NAME sectons.
&s list, &&sections
list, &&section list
Search ony the gven manua sectons. list s a coon- or comma-
separated st of sectons. If an entry n list s a smpe secton, for
exampe "<", then the dspayed st of descrptons w ncude pages
n sectons "<", "<perl", "<x", and so on; whe f an entry n list has
an extenson, for exampe "<perl", then the st w ony ncude
pages n that exact part of the manua secton.
&m system|B...|,
&&systemsCsyste
m|B...|
If ths system has access to other operatng system's manua page
names, they can be accessed usng ths opton. To search NewOS's
manua page names, use the opton "&m !e'OS".
The system speced can be a combnaton of comma demted
operatng system names. To ncude a search of the natve operatng
system's manua page names, ncude the system name man n the
argument strng. Ths opton w overrde the DSS1*M envronment
varabe.
&M ath,
&&manpathCath
Specfy an aternate set of coon-demted manua page herarches
to search. By defaut, 'hatis uses the DMA!"A12 envronment
varabe, uness t s empty or unset, n whch case t w determne
an approprate manpath based on your D"A12 envronment varabe.
Ths opton overrdes the contents of DMA!"A12.
&L lo!ale,
&&localeClo!ale
whats w normay determne your current ocae by a ca to the C
functon setlocale whch nterrogates varous envronment varabes,
possby ncudng DLC.M*SSA:*S and DLA!:. To temporary
overrde the determned vaue, use ths opton to suppy a ocae
strng drecty to whats. Note that t w not take ehect unt the
search for pages actuay begns. Output such as the hep message
w aways be dspayed n the ntay determned ocae.
&C "le, &&con$%&
$leC"le
Use ths user conguraton e rather than the defaut of
E09manpath.
&h, &&help Prnt a hep message and ext.
&,, &&version Dspay verson nformaton.
*xit StatusA
F Successfu program executon.
8 Usage, syntax or conguraton e error.
; Operatona error.
8
?
Nothng was found that matched the crtera
speced.
*nvironment
SS1*M
If DSS1*M s set, t w have the same ehect as f t had been speced as
the argument to the &m opton.
MA!"A1
2
If DMA!"A12 s set, ts vaue s nterpreted as the coon-demted manua
page herarchy search path to use.
MA!G#D
12
If DMA!G#D12 s set, ts vaue s used as the termna wdth (see the &&lon%
opton). If t s not set, the termna wdth w be cacuated usng an ioctl f
avaabe, the vaue of DCOLUM!S, or fang back to 80 characters f a ese
fas.
*xamples
whatis whatis
#9 Linux 'hatis Command
;hatis co""and is helful to get %rief infor"ation a%out Linux co""ands or functions. ;hatis
co""and disla!s "an age single line descrition for co""and that "atches string assed as a
co""and line argu"ent to #hatis co""and. ;hatis co""and searches for string in its index
data%ases #hich is "aintained %! "and% rogra". ;hatis co""and icks short descrition of N+4E
section of "an age of co""and that "atches to inut gi$en to the #hatis co""and.
;hatis ro$ides se$eral co""and line otions to hel user in getting %rief infor"ation of secific
Linux co""ands as er their need or interest.
2!ntax:
$ whatis D)o#tionsE
-or exa"le, here is the outut of #hatis co""and, #hen it is run #ithout an! otion.
$ whatis write
write -!/ ) send a message to another 1ser
write -'/ ) write to a file descri#tor
3t disla!s %rief infor"ation a%out R#riteS fro" "an ages.
/' \et inormation rom speciic sections o man pages using 3s option
3f #e #ant to get Linux co""and infor"ation fro" secific section of "an ages, then #e can
ro$ide sections list using R9s or csections or BsectionS otion. 3t #ill restrict #hatis co""and to
disla! %rief infor"ation fro" secified "an age section onl!.
$ whatis )s O!O3O'O o#en
o#en -!/ ) start a #rogram on a new 6irt1al terminal -LT/0
o#en -'/ ) o#en and #ossibly create a file or de6ice
3t disla!s oen co""and and function %rief infor"ation fro" "an age sections 1 and 6.
$ whatis )s O'O o#en
o#en -'/ ) o#en and #ossibly create a file or de6ice
3t disla!s oen function %rief infor"ation fro" "an age section 6.
1' Search inormation through )ild3cards using 3) option
3f #e #ant to search Linux co""ands or functions infor"ation using #ild card, then #hatis co""and
gi$es R9# or B#ildcardS otion. 3t #ill "ake !our search secific as er userQs need.
$ whatis )w JabMJ
abort -%/ ) ca1se abnormal #rocess termination
abs -%/ ) com#1te the absol1te 6al1e of an integer
3t disla!s %rief infor"ation of Linux co""ands or functions #hich start fro" Ra%S.
$ whatis )w JabPJ
abs -%/ ) com#1te the absol1te 6al1e of an integer
3t disla!s %rief infor"ation of Linux co""ands or functions #hich start fro" Ra%S and follo#ed %!
an! single character.
M' Search inormation through regular expressions using 3r option
3f #e #ant to search Linux co""ands or functions infor"ation using regular exressions, then #hatis
co""and gi$es R9r or BregexS otion. 3t #ill gi$e flexi%ilit! to custo"i.e !our search for Linux
co""ands or functions throughout the Linux s!ste".
$ whatis )r JQabJ
abort -%/ ) ca1se abnormal #rocess termination
abs -%/ ) com#1te the absol1te 6al1e of an integer
3t disla!s %rief infor"ation of Linux co""ands or functions #hich start fro" Ra%S.
$ whatis )r Jab$J
anacrontab -5/ ) config1ration file for anacron
baobab -!/ ) " gra#hical tool to analyse disk 1sage
crontab -!/ ) maintain crontab files for indi6id1al 1sers -Li9ie @ron/
crontab -5/ ) tables for dri6ing cron
fstab -5/ ) static information abo1t the filesystems
inittab -5/ ) init daemon config1ration
swab -%/ ) swa# adacent bytes
tc)stab -&/ ) >eneric siKe table mani#1lations
3t disla!s %rief infor"ation of Linux co""ands or functions #hich ends #ith Ra%S.
N' !isable trimmed output using 3l option
0enerall! #hatis co""and tri"s long outut of Linux co""ands or functions infor"ation to a$oid
RNot goodS outut disla! on ter"inal that is going %e!ond screen. 'o allo# #hatis co""and to sho#
co"lete outut on screen, R9l or BlongS otion can %e used.
$ whatis ssh)im#ort)id
ssh)im#ort)id -!/ ) retrie6e one or more #1blic keys from a #1blic keyser6er
-La1nch#ad0net by defa1lt/ and a##end them to the c1rrent 1serJs a1thoriKedRkeys
file -or some other s#ecifie000
3t disla!s tri""ed outut of %rief infor"ation of Linux co""and.
$ whatis )l ssh)im#ort)id
ssh)im#ort)id -!/ ) retrie6e one or more #1blic keys from a #1blic keyser6er
-La1nch#ad0net by defa1lt/ and a##end them to the c1rrent 1serJs a1thoriKedRkeys
file -or some other s#ecified file/
3t disla!s co"lete outut of %rief infor"ation of Linux co""and.
D' 8estrict search up to speciied path using 35 option
B! default, #hatis co""and uses J4+NP+'> en$iron"ent $aria%le. But #hatis ro$ides R94 or B
"anathS otion to restrict search u to secified ath of "an ages.
$ whatis ), /1sr/share/man he9d1m#
he9d1m# -!/ ) "+@II3 decimal3 he9adecimal3 octal d1m#
3t disla!s %rief infor"ation of Linux hexdu" co""and fro" "an ages a$aila%le at ath
@usr@share@"an.
$ whatis ), /1sr/man he9d1m#
he9d1m#: nothing a##ro#riate0
3t could not find %rief infor"ation of Linux hexdu" co""and fro" secified ath @usr@"an.
II' Linux )hereis Command
;hereis co""and is helful to locate %inar!, source and "anual ages of co""ands in the Linux
s!ste". 3t is $er! si"le utilit! and ro$ides se$eral otions #hich are gi$en %elo# #ith exa"les.
2!ntax:
$ whereis D)o#tionsE
-or exa"le, #hereis co""and is run #ithout an! otion.
$ whereis o#en
o#en: /bin/o#en /1sr/share/man/man!/o#en0!0gK /1sr/share/man/man'/o#en0'0gK
3t locates %inar!, source and "an ages of RoenS co""and and here it disla!ed aths #here %inar!,
"an ages of oen co""and is a$aila%le in the s!ste".
?' Locate binaries using 3b option
3f #e #ant to locate %inar! of Linux co""and, use R9%S otion.
$ whereis )b whereis
whereis: /1sr/bin/whereis /1sr/bin/F!!/whereis
3t locates %inar! of R#hereisS co""and and disla!s aths #here %inar! of co""and is a$aila%le in
the s!ste".
P' Locate man pages or a command using 3m option
3f #e #ant to locate "an age of Linux co""and, use R9"S otion.
$ whereis )m whereis
whereis: /1sr/share/man/man!/whereis0!0gK
3t locates "an age of R#hereisS co""and and disla!s ath #here "an age of co""and is
a$aila%le in the s!ste".
_' Locate source o a command using 3s option
3f #e #ant to locate source of Linux co""and, use R9sS otion.
$ whereis )s whereis
whereis:
3t locates source of R#hereisS co""and, %ut source of R#hereisS co""and does not exist in the
s!ste", so it did not disla! ath for source of co""and in the s!ste".
O' Locate unusual entries using 3u option
'his otion is so"ething different that searches for unusual entries. 'hese entries are those co""and
#hose source, %inar! or "an age does not exist in the s!ste" as er otions RE9%"sFS secified along
#ith RBuS.
$ whereis )m )1 wcgre#
wcgre#:
3t checks if secified co""and <i.e. #cgre= "an age does not exist in the s!ste". ;hereis
co""and #ith otions R9" and 9uS locates for the co""ands in the s!ste" #hose "an age does not
exist.
$ whereis )m )1 gre#
$
>ere, #hereis co""and #ith sa"e otions is alied on RgreS co""and #hose "an age exists in
the s!ste", so #hereis returned nothing and exits nor"all!.
/0' Locate binaries in a speciied path using 3H option
3f user #ants to search for %inar! and #ants to li"it the scoe of search for #hereis co""and u to
secified ath, then use R9BS otion.
$ whereis )S /bin )f forRloo#
forRloo#: /bin/forRloo#
3t locates %inar! of Rfor?looS user rogra" fro" ath R@%inS.
$ whereis )S /1sr )f o#en
o#en: /1sr/share/man/man!/o#en0!0gK /1sr/share/man/man'/o#en0'0gK
3f oen co""andQs %inar! is not found at secified ath, then it is not sho#n %ut #hereis co""and %!
default searches for other t!es <i.e. "an age and source= of secified co""and <i.e. oen= and
disla!s the" if found.
//' Locate man pages )ith limited scope using 35 option
3f user #ants to search for "an ages and #ants to li"it the scoe of search for #hereis co""and u
to secified ath, then use R94S otion.
$ whereis ), /1sr/share/man/man! )f o#en
o#en: /bin/o#en /1sr/share/man/man!/o#en0!0gK
$ whereis ), /1sr/share/man/man' )f o#en
o#en: /bin/o#en /1sr/share/man/man'/o#en0'0gK
$ whereis ), /1sr/share/man/man% )f o#en
o#en: /bin/o#en
>ere, it is o%ser$ed that #hereis co""and is disla!ing "an age of RoenS co""and #hich is
a$aila%le in secified ath onl!. But, #hereis co""and %! default searches for other t!es <i.e. %inar!
and source= of secified co""and <i.e. oen= and disla!s the" if found.
III' Linux )hich Command
;hich co""and is $er! s"all and si"le co""and to locate executa%les in the s!ste". 3t allo#s user
to ass se$eral co""and na"es as argu"ents to get their aths in the s!ste". R#hichS co""ands
searches the ath of executa%le in s!ste" aths set in JP+'> en$iron"ent $aria%le.
2!ntax:
$ which D)o#tionE
-or exa"le,
$ which ls gdb o#en gre#
/bin/ls
/1sr/bin/gdb
/bin/o#en
/bin/gre#
3t locates co""and na"es B RlsS, Rgd%S, RoenS and RgreS secified as argu"ents to R#hichS
co""and and disla!s aths of each executa%le #here it exists in the s!ste".
/1' !isplay all the paths using 3a option
R#hichS co""and gi$es otion R9aS that disla!s all aths of executa%le "atching to argu"ent.
$ which echo
/1sr/sbin/echo
+%o$e #ill search disla! the executa%le RechoS fro" all aths set in JP+'> en$iron"ent $aria%le
and disla!s the first ath #here echo executa%le is found. 3t "a! %e case that executa%le is laced at
other aths of JP+'> en$iron"ent $aria%le as #ell. 'o get all aths #here executa%le is resent in the
s!ste", R9aS otion can %e used.
$ which )a echo
/1sr/sbin/echo
/bin/echo
D
!AM*
whats - search the whats database for compete words.
S!O"S#S
'hatis keyword ...
D*SC-#"1#O!
whats searches a set of database es contanng short descrptons of system
commands for keywords and dspays the resut on the standard output. Ony compete
word matches are dspayed.
'he #hatis data%ase is created using the co""and @usr@s%in@"ake#hatis.
'hatis
)hatis disla!s short "an age descritions. Unlike
%6amples5
$ whatis info
info -!/ ) read Info doc1ments
info -5/ ) readable online doc1mentation
$ whatis chmod
chmod -!/ ) change file modes
chmod3 fchmod -'/ ) change mode of file
Ghat is 'hereis 6
;hereis co""and is used to find out #here the %inar!, source, and "an age files for a co""and is
located.
7 #hereis Exa"les
Find 'hereis a U!#H command
;hen !ou #ant to find out #here a secific Unix co""and exists <for exa"le, #here does ls
co""and existsg=, !ou can execute the follo#ing co""and.
$ whereis ls
ls: /bin/ls /1sr/share/man/man!/ls0!0gK /1sr/share/man/man!#/ls0!#0gK
Find 'hereis a U!#H command executa+le is located
;hen !ou #ant to kno# onl! #here the executa%le for a secific co""and is a$aila%le, use 9% otion.
'his is "ore hand!, and !ou are "ost likel! %e using #hereis co""and to find out the location of
onl! executa%les.
$ whereis )b ls
ls: /bin/ls
Chan%e the search location of 'hereis command
;hen !ou #ant to search an executa%le fro" a ath other than the #hereis default ath, !ou can use
9B otion and gi$e ath as argu"ent to it.
$ whereis )1 )S /tm# )f lsmk
lsmk: /tm#/lsmk
'his searches for the executa%le ls"k in the @t" director!, and disla!s it, if it is a$aila%le.
Syntax and Options
Short
Optio
n
Option Description
-b Search ony for bnares
-m Search ony for manua sectons
-s Search ony for sources
-u
Search for unusua entres. A e s sad to be unusua f t does not have one entry
of each requested type. Thus wheres -m -u asks for those es n the current
drectory whch have no documentaton
-B Change or otherwse mt the paces where wheres searches for bnares
-M Change or otherwse mt the paces where wheres searches for manua sectons
-S Change or otherwse mt the paces where wheres searches for sources
-f
Termnate the ast drectory st and sgnas the start of e names, and must be
used when any of the -B, -M, or -S optons are used
A+out 'hereis
Locates the %inar!, source, and "anual age files for a co""and.
Syntax
whereis D)bms1E D)S,+ directory000 )fE filename000
Description
)hereis locates source@%inar! and "anuals sections for secified files. 'he sulied na"es are
first stried of leading athna"e co"onents and an! <single= trailing extension of the for"
^'ext^, for exa"le, ^'c^. Prefixes of ^s'^ resulting fro" use of source code control are also
handled. )hereis then atte"ts to locate the desired rogra" in a list of standard Linux laces.
Options
&+Search ony for bnares.
&
m
Search ony for manua sectons.
&s Search ony for sources.
&u
Search for unusua entres. A e s sad to be unusua f t does not have one
entry of each requested type. For exampe, "'hereis &m &u I" asks for those
es n the current drectory whch have no documentaton.
&BChange or otherwse mt the paces where 'hereis searches for bnares.
&
M
Change or otherwse mt the paces where wheres searches for manua
sectons.
&SChange or otherwse mt the paces where wheres searches for sources.
&f
Termnate the ast drectory st and sgnas the start of e names, and must be
used when any of the &B, &M, or &S optons are used.
*xamples
whereis #erl
List the directories #here the perl source files, docu"entation, and %inaries are stored.
whereis )1 ), /1sr/man/man! )+ /1sr/src )f M
-ind all files in the current director! #hich are not docu"ented in 7usr7man7man/, #hose
source resides in 7usr7src.
a" a ne# Linux and Unix9like s!ste" co""and line user. >o# do 3 find and locate the %inar!,
source, and "anual age files for a gi$en co""andg
]ou need to use the whereisco""and to find the source, %inar!, and "anuals sections for
secified co""ands or files.
'hereis command
details
Descrpton
Locatng command or
program
Category Searchng
Dmcuty Easy
Root prveges No
Estmated competon 10m
tme
Contents
Syntax
Exampes
Search ony for bnares
Search ony for manua sectons
Search ony for sources
Searches for unusua es
Lmt the searches for bnares to specc
drectores
Optons
See aso
A bnary s nothng but an executabe from of a command such as s or program
such as Gmp. Use ths command to nd out:
1. The ocaton of a bnary e.
2. The ocaton of source code.
3. The ocaton of man page.
"urpose
-ind the binary< source code and man page for secified rogra" or co""and.
Syntax
'he %asic s!ntax is as follo#s:
whereis command
1R
whereis #rogram
1R
whereis Do#tionsE #rogram
1R
whereis )S,+ directory )f command
'hereis command examples
'o find out the location of the executa%le, source code and "an age for the date co""and,
t!e:
$ whereis date
2a"le oututs:
+ni"ated gif L1: #hereis co""and running on "! (e%ian %ased ser$er
2o' do # only search for +inary $les6
Pass the )b otion as follo#s:
$ whereis )b date
2o' do # only search for manual sections $les6
Pass the )m otion as follo#s:
$ whereis )m date
2o' do # only search for source code $les6
Pass the )s otion as follo#s:
$ whereis )s date
2o' do # only Search for unusual entries6
+ file is said to %e unusual if it does not ha$e one entr! of each reVuested t!e. 'hus the
follo#ing exa"le, asks for those files in the current director! #hich ha$e no docu"entation:
$ whereis )m )1 M
2o' can # limit the searches for +inaries to speci$c directories6
]ou can ass the follo#ing otion to li"it li"it the laces #here #hereis searches for files:
-B /path/to/dir : Lmt the paces where wheres searches for bnares.
-M /path/to/dir : Lmt the paces where wheres searches for manua
sectons.
-S /path/to/dir : Lmt the paces where wheres searches for sources.
]ou "ust ass the )f otion #hen an! of the 9B, 94, or 92 otions are used. 'he )f otion
ter"inate the last director! list and signals the start of file na"es. 3n this exa"le, li"it search
for %inar! files in @%in@ director! onl! for ls and gcc co""ands:
$ whereis )S /bin )f ls gcc
2a"le oututs:
ls: /bin/ls /1sr/share/man/man!/ls0!0gK
gcc:
'here is no outut for the gcc co""and since it is located in @usr@%in@ director!. 'o find all of
the files in the @s%in@ director! that either are not docu"ented in the @usr@"an@"anO director! or
do not ha$e source in the @root@src director!, enter:
I cd /sbin
I whereis )1 ), /1sr/man/man&/ )+ /root/src/ )f M
'hereis command options
-ro" the #hereis<1= co""and "an age:
Optio
n
Meanin%
-f
Dene search scope.
-b
Search ony bnares.
-B
Dene bnares ookup path.
-m
Search ony manua paths.
-M
Dene man ookup path.
-s
Search ony sources path.
-S
Dene sources ookup path.
-u
Search from unusua entes.
-V
Output verson nformaton
and ext.
-h
Dspay ths hep and ext.
See also
wheres(1) Lnux/Unx command man page
!AM*
wheres - ocate the bnary, source, and manua page es for a command
S!O"S#S
'hereis | &+msu | | &BMS #ire!tory... &f | "lename ...
D*SC-#"1#O!
'hereis ocates source/bnary and manuas sectons for speced es. The
supped names are rst strpped of eadng pathname components and any
(snge) trang extenson of the form 9e$t% for exampe, 9c. Prexes of s9 resutng
from use of source code contro are aso deat wth. 'hereis then attempts to
ocate the desred program n a st of standard Lnux paces.
O"1#O!S
&+
Search only for +inaries9
&m
Search ony for manua sectons.
&s
Search ony for sources.
&u
Search for unusua entres. A e s sad to be unusua f t does not have one
entry of each requested type. Thus `'hereis &m &u I' asks for those es
n the current drectory whch have no documentaton.
&B
Change or otherwse mt the paces where 'hereis searches for bnares.
&M
Change or otherwse mt the paces where 'hereis searches for manua
sectons.
&S
Change or otherwse mt the paces where 'hereis searches for sources.
&f
Termnate the ast drectory st and sgnas the start of e names, and must
be used when any of the &B, &M, or &S optons are used.

*HAM"L*
ind all files in 7usr7bin #hich are not docu"ented in 7usr7man7man/ #ith source in 7usr7src:
example% cd /usr/bin
example% whereis -u -M /usr/man/man1 -S /usr/src -f
'he whereis co""and is used to locate the /inary, the source code and the online manual page
for an! secified rogra".
+ %inar! is an e6ecuta/le <i.e., read! to run= for" of a rogra". 2ource code is the original
for" of a rogra" as #ritten %! a hu"an using a rogra""ing language and %efore it has %een
con$erted %! a co"iler into a %inar!. 'he online "anual ages, co""onl! referred to as man
pages, are nor"all! accessed using the man co""and.
#hereis_s %asic s!ntax is
whereis Do#tion-s/E #rogramRname-s/
;hen used #ithout an! otions, #hich is "ost co""onl! the case, #hereis atte"ts to sul!
the a/solute path names <i.e., the ath to the root director!= for the %inar!, source code and "an
age for e$er! rogra" na"e <including co""and na"es, #hich are generall! the sa"e as
rogra" na"es= that is sulied to it as an argument <i.e., inut=. +n! nu"%er of na"es can %e
acceted as argu"ents, and the results for each #ill %e returned on a searate line.
'hus, for exa"le, the follo#ing #ould %e used to attempt to find the locations of the
executa%le, source code and "an age for the ls co""and <#hich is used to list the contents of
an! secified director!=:
whereis ls
+lthough #hereis ideall! returns three ieces of infor"ation for each argu"ent, in realit! it
often returns fe#er and so"eti"es returns "ore. -or exa"le, it #ill not return a location for
source code for a rogra" on a co"uter for #hich the source code has not %een installed
<#hich is co""on #hen rogra"s are installed in reco"iled for" during installation of the
oerating s!ste"=. Like#ise, there "a! %e no "an ages for so"e co""ands, or there "a! %e
"ore than one.
-or so"e co""ands it "ight %e the case that no executa%le is returned. Exa"les include alias
and umas(. 'his is resu"a%l! %ecause no searate executa%les #ith these na"es exist and
such co""ands are %uilt directl! into the shell <i.e., the rogra" that executes co""ands
t!ed in %! a user and disla!s their results=.
3f an executa%le, source code or "an age file exists on a co"uter %ut has not installed in a
standard location, no result #ill %e returned for it. 'his is %ecause #hereis onl! searches in
such locations. +n exa"le is the situation in #hich a user has installed a rogra" in its home
directory <i.e., the director! #hich contains configuration files, rogra"s and data secific to
that user= rather than in directories that are accessi%le to all users.
3n the e$ent that nothing is found for one or "ore of the three t!es of infor"ation for #hich
#hereis searches for each argu"ent, no error "essage or other notification is ro$ided. 3f
"ultile results are found, #hereis returns all of the".
3n so"e situations, #hereis "ight return onl! a single entr! for so"e co""ands. 'his is true in
the case of the spell co""and <#hich, as its na"e i"lies, is used to check the selling of text
files=, at least on so"e s!ste"s, as can %e seen %! running the follo#ing:
whereis s#ell
2e$eral otions are a$aila%le to li"it the t!e of results returned %! #hereis <as is the case #ith
the wc co""and, #hich %! default counts the nu"%er of lines, #ords and characters that are
contained in text=. 'he :/ otion tells it to search onl! for %inaries. 'he :m otion tells it to
search onl! for "an ages. 'he :s otion tells it to search onl! for sources. 'hus, for exa"le,
the follo#ing could %e used to search for onl! the %inaries and source code for the whoami
co""and <#hich reorts the o#ner of the current login session=:
whereis )b whoami
+s is generall! <%ut not al#a!s= the case #ith single9letter otions for shell rogra"s, these
otions can %e used together in an! co"%ination and an! order. 'he order in #hich the results
are disla!ed is not affected %! the order in #hich the otions are used.
Linux / Unix Command: which
Command Library
!AM*
whch - shows the fu path of (she) commands.
S!O"S#S
'hich |optons| |--| programname |...|
D*SC-#"1#O!
Ghich takes one or more arguments. For each of ts arguments t prnts to stdout
the fu path of the executabes that woud have been executed when ths
argument had been entered at the she prompt. It does ths by searchng for an
executabe or scrpt n the drectores sted n the envronment varabe "A12
usng the same agorthm as +ash(8).
'his "an age is generated fro" the file which.te6info.
O"1#O!S
&&all, &a
Prnt a matchng executabes n "A12, not |ust the rst.
&&read&alias, &i
Read aases from stdn, reportng matchng ones on stdout. Ths s usefu n
combnaton wth usng an aas for whch tsef. For exampe
alias 'hichC7alias J 'hich &i7.
&&s3ip&alias
Ignore opton `--read-aas', f any. Ths s usefu to expcty search for
norma bnares, whe usng the `--read-aas' opton n an aas or functon
for whch.
&&read&functions
Read she functon dentons from stdn, reportng matchng ones on
stdout. Ths s usefu n combnaton wth usng a she functon for whch
tsef. For exampe:
'hich() K declare &f J 'hich &&read&functions DL M
export -f whch
&&s3ip&functions
Ignore opton `--read-functons', f any. Ths s usefu to expcty search for
norma bnares, whe usng the `--read-functons' opton n an aas or
functon for whch.
&&s3ip&dot
Skp drectores n "A12 that start wth a dot.
&&s3ip&tilde
Skp drectores n "A12 that start wth a tde and executabes whch resde
n the 2OM* drectory.
&&sho'&dot
If a drectory n "A12 starts wth a dot and a matchng executabe was
found for that path, then prnt "./programname" rather than the fu path.
&&sho'&tilde
Output a tde when a drectory matches the 2OM* drectory. Ths opton s
gnored when whch s nvoked as root.
&&tty&only
Stop processng optons on the rght f not on tty.
&&versionB&vB&,
Prnt verson nformaton on standard output then ext successfuy.
&&help
Prnt usage nformaton on standard output then ext successfuy.

-*1U-! ,ALU*
Ghich returns the number of faed arguments, or -1 when no `programname' was
gven.
*HAM"L*
The recommended way to use ths utty s by addng an aas (C she) or she
functon (Bourne she) for 'hich ke the foowng:
E%aFsh:
which -/
T
-aliasU declare )f/ H /1sr/bin/which ))tty)only ))read)alias ))read)
f1nctions ))show)tilde ))show)dot $@
V
e9#ort )f which
EtFcsh:
alias which Jalias H /1sr/bin/which ))tty)only ))read)alias ))show)dot
))show)tildeJ
'his #ill rint the reada%le I@ and .@ #hen starting #hich fro" !our ro"t, #hile still rinting
the full ath #hen used fro" a scrit:
N which :'
~/bin/:'
N echo Wwhich :'W
/home/carlo/bin/:'
8; Linux Ghich CommandB Ghatis CommandB
Ghereis Command *xamples
%! >i"anshu +rora on +ril 67, 6L17
'his Linux tutorial #ill exlain the three R;S co""ands. 'he three R;Ss are #hatis, #hereis
and #hich co""ands.
]ou alread! kno# ho# to use find co""and to efficientl! fo find a file.
No#, these three ; co""ands #ill hel !ou to locate "ore stuff fro" Linux co""and line.
#9 Linux 'hatis Command
;hatis co""and is helful to get %rief infor"ation a%out Linux co""ands or functions.
;hatis co""and disla!s "an age single line descrition for co""and that "atches string
assed as a co""and line argu"ent to #hatis co""and. ;hatis co""and searches for string
in its index data%ases #hich is "aintained %! "and% rogra". ;hatis co""and icks short
descrition of N+4E section of "an age of co""and that "atches to inut gi$en to the
#hatis co""and.
;hatis ro$ides se$eral co""and line otions to hel user in getting %rief infor"ation of
secific Linux co""ands as er their need or interest.
2!ntax:
$ whatis D)o#tionsE
-or exa"le, here is the outut of #hatis co""and, #hen it is run #ithout an! otion.
$ whatis write
write -!/ ) send a message to another 1ser
write -'/ ) write to a file descri#tor
3t disla!s %rief infor"ation a%out R#riteS fro" "an ages.
A+out 'hich
Locate the executa%le file associated #ith a gi$en co""and.
Syntax
which )a DfilenameE 000
Description
)hich returns the athna"es of the files <or links= #hich #ould %e executed in the current
en$iron"ent, had the filename <or filenames= %een gi$en as a co""and <or co""ands= in a
strictl! P123A9confor"ant shell. 3t does this %! searching the aths in the EA9. en$iron"ent
$aria%le for executa%le files "atching the na"es of the argu"ents.
)hich does not follo# s!"%olic links.
Options
&
a
Prnt a matchng pathnames of each
matchng "lename.
*xit Status
)hich returns the follo#ing $alue, deending on #hat occurred:
FA "lenames were found, and a were executabe.
8
One or more "lenames were not found, or were not
executabe.
;An nvad opton was speced.
*xamples
which sh
Locates the athna"e of the file #hich #ould %e run if the sh co""and #ere executed. 1n
"ost s!ste"s, this #ill outut:
/bin/sh
xman - Manua page dspay program for the X Wndow System
Synopsis
xman | &otions ... |
Description
'man s a manua page browser. The defaut sze of the nta $man wndow s
sma so that you can eave t runnng throughout your entre ogn sesson. In the
nta wndow there are three optons: (el w pop up a wndow wth on-ne hep,
)uit w ext, and *anual Pa+e w pop up a wndow wth a manua page browser
n t. Typng Contro-S w pop up a wndow promptng for a specc manua page
to dspay. You may dspay more than one manua page browser wndow at a tme
from a snge executon of $man.
-or further infor"ation on using 6man, lease read the on9line hel infor"ation. 4ost of this
"anual #ill discuss custo"i.ation of 6man.
Options
A"an suorts all standard 'oolkit co""and line argu"ents <see K <1= =. 'he follo#ing
additional argu"ents are suorted.
&help$le "lename
Speces a hepe to use other than the defaut.
&+othsho'n
Aows both the manua page and manua drectory to be on the screen at
the same tme.
&notop+ox
Starts wthout the Top Menu wth the three buttons n t.
&%eometry ,$(-'-.
Sets the sze and ocaton of the Top Menu wth the three buttons n t.
&pa%esiNe ,$(-'-.
Sets the sze and ocaton of a the Manua Pages.
CustomiNin% Hman
Kman allo#s custo"i.ation of %oth the directories to %e searched for "anual ages, and the
na"e that each director! #ill "a to in the Sections "enu. A"an deter"ines #hich directories
it #ill search %! reading the ?9+29T# en$iron"ent $aria%le. 3f no ?9+29T# is found then
the director! is @usr@"an is searched on P123A s!ste"s. 'his en$iron"ent is exected to %e a
colon9searated list of directories for x"an to search.
seten6 ,"NP"TB /mit/kit/man:/1sr/man
B! default, 6man #ill search each of the follo#ing directories <in each of the directories
secified in the users 4+NP+'>= for "anual ages. 3f "anual ages exist in that director!
then the! are added to list of "anual ages for the corresonding "enu ite". + "enu ite" is
onl! disla!ed for those sections that actuall! contain "anual ages.
*irectory +ection Name
))))))))) ))))))))))))
man! -!/ 8ser @ommands
man' -'/ +ystem @alls
man% -%/ +1bro1tines
man( -(/ *e6ices
man5 -5/ =ile =ormats
man2 -2/ >ames
man7 -7/ ,iscellaneo1s
man& -&/ +ys0 "dministration
manl -l/ Local
mann -n/ New
mano -o/ Old
For nstance, a user has three drectores n her manua path and each contan a
drectory caed man/. A these manua pages w appear aphabetcay sorted
when the user seects the menu tem caed 0/1 2u3routines. If there s no drectory
caed mano n any of the drectores n her MANPATH, or there are no manua
pages n any of the drectores caed mano then no menu tem w be dspayed
for the secton caed 0o1 Ol#.
Bsd and Linux Systems
3n ne#er B2( and Linux s!ste"s, Kman #ill search for a file na"ed "etc"man.conf #hich #ill
contain the list of directories containing "anual ages. 2ee man.conf <N= for a co"lete
descrition of the file for"at.
the Mandesc File
B! using the mandesc file a user or s!ste" "anager is a%le to "ore closel! control #hich
"anual ages #ill aear in each of the sections reresented %! "enu ite"s in the Sections
"enu. 'his functionalit! is onl! a$aila%le on a section %! section %asis, and indi$idual "anual
ages "a! not %e handled in this "anner. <+lthough generous use of s!"%olic links 99 see ln <1=
99 #ill allo# al"ost an! configuration !ou can i"agine.=
'he for"at of the "andesc file is a character follo#ed %! a la%el. 'he character deter"ines
#hich of the sections #ill %e added under this la%el. -or instance suose that !ou #ould like
to create an extra "enu ite" that contains all rogra""er su%routines. 'his la%el should
contain all "anual ages in %oth sections t#o and three. 'he mandesc file #ould look like this:

'Programmer +1bro1tines
%Programmer +1bro1tines
Ths w add a menu tem to the 2e!tions menu that woud brng up a stng of a
manua pages n sectons two and three of the Programmers Manua. Snce the
abe names are e$a!tly the same they w be added to the same secton. Note,
however, that the orgna sectons st exst.
3f !ou #ant to co"letel! ignore the default sections in a "anual director! then add the line:
no defa1lt sections
anywhere n your mandesc e. Ths keeps xman from searchng the defaut
manua sectons In that #ire!tory only. As an exampe, suppose you want to do the
same thng as above, but you don't thnk that t s usefu to have the 2ystem 4alls
or 2u3routines sectons any onger. You woud need to dupcate the defaut
entres, as we as addng your new one.
no defa1lt sections
!-!/ 8ser @ommands
'Programmer +1bro1tines
%Programmer +1bro1tines
(-(/ *e6ices
5-5/ =ile =ormats
2-2/ >ames
7-7/ ,iscellaneo1s
&-&/ +ys0 "dministration
l-l/ Local
n-n/ New
o-o/ Old
Xman w read any secton that s of the from man5!hara!ter6, where
<character> s an upper or ower case etter (they are treated dstncty) or a
numera (0-9). Be warned, however, that man(1) and catman(8) w not search
drectores that are non-standard.
Gid%ets
In order to specfy resources, t s usefu to know the herarchy of the wdgets
whch compose $man. In the notaton beow, ndentaton ndcates herarchca
structure. The wdget cass name s gven rst, foowed by the wdget nstance
name.
Fman 9man (This widget is never used)
To#Le6el+hell to#So9
=orm form
Label to#Label
@ommand hel#S1tton
@ommand :1itS1tton
@ommand man#ageS1tton
Transient+hell search
*ialogAidget@lass dialog
Label label
Te9t 6al1e
@ommand man1alPage
@ommand a#ro#os
@ommand cancel
Transient+hell #lease+tandSy
Label label
To#Le6el+hell man1alSrowser
Paned ,an#ageRL#ane
Paned horiKPane
,en1S1tton o#tions
,en1S1tton sections
Label man1alSrowser
Liew#ort directory
List directory
List directory
0
0 -one for each section3
0 created on the fly/
0
+crollSyLine man1alPage
+im#le,en1 o#tion,en1
+meS+S dis#lay*irectory
+meS+S dis#lay,an1alPage
+meS+S hel#
+meS+S search
+meS+S showSoth+creens
+meS+S remo6eThis,an#age
+meS+S o#enNew,an#age
+meS+S showLersion
+meS+S :1it
+im#le,en1 section,en1
+meS+S Xname of sectionN
0
0 -one for each section/
0
Transient+hell search
*ialogAidget@lass dialog
Label label
Te9t 6al1e
@ommand man1alPage
@ommand a#ro#os
@ommand cancel
Transient+hell #lease+tandSy
Label label
Transient+hell likeTo+a6e
*ialog dialog
Label label
Te9t 6al1e
@ommand yes
@ommand no
To#Le6el+hell hel#
Paned ,an#ageRL#ane
Paned horiKPane
,en1S1tton o#tions
,en1S1tton sections
Label man1alSrowser
+crollSyLine man1alPage
+im#le,en1 o#tion,en1
+meS+S dis#lay*irectory
+meS+S dis#lay,an1alPage
+meS+S hel#
+meS+S search
+meS+S showSoth+creens
+meS+S remo6eThis,an#age
+meS+S o#enNew,an#age
+meS+S showLersion
+meS+S :1it
Application -esources
$man has the foowng appcaton-specc resources whch aow customzatons
unque to $man.
manualFont!ormal (Cass Font)
The font to use for norma text n the manua pages.
manualFontBold (Cass Font)
The font to use for bod text n the manua pages.
manualFont#talic (Cass Font)
The font to use for tac text n the manua pages.
directoryFont!ormal (Cass Font)
The font to use for the drectory text.
+othSho'n (Cass Boolean)
Ether `true' or `fase,' speces whether or not you want both the drectory
and the manua page shown at start up.
directory2ei%ht (Cass Directory2ei%ht)
The heght n pxes of the drectory, when the drectory and the manua
page are shown smutaneousy.
topCursor (Cass Cursor)
The cursor to use n the top box.
helpCursor (Cass Cursor)
The cursor to use n the hep wndow.
manpa%eCursor (Cass Cursor)
The cursor to use n the manua page wndow.
search*ntryCursor (Cass Cursor)
The cursor to use n the search entry text wdget.
pointerColor (Cass Fore%round)
Ths s the coor of a the cursors (ponters) speced above. The name was
chosen to be compatbe wth xterm.
helpFile (Cass File)
Use ths rather than the system defaut hepe.
topBox (Cass Boolean)
Ether `true' or `fase,' determnes whether the top box (contanng the hep,
qut and manua page buttons) or a manua page s put on the screen at
start-up. The defaut s true.
verticalList (Cass Boolean)
Ether `true' or `fase,' determnes whether the drectory stng s vertcay
or horzontay organzed. The defaut s horzonta (fase).
:lo+al Actions
'man denes a user nteracton through goba actons. Ths aows the user to
modfy the transaton tabe of any wdget, and bnd any event to the new user
acton. The st of actons supported by $man are:
:oto"a%e( page)
When used n a manua page dspay wndow ths w aow the user to move
between a drectory and manua page dspay. The a+e argument can be
ether Directory or Manual"a%e.
Ouit()
Ths acton may be used anywhere, and w ext xman.
Search(type, action)
Ony usefu when used n a search popup, ths acton w cause the search
wdget to perform the named search type on the strng n the search
popup's vaue wdget. Ths acton w aso pop down the search wdget. The
tye argument can be ether Apropos, Manpa%e or Cancel. If an a!tion of
Open s speced then xman w open a new manua page to dspay the
resuts of the search, otherwse xman w attempt to dspay the resuts n
the parent of the search popup.
"opup2elp()
Ths acton may be used anywhere, and w popup the hep wdget.
"opupSearch()
Ths acton may be used anywhere except n a hep wndow. It w cause the
search popup to become actve and vsbe on the screen, aowng the user
search for a manua page.
Create!e'Manpa%e()
Ths acton may be used anywhere, and w create a new manua page
dspay wndow.
-emove1hisManpa%e()
Ths acton may be used n any manua page or hep dspay wndow. When
caed t w remove the wndow, and cean up a resources assocated wth
t.
SaveFormatted"a%e(action)
Ths acton can ony be used n the li3e1oSave popup wdget, and tes
xman whether to Save or Cancel a save of the manua page that has |ust
been formatted.
Sho',ersion()
Ths acton may be caed from any manua page or hep dspay wndow,
and w cause the nformatona dspay ne to show the current verson of
xman.
Files
5manath #ire!tory6/man<!hara!ter>
5manath #ire!tory6/cat<!hara!ter>
5manath #ire!tory6/mandesc
/usr/share/X11/app-defauts/Xman
speces requred resources.
/tmp
'man creates temporary es n /tmp for a unformatted man pages and a
apropos searches.
Hman
Contents
1. Introducton
2. Runnng xman
3. Searchng xman
4. Launchers
(iscussion thread for this #iki can %e found here
#ntroduction
'he original docu"entation for all Linux s!ste"s #as a set of files collecti$el! kno#n as the
^"an ages^ that for"ed a readil! a$aila%le "anual descri%ing the actions and otions for each
co""and. 'he co""and ^"an^ follo#ed %! an otional section nu"%er and the na"e of the
co""and for #hich infor"ation #as desired %rings u the ^"an age^ for that co""and,
allo#ing !ou to learn "ore a%out it.
Unfortunatel! in toda!_s #orld, "an! of the "an ages are so full of /argon that the! see"
inco"rehensi%le to ne#co"ers 99 and e$en, at ti"es, to long9ti"e users of Linux. 2till the!
are Vuite useful, eseciall! for refreshing one_s "e"or! a%out details of a co""and not often
used.
'here_s one "a/or dra#%ack, ho#e$er: ;hen !ou need to find a "an age #hile at the
co""and line, !ou "ust either oen a second ter"inal #indo# to issue the ^"an^ co""and,
or a%ort the action under #a! so that !ou can run ^"an^ in the current #indo#.
3f, like "an! of us, !ou are using a ter"inal #indo# fro" #ithin !our file "anager <Nautilus,
(olhin, 'hunar, etc.= or fro" a deskto launcher, there_s an eas! otion. 'he urose of this
ost is to sho# !ou ho# to use it, and ho# to install and configure a launcher that #ill "ake it
e$en si"ler to use.
'his eas! otion is a rogra" called ^x"an^ that_s installed %! default #ith the A ;indo#
2!ste". 3t does the sa"e thing as the co""and ^"an^ does fro" a ter"inal, %ut does so #ithin
its o#n #indo# on the deskto, and includes a nu"%er of features to si"lif! its use. 2ince
x"an dates fro" the earliest da!s of the A s!ste", it doesn_t ha$e all the e!e cand! of "ore
recent deskto tools, and "an! of its actions are not at all intuiti$e, %ut desite this it_s still one
of the tools that 3 use dail!. ]ou "a! find it eVuall! useful.
-unnin% xman
'o get started #ith x"an, oen a ter"inal #indo# and t!e
9man
follo#ed %! the Enter ke!. ]ou_ll see this #indo# aear in !our disla!
Ths s the "top box" and smpy gudes you to the next step. Cck the
"Manua Page" button, and you' get the defaut nstructon screen:

Das könnte Ihnen auch gefallen