You are on page 1of 40

1. Idea and History of Linux 2. Linux Usage Basic 3. Browsing the file system 4. User, rou!

and "ermission

#. Using $he Bash %hell &. %tandard In!ut ' (ut!ut and "i!es ). $ext "rocessing $ool

U*I$+1
Idea and History of Linux
First Linux version (UNIX) operating system developed by ,-en $hom!son. and ,/ennis 0itchie in ,1$ 2$ Bells La3 U.%.1. in 1970 or! on "UI mode# 1454 *U pro$e%t as introdu%ed (&rap'i%al Not UNIX) it as an organi(ation t'e aim o) t'is organi(ation to develop t'e %lone o) U*I6 *perating +ystem# 145) 7inix -ernel as introdu%ed by LINUS TORVALD a &raduate student o) ,HELKENSI UNIVERSITY

Linux (rigin8 +
Linus $or9alds %reated its -:0*:L in 1991# it' assistan%e )rom programmers around t'e orld )irst posted on Internet in 1991 Linux 1#0 in 199-. /#/ in 1999 0oday used on 7110 million %omputers it' 10002s o) programmers or!ing to en'an%e it

;hat is Linux <


3 )ully1net or!ed 4/56-17it Unix1li!e *perating +ystem Unix 0ools Li!e sed8 a !8 and grep (explained later) "ompilers Li!e "8 "998 Fortran8 +malltal!8 3da Net or! 0ools Li!e telnet8 )tp8 ping8 tra%eroute :ulti1user8 :ultitas!ing8 :ultipro%essor ;as t'e X <indo s &UI "oexists it' ot'er *perating +ystems =uns on multiple plat)orms In%ludes t'e +our%e "ode

0ed Hat :nter!rise Linux


"ommer%ial >istribution ?nterprise1targeted operating system Fo%used on mature open sour%e te%'nology 1/11@ mont' release %y%le Aersions available started )rom /#18 4#08 -#0 no B#0 +upport available up to /- x 7 %overage plans +upports many pro%essor ar%'ite%tures Intel x@61%ompatible8 Intel Itanium /8 3:>6-8 I7: Co erC" on eserver i+eries and e+erver p+eries and I7: :ain)rame on e+erver (+eries and +5490

$he =edora "ro>ect


=ed ;at1sponsored open sour%e pro$e%t Fo%used on latest open sour%e te%'nology =apid )our to six mont' release %y%le 3vailable as )ree do nload )rom t'e internet 3n open8 %ommunity1supported proving ground )or te%'nologies 'i%' may be used in up%oming enterprise produ%ts =ed ;at does not provide )ormal support )or Fedora Cro$e%t

;hat is -ernel<
0'e !ernel is t'e 'eart o) t'e 'ole operating system# It manages %ommuni%ation it' 'ard are8 de%ides 'i%' pro%esses to run8 and provides ea%' pro%ess it' an isolated8 virtual address spa%e in 'i%' to run# 0'e !ernel is 'at your boot loader8 &=U7 8 loads into memory# 0'e !ernel loads devi%e driver modules

;hat is ?the shell?<


0'e s'ell is a program t'at ta!es your %ommands )rom t'e !eyboard and gives t'em to t'e operating system to per)orm# In t'e old days8 it as t'e only user inter)a%e available on a Unix %omputer# No adays8 e 'ave graphical user interfaces (GUIs) in addition to command line interfaces (CLIs) su%' as t'e s'ell#

;hat is Boot loader <


boot loader is t'e )irst so)t are program t'at runs 'en a %omputer starts# It is responsible )or loading and trans)erring %ontrol to t'e operating system kernel so)t are# 0'e !ernel8 in turn8 initiali(es t'e rest o) t'e operating system 0UB (&=and Uni)ied 7ootloader)8 'i%' is installed by de)ault8 is a very po er)ul boot loader# &=U7 %an load a variety o) )ree operating systems8 as ell as proprietary operating systems it' %'ain1loading (t'e me%'anism )or loading unsupported operating systems8 su%' as >*+ or <indo s8 by loading anot'er boot loader)#

;hat is %;1" "artition <


s ap partitions are used to support virtual memory# In ot'er ords8 data is ritten to a s ap partition 'en t'ere is not enoug' =3: to store t'e data your system is pro%essing#

%i@e of %;1" <


3t least /B6 :7 0 i%e t'e amount o) =3: on your ma%'ine + ap s'ould eDual /x p'ysi%al =3: )or up to / &7 o) p'ysi%al =3:8 and t'en 1x p'ysi%al =3: )or any amount above / &78 but never less t'an 4/ :7# +<3C %an also used a)ter t'e installation =ed ;at ?nterprise Linux supports up to 4/ s ap )iles

%am!le "artition %tructure


7ount "oint 5boot 5 5usr 5var 5'ome +<3C 7ot' are operating system# :ulti1users# :ulti1tas!ing E pro%essing# <or!s in AUI E UI mode# ;indows %i@e 1/@ :7 /0-@ :7 /0-@ :7 B1/ :7 B1/ :7 Use re%ommended si(e

%imilarity Between Linux 2 ;indows

/issimilarity Between Linux 2 ;indows


Linux

1# ?%onomi%al to use /# :ore +e%urity 4# :ostly or! in AUI -# <or!station E +erver

1# Not ?%onomi%al to use /# Less +e%urity 4# :ostly <or! in UI -# "lient E +erver

7ulti+tasBing8+ :ultiple tas! %an run pro%ess one by one at a time# 7ulti+!rocessing8+ :ultiple Crograms %an per)orm at a time

"rinci!le of Linux
1. :9erything is a file8+ 0'e UNIX se%urity module is based around t'e se%urity o) )iles by treating everyt'ing is a )ile# Fou %an se%ure a%%ess to ;ard are in t'e same ay as you se%ure a%%ess to do%ument# 2. %mall, %ingle !ur!ose !rogram81 UNIX provide many small utility t'at per)orms one tas! very ell# 3. 13ility to chain !rograms together to !erform com!lex tasB8 1 3 %ore design )eature o) UNIX is t'at t'e output o) one programs %an be input )or anot'er# 4. 19oid ca!ti9e user interface81 Intera%tive %ommands are rare in UNIX more %ommands expe%t t'eir options and arguments to be typed on t'e %ommand line 'en t'e %ommand line is laun%'ed# 0'e %ommand %omplete normally8 possibly produ%ing output or generate an error message and Duits inter1a%tivity is reserved )or programs 'ere it ma!e sense #. Aonfiguration data stored in text8+ all t'e data is stored in text b2%o( text is Universal inter)a%e and many UNIX utility exist to manipulate text# +toring "on)iguration in text allo s an administrator to move a "on)iguration )rom one :a%'ine to anot'er easily#

(!en %ource %oftware


<'en programmers on t'e Internet %an read8 redistribute8 and modi)y t'e sour%e )or a pie%e o) so)t are8 it evolves Ceople improve it8 people adapt it8 people )ix bugs# 3nd t'is %an 'appen at a speed t'at8 %ompared to %onventional so)t are development8 seems astonis'ing *pen sour%e so)t are re)er to t'e so)t are in 'i%' t'e sour%e %ode is )reely available to all users to modi)y t'eir Linux as t'eir need# ;e3site 'ttpG55 #opensour%e#org5do%s5de)ination#p'p

;hat is ;I*/(;%< ;+ I+ *+ /+ (+ ;+ %+ <ide Intera%tive Net or! >evelopment *))i%e <or! +olutions
1# =ed 'at /# +use 4# 0urbo Linux -# Fedora Linux B# +ol +upported by =;?L +upported by N*A?LL +upported by U+ E Hapenese +upported by =?> ;30 +upported by +erver *ptimi(ed Linux

/istri3utors of Linux

:nd of U*I$+1

U*I$+ 2
Linux Usage Basic
Login in to a Linux %ystem8+ =ed ;at Linux provide t o type o) login met'od# 0 o type o) login +%reen G1 Airtual "onsole Itext basedJ and &rap'i%al Login Idisplay managerJ Login using login name and pass ord# ?a%' user 'as a 'ome dire%tory )or personal )ile storage# =ed ;at provides by de)ault six virtual %onsoles t'at are I ctrlCaltCf1D to EctrlCaltCf&D. EctrlCaltCf)D is used )or &rap'i%al mode# Init & and re3oot %ommand is used to restart# :lements of F6G ;indows %ystem8+ 0'e KX2 <indo s system is Linux2s &rap'i%al subsystem ,XL *rg# is parti%ular version o) t'e X indo s system used by =ed ;at# Loo! E 7e'avior Largely "ontrolled by t'e >es!top ?nvirment# 0 o >es!top environments provided by =ed ;at# 1111# *(7: t'e de)ault

%im!le 9iew of

*(7: /esBto!

des!top environment# /# -/: an alternate des!top envoirment#

%im!le 9iew of -/: /esBto!


+tart ,XL s it%' text base to grap'i%al#

=ollowing commands are used to create a new file


N3N* AI AI: &AI: ?asy8 ?ditor8 +imple ?asy8 ?ditor8 +imple 3dvan%ed )eatured it' ?n%ryption

Basic =ile editing H 9i editor


vi 1 t'e basi% text editor t'ree modes M "ommand mode NO de)ault startup M Insert mode M ex mode vi net or!nuts NO a typi%al example M ?nter insert mode NiP and N"=P M ?nter N?+"P return to %ommand mode M Navigate t'e %ursor M h move %ursor le)t M j moves %ursor do n M k moves %ursor up M l moves %ursor rig't

%ome %im!le Aommands


ls date cal clear !wd mBdir rmdir cd cat rm c! m9 touch less more O O O O O O O O O O O O O O O list t'e )iles and dire%tory display date and time display %alendar %lear t'e s%reen prints t'e name o) %urrent or!ing dire%tory %reates t'e dire%tory removes t'e dire%tory %'anges t'e dire%tory display t'e %ontents o) )ile removes t'e )iles %opy t'e )iles and dire%tory move and rename ( )iles and dire%tories ) updates t'e )ile5dire%tory time1stamps pager %ommand pager %ommand

Aommands
& O go to last line in )ile 1& O go to )irst line in )ile ; O go to )irst line on s%reen : O go to middle line on s%reen L O go to last line on s%reen (N?nterP O ma!e %urrent line )irst line on s%reen (1 O ma!e %urrent line last line on s%reen QQdate O Inserts t'e %urrent date and time in to )ile QRsort O +orts t'e data o) your )ile QR)mt 166 O )ormats t'e data o) your )ile in to 66 %olumn idt' ?x mode G +ear%' and =epla%e %ommand GSs5big5small GSs5big5small5g 0o display t'e list o) )iles E >ire%tories e use ,lsL %ommand# 7lue "olor ,>ire%toriesL and <'ite "olor )iles# I it s'o s t'at login it' Crivilege User J it s'o s t'at login it' Non1 Crivilege user History %ommand is used to s'o t'e past %ommand# 0e3oot, init &, %ommand is used to restart t'e system# "ower off "ommand is used to s'utdo n t'e system . If you ant your system s'ut do n a)ter your parti%ular time li!e a)ter / minute t'en %ommand is J T s'utdo n U' / I 1' )or 'alt8 / )or / minuteJ Areating directory8+ J T m!dir dir name :ntering into dir8+ J T %d dir name

Listing directory content8+


Ls to s'o t'e list o) )iles E dire%tory Ls Ua in%lude 'idden )iles Ls Ul display extra in)ormation Ls Ur re%urse t'roug' dire%tories Ls Uld dire%tories and symlin! in)ormation Areating a user8 + J T Useradd username J T pass d username mBdir to %reate a dire%tory (T m!dir dirname) cd to %'ange t'e dire%tory (T %d dirname) cd .. to %ome out )rom previous dire%tory (T %d ##) cd H to go at previous or!ing dire%tory (T %d 1) cd to go at t'e ;ome (V) dire%tory (T %d) !wd to display present or!ing dire%tory (T p d) rm to remove t'e )ile ( T rm 1WoptionR )ile name# *ptions are Ui intera%tive 1r re%urse 1) )or%e)ully 5. rmdir to remove empty dire%tory (T rmdir dirname) 4. rmdir Hr dirname to remove any )ile E dire%tory are exists# $he location of a file and directory can 3e s!ecified 3y two methods 13solute 1# 7egin it' a )or ard slas' /# "omplete ,road mapL to )ile lo%ation 4# "an be used any time you is' to spe%i)y a )ile name# 0elati9e 1# >o not begin it' slas' /# +pe%i)y lo%ation relative to your "urrent or!ing dire%tory# 4#"an be used as a stored ay to spe%i)y a )ile name# 1. 2. 3. 4. #. &. ).

10

:nd of U*I$+2

Unit+4
Browsing the file system
<e 'ave already dis%ussed or learned in UNIX all8 in)ormation treated as a )ile# +ingle dis! %an store t'ousands o) )iles or organi(ing t'e data on t'e dis! t'e o5s provides a )ile system# 0'ere are t'ree types o) )ile# 1. (rdinary 2 0egular file8+ all )iles are %reated by a user %ome under t'ese %ategories# 2. /irectory file8+ )or ea%' dire%tory t'ere is )ile by t'e same name as t'e dire%tory# <'i%' %ontain in)ormation about )iles under t'at dire%toryX 3. /e9ice file81 devi%e )ile are spe%ial types typi%ally asso%iated it' input5output devi%e su%' as Crinter8 0ap >rive8 ;>>8 F>>8 ">1>rive#

%tructure of the file system


Linux )ile system 'as a tree stru%ture or 'ierar%'i%al stru%ture t'at is )ile E sub dire%tories %an be stored in t'e dire%tory#

KD I you are 'D I you are

or! in 'ome dire%tory# or! in root dire%tory#

1. '3in8+ t'is is t'e binary dire%tory# <'i%' %ontain t'e exe%utable )ilesX <'en a program is installed its binary )iles are stored 'ere# 2. 'de981 dev stand )or devi%e t'at %ontains )iles t'at point to t'e 'ard are t'at ma!e up t'e system# 3. 'etc81 t'is )older %ontains various %on)iguration )iles t'at %an be manually edited to a))e%t t'e system %'arge# 4. 'li381 lib means ,LibraryL )iles )reDuently used system )iles needed by program or t'e operating system are stored 'ere $ust li!e library )iles stored in ,"GY indo sYsystemL in indo s o5s# #. 'usr8+ Non1%riti%al )iles are stored in t'is dire%tory 'i%' %ontain a %opy o) most o) t'e dire%tories in t'e root# &. '9ar81 t'e various )older %ontains $ust t'at various )iles su%' as log )ile# ). 'tem81 t'is is t'e dire%tory t'at used by appli%ation )or storing temporary )iles# 5. 'o!t81 t'e option dire%tory stored add on %omponent su%' as des!top envoirment database # 4. 'mnt81 all storage media ot'er t'an Linux partition are mounted 'ere# 1L. 'root81 t'is is t'e 'ome dire%tory o) t'e root user 11. '3oot81 t'e boot loader )iles are stored 'ere# 12. 'home81 t'is is t'e dire%tory t'at %ontain user2s )ile#

11

13. $he '!roc' /irectory + %ontains spe%ial )iles t'at eit'er extra%t in)ormation )rom or send in)ormation to t'e !ernel# ?xamples in%lude system memory8 %pu in)ormation8 'ard are %on)iguration et%# 14. $he 's3in' /irectory + stores exe%utables used by t'e root user# 0'e exe%utables in 5sbin5 are used at boot time8 )or system administration and to per)orm system re%overy operations#

Ao!ying files and /irectories


I) t'e destination is a dire%tory8 t'e %opy is pla%ed t'ere I) t'e destination is a )ile8 t'e %opy is over rites t'e destination# I) t'e destination does not exist8 t'e %opy renamed# Aommand H c! source add destination add Aommand H c! HEo!tionD filename 'dirname +I M asB me 3efore o9erwriting a file. +r M recursi9ely co!y an entire directory tree. +! M !ermission, ownershi!, 2 time stam!s.

7o9e and renaming files 2 directory


:ove %ommand is used to move a )ile or dire%tory )rom sour%e to destination# (0 :ove %ommand is used to rename a )ile or dire%tory *ote8 + i) t'e destination is not rea%'able t'en it renames t'e )ile or dire%tory# Aommand8 + mv Eo!tionD filename destination =or exam!le8 + %reate t o dire%tory named aa8 bb# VJ T m!dir aa bb VJ T %d aa aaJ T nano '%l aaJ T mv '%l 5root5bb aaJ T %d VJ T %d bb bbJ T ll No your )ile '%l 'as moved )rom aa to bb# *autilus8+ grap'i%al )ile system bro ser#

:nd of U*I$+4
1/

Unit+#
User, rou!, and "ermission ;hat is User 1ccount <
<'en a %omputer is used by many people it is usually ne%essary to di))erentiate bet een t'e users8 )or example8 so t'at t'eir private )iles %an be !ept private# 0'is is important even i) t'e %omputer %an only be used by a single person at a time8 as it' most %omputers# 0'us8 ea%' user is given a uniDue username8 and t'at name is used to log in#

User8+
?very user is assigned a uniDue user I> no# (UI>)# (UI>0) identi)y root# User2s name and UI> are stored in 5et%5pass d# User and assigned a 'ome dire%tory and a program t'at is run 'en t'ey log in %asually a s'ell# User %an not read8 rite or exe%ute ea%' ot'er8 )iles it'out permission# *ote to see UI> run t'e VJ T "at 5et%5pass d#

;hat is

rou! <

Is a %olle%tion o) users 'i%' ma!e easy )or administrators to per)orm t'e tas! o) administration level 'en t'ey need to apply permissions and restri%tions it' same level to many o) t'e users8 t'en su%' permission and restri%tions %an be applied to related group#

rou!8+
User2s are assigned to a group# ?a%' group is assigned a uniDue group I> no# (&I>)# &I> is stored in 5et%5group# ?a%' user is given t'eir o n private group# "an be added to ot'er groups )or additional a%%ess# 3ll users in a group %an s'are a )ile t'at belongs to t'e group# *ote to see &I> run t'e VJ T "at 5et%5group

$he ,root. user


0'e root userG a spe%ial administrative a%%ount M +ame li!e ,AdministratorL e %alled in <inZ M +ometimes %alled t'e ,superuserL M root 'as %omplete %ontrol over t'e system M 3n unlimited %apa%ity to damage t'e systemQ

;hat is "ermission <


+pe%i)ies 'at rig'ts are you granting to users to a%%ess t'e resour%es are available in t'e %omputer8 so t'at important resour%es su%' as )iles are prote%ted )rom unaut'ori(ed users#

14

"ermission $y!es
"ermissions+ %ym3olic 7ethod
Four symbols are used 'en displaying permission# 08 + permission to read a )ile or list a dire%tories %ontent# ;8 + permission to rite a )ile or %reate and remove )iles )rom a dire%tory# 68 + permission to exe%ute a program or %'ange into a dire%tory and do a long listing o) t'e dire%tory# +G 1 no permission in pla%e o) t'e r8 8 x#

"ermissions+ *umeric 7ethod


Four numbers are used 'en displaying or applying permissions M 4 M 2 M 1 M L Cermission to read a )ile or list a dire%tory2s %ontents Cermission to rite to a )ile or %reate and remove )iles )rom a dire%tory Cermission to exe%ute a program or %'ange into a dire%tory and do a long listing o) t'e dire%tory no permission ( in pla%e o) t'e 48 28 or 1 )

:xamining "ermission
File permission may be vie ed using VJ [ ls Ul 5bin5login 1r xr1xr1xl root root 190@0 3pr 1 1@G/6 5bin5login File type and permissions are represented by a 10 %'ara%ter string#

Ahanging =ile (wnershi!


*nly root %an %'ange a )ile2s o ner# *nly root or t'e o ner %an %'ange a )ile2s group# * ner s'ip is %'anged it' chown# VJ T %'o n I1rJ username )ile5dirname &roup o ners'ip is %'anged it' chgr! VJ T %'grp I1rJ groupname )ile5dirname# 0o %'ange a%%ess mode it' chmod VJ T %'mod I1rJ mode )ile <'ere mode is 1# U8 &8 or * )or User8 &roup8 or *t'er /# 9 sign )or grant t'e permission# 4# U sign )or deny t'e permission# -# r8 8 x8 )or =ead8 <rite8 ?xe%ute# =or :xam!le8+ VJ T %'mod uOr x8 gOr 8 oOr )ile name VJ T %'mod ugo 9r )ile name ()or read permission to all)# VJ T %'mod aO r x )ilename

Ahanging !ermission with numeric method


Uses a tree digit mode number# 1. First digit spe%i)ies o ner2s permission# 2. +e%ond digit spe%i)ies group2s permission# 3. 0'ird digit spe%i)ies ot'er2s permission#

1-

1!!lying "ermission with *umeric 7ethod


1# - ()or read) /# / ()or rite) 4# 1 ()or exe%ute) :xam!le8 + KD I %'mod 6-0 )ile name I) u ants to give t'e read8 rite8 permission to o ner t'en %ombined t'e bot' digit %ode (-9/O6)8 and read permission to group (-)8 and )or ot'er2s on permission t'en (0)# chmod %ommand is used to %'ange a%%ess modes Numeri% :et'od M chmod &&4 somefile )ile name (&rants =ead and <rite a%%ess to o ner and group but read only it to and ot'er# ) M chmod &LL somefile )ile name ( +ets read and rite permission to o ner8 it' exe%ute turned o))8 it' ot'ers and group 'ave no permissions ) M chmod 444 somefile )ile name ( :a!e t'e )ile orld1readable )

Ahanging "ermission *autilus


Nautilus %an be used to set t'e permission and group members'ip o) )iles and dir# 1# sIn a nautilus indo rig't %li%! on a )ile# /# +ele%t properties )rom t'e %ontent menu# 4# +ele%t t'e permission tab# *ote8 + 0o %'e%! t'e permission use ls Ul# I) e %'ange t'e permission o) any )ile and dir t'en t'eir %olors be%ome green# $o add a user in a grou! VJ T usermod U& groupname username $o change the ownershi! of a user to other user8+ Log in it' root2s 'ome dire%tory VJ T %d 5'ome ;omeJ T %'o n username username

:nd of U*I$+#
1B

Unit+&
Using the 3ash shell
;hat is shell scri!t <
+'ell s%ripts are text )iles t'at %ontains a series o) %ommands or statements to be exe%uted +'ell s%ripts are use)ul )or 3utomating %ommonly used %ommands Cer)orming system administration and troubles'ooting "reating simple appli%ations :anipulation o) text or )iles# +'ell ma!es an inter)a%e bet een Users E \ernel# 0'ere are t'ree main s'ells )or UNIX isG 1 1. Bourn %hell 2. A %hell 3. -orn %hell No a days 7as' s'ell be%ome popular in Linux *5+# 7roun again s'ell (7as' s'ell) as released Brain fox 2 chief 0emey as part o) t'e )ree so)t are )oundation# 0'e *U pro$e%t )eatures o) 7as' s'ell areG 1 1# Input and output redire%tion# /# Use o) ild %ard# 4# "ommand line editing# -# ]ilde representation B# 7uilt1 in s'ell %ommand E Aariables# 6# "ommand 'istory and aliasing#

Aommand line %hortcuts


1# /# 4# -# B# (Z) (X) (019) (ab%) (^ab%) :at%' (ero or more %'ara%ters# :at%' any single# :at%' a range o) number# :at%' any o) t'e %'ara%ter in t'e list# :at%' all %'ara%ter in t'e list# =emove all )iles in extension #mp4 e use# +yntaxG 1 VJ T rm Zmp4 =emove all )iles in extension #txt e use# +yntaxG 1 VJ T rm Ztxt 0o s'o t'e )ile 'i%' 'ave se%ond %'ara%ter it' K*2 alp'abateX +yntaxG 1 VJ T e%'o X*Z 0o s'o t'e )ile 'i%' 'ave 0'ird %'ara%ter it' K:2 alp'abateX +yntaxG 1 VJ T e%'o XXmZ VJ T ls a press tab !ey t o times# VJ T %at a press tab !ey t o times# (0'is %ommand is used to s'o t'e )ile E dire%tories start it' letter Ka2 as li!e a$ay#txt) Q %'ar repeat last %ommand t'at start it' %'ara%ter# 16

*otes8 +

+yntaxG 1 VJ T Q %'ar ?xampleG 1 VJ T Q d (any %'ara%ter alp'abate) Q num repeat last %ommand by t'is no# in 'istory output# +yntaxG 1 VJ T Q num ?xampleG 1 VJ T QB VJ T m!dir UC or!5Winbox8outbox8pendingR5Wnormal8urgent8importantR In3ox *ormal Urgent Im! ;orB (ut3ox *ormal Urgent Im! "ending *ormal Urgent Im!

$o AhecB $his8 +
VJ T ls 0'en it s'o s ( or! dire%tory) VJ T %d or! <or!J T ls 0'en it s'o s (inbox8 outbox8 pending dire%tory) VJ T %d inbox InboxJ T ls 0'en it s'o s (normal8 urgent8 important sub dire%tory)

Aommand :diting $ricB


VJ T %trl Ua VJ T %trl Ue VJ T %trl Uu VJ T %trl U! VJ T %trl Uarro moves to beginning o) line# moves to end o) line# delete to end beginning o) line# delete to end o) line 'en t'e %ursor in t'e beginning o) line# moves le)t or rig't by ord#

*(7: $erminal
3ppli%ation 1111 3%%essories 1111 0erminal &rap'i%al terminal emulator t'at supply multiple ,tabbedL s'ells# "trl 9 +'i)t 9 0 "trl 9 Cgup5Cgdn "trl 9 +'i)t 9 < "trl 9 +'i)t 9 " "trl 9 +'i)t 9 A %reate a ne tab# + it%' to next5previous %lose t'e tab# %opies sele%ted text# paste text to t'e prompt

Areating %hell %cri!ts8+


%te! 18+ use su%' as KAI2 to %reate a text )ile %ontaining %ommands# First line %ontain t'e magi% s'ebang seDuen%eG T Q Li!e T Q5bin5bas' "omment your s%ripts Q "omments start it' T

17

7aBe a %cri!t
*pen a ne )ile it' KAI2 editor li!e VJ T vi )ilename and type t'e )ollo ing VJ T vi )ilename Cress ,IL )or insert mode# T Q5bin5bas' T t'is s%ript display ?%'o ,t'e date E time are [ (date)L ?%'o ,your or!ing dire%tory is [ (p d)L ?%'o ,your )iles E >ir# 3re [ (ls 1a) ?%'o ,your virtual %onsoles open are [ ( 'o) Cress ,:%AL !ey 8wN 0o run t'e )ile VJ T .'filename %te! 28+ :a!e t'e s%ript exe%utable VJ T %'mod u9x )ilename 0o exe%ute t'e ne s%riptG 1# Cla%e t'e s%ript )ile in a dire%tory in a exe%utable pat' /# +pe%i)ying t'e absolute or relative pat' to t'e s%ript on t'e %ommand line#

;riting "rograms using 3ash scri!ting


%am!le "rogram 1 T +imple Crogram )or users input e%'o 1n _?nter Four Name G_ read a e%'o 1n _?nter Four 3ge G_ read b e%'o _;ello >ear [a your age is [b Fears_ %am!le "rogram 2 T 3ddition o) 3 and 7 number e%'o 1n _?nter First number G_ read a e%'o 1n _?nter +e%ond number G_ read b %O`expr [a 9 [b` e%'o _=esult is_ [% %am!le "rogram 3 T :ultiply 3 and 7 e%'o 1n _?nter First number G_ read a e%'o 1n _?nter +e%ond number G_ read b %O`expr [a YZ [b`

1@

e%'o _=esult is_ [% %am!le "rogram 4 T >ivides 3 )rom 7 e%'o 1n _?nter First number G_ read a e%'o 1n _?nter +e%ond number G_ read b %O`expr [a 5 [b` e%'o _=esult is_ [% %am!le "rogram # T +ubtra%t 7 )rom 3 e%'o 1n _?nter First number G_ read a e%'o 1n _?nter +e%ond number G_ read b %O`expr [a 1 [b` e%'o _=esult is_ [% %am!le "rogram & T 0o "'e%! 7igger number bet een t o numbers e%'o 1n _?nter First number G_ read a e%'o 1n _?nter +e%ond number G_ read b i) I [a 1gt [b J. t'en e%'o _3 is 7I&_ eli) I [a 1eD [b J. t'en e%'o _7ot' are eDual_ else e%'o _7 is 7I&_ )i %am!le "rogram ) T 0o s'o table o) number given by user iO1 e%'o 1n _?nter any number G _ read n 'ile I [i 1le 10 J do e%'o _[n X [i O `expr [i YZ [n`_ iO`expr [i 9 1` done %am!le "rogram 5 T"'e%!s to see 'osts 19/#16@#0#1 to 19/#16@#0#10 are alive )or n in W1##10R. do 'ostO19/#16@#0#[n ping 1%/ ['ost EP 5dev5null

19

done

i) I [X O 0 J. t'en T print 'ost names 40 %'ar ide and le)t $usti)ied print) _S140s is aliveYn_ ['ost else print) _S140s is N*0 aliveYn_ ['ost )i

U*I$+)
%tandard In!ut ' (ut!ut and "i!es
*ne o) t'e most important )eatures o) Linux (and UNIX) is t'e ability to redire%t a %ommand2s input8 output8 and error data# Linux provides t'e t'ree I5* %'annel to programs# 1. %tandard In!ut -ey3oard 3y default 2. %tandard (ut!ut $erminal ;indows 3y default 3. %tandard error $erminal ;indows 3y default

0edirecting to file
1# P /# /P 4# EP =edire%t +0> *U0CU0 to )ile =edire%t +0> ?==*= to )ile =edire%t all output to a )ile

Aommon 0edirection o!erators


1# "ommand P)ilename >ire%t standard output %ommand to )ile# /# "ommand PP)ilename 3ppend standard output %ommand to )ile# 4# "ommand N)ilename +end )ile as input to %ommand -# "ommand /P)ilename =edire%ted error message )rom %ommand to )ile# B# "ommand /PP)ilename 3ppend error message )rom %ommand to )ile# 1. In!ut 0edirection8+ any text input enter )rom t'e !eyboard redire%t in to spe%i)ied )ile# VJ T %at P)ilename8 VJ T ls UlP)ilename 2. (ut!ut 0edirection81 instru%t to s'ell to redire%t to a %ommand output into t'e spe%i)ied )ile instead o) t'e terminal# VJ T %at N)ilename 3. :rror 0edirection81 VJ T xy( /Perror message

:x!eriment of u!!er command 3y the following !rocess


First o) %reate a user on root and login to t'at user and )ollo t'e step 1# VJ T )ind 5 1name pass d /# VJ T )ind 5et% Uname pass d 4# VJ T Find 5et% Uname pass d Pra$ ()ilename) Wsend t'e result in ra$ and s'o remaining errorR# -# VJ T %at ra$ ()ilename) Wra$ s'o t'e resultR# B# VJ T )ind 5et% Uname pass d PPra$ ()ilename) Wadd t'e result in ra$ 'i%' %omes in %ommand number 4R# 6# VJ T %at ra$ Ws'o t'e total result in ra$R 7# VJ T %at Nra$ W%ommand 6 and 7 'as same output e use %ommand as ell as %ommand 7R# @# VJ T )ind 5et% Uname pass d /Pra$/ ()ilename) Wsend t'e errors in ra$/()ilename) and s'o resultR#

/0

9# VJ T %at ra$/ ()ilename) or VJ T %at Nra$/ ()ilename) Wto see t'e error are in ra$/ ()ilename)R# 10# VJ T )ind 5et% Uname pass d /PPra$/ ()ilename) Wadd t'e error 'i%' are %omes in %ommand @R# 11# VJ T %at ra$/ ()ilename) or VJ T %at Nra$/ ()ilename)# 1/# VJ T )ind 5et% Uname pass d EPra$4 ()ilename)# 14# VJ T %at ra$4 ()ilename)# 1-# VJ T )ind 5et% Uname pass d Paa Pbb Wto send all t'e result in )ile named aa and error in )ile named bbR# 1B# VJ T %at aa Wto see resultR# 16# VJ T %at bb Wto see errorR#

0edirecting %$/(U$ to a "rogram O"i!ingP


Cipes (t'e a %'ara%ter) %an %onne%t %ommands# (%ommand1 a %ommand/) +ends +0>*U0 o) %ommand1 to +0>IN o) %ommand/ instead o) t'e s%reen# +0>?== is not )or arded a%ross pipes# "I": is used to add t o or more %ommands# :x VJ T ls Ul a more $r translate t'e upper %ase into lo er %ase and lo er %ase into upper %ase# *riginal )ile ill be un%'anged# %yntax8+ VJ T tr Ka1(2 K31]2 N)ilename %yntax8+ VJ T tr K31]2 Ka1(2 N)ilename

0edirecting %$/(U$ to a "rogram :xam!les


Less8 vie input one page at a time# T ls Ul 5et% aless Winput %an be sear%'ed it' 5R# L!r8 +end input to a printer# VJ T e%'o ,test printL a lpr or T e%'o ,test printL a lpr Up printerbname# 7ail8 +end input via e1mail# VJ T e%'o ,test mailL a mail1s ,testL usercexample#%om VJ VJ

%cri!ting for loo!s


Cer)orming a%tions on ea%' member o) a set o) values# %yntaxG ma!e a )ile it' AI editor TQ5bin5bas' T alive/#s' T %'e%!s to see i) 'osts 19/#16@#1#1119/#16@#1#/0 are alive T iterate t'roug' IC addresses For n in W1d/0R. do ;ostO19/#16@#1#[n Cing U%/ ['ost EP 5dev5null I) I[X O0J. t'en ?%'o ,['ost is upL ?lse ?%'o ,['ost is do nL Fi >one Cress K?+"2 !ey

/1

G <D VJ T %'mod u9x ra$ ()ilename)#

VJ T# 5ra$ ()ilename)#

=ilter Aommand
VJ T grep# 5et%5pass d Wit s'o t'e %ontent o) )ile a)ter )ilteringR#

%ort Aommand
VJ T sort %olor (it s'o t'e alp'abeti%al %ontent)# VJ T ls Ul asort 7utt Aommand Ot'is %ommand is a text1based mail %lientP.

U*I$+5 $est "rocessing $ools


Introduction to %tring "rocessing Head and $ail ;ead s'o s t'e )irst 10 lines o) a )ile M 0ry 'ead 5et%5some)ile M 0ry 'ead 1n B 5et%5some)ile (s'o s t'e )irst B lines o) t'e )ile) 0ail s'o s t'e last 10 lines o) a )ile M 0ry tail 5et%5some)ile M 0ry tail 1n B 5et%5some)ile (s'o s t'e last B lines o) t'e )ile) wc, sort, uniN , cut and !aste wc ,<ord "ountL used to %ount t'e line8 ord8 %'ara%ter in t'e )ile# %yntax KD I wc +l filename Ofor count the lineP KD I wc +w filename Ofor word countP KD I wc +c filename Ofor column countP VJ T % 1m )ilename ()or t'e %'ara%ter %ount) M *ptions ( +l Ofor lineP8 +wOfor wordP8 +cOfor columnP ) sort ,+orting *rderL it is used to sort t'e data into as%ending or des%ending order but original )ile ill be no %'ange# %yntaxG1 VJ T sort Ur )ilename W)or des%ending sortR M KD I sort )ilename W)or as%endingR M KD I sort Un )ilename W)or as%ending numeri% sort M KD I sort Unr )ilename Wreverse numeri% sortR M KD I sort Uu )ilename WuniDue sortingR M sort ("$I(*% some)ile M *ptions ( 1r8 1n ) uniN ,=emoves dupli%ate lines in a )ileL M +u to s'o only truly uniD M +d to s'o lines t'at are repeated in t'e input M +c to %ount lines cut , >isplay spe%i)i% %olumns o) t'e )ile data %yntax KD I cut +c2+# filename
//

KD I cut Hf3 Hd8 'etc'!asswd paste ,Caste )iles toget'erL KD I !aste file1.txt file2.txt Q file3

as!ell, ex!and looB and sed as!ell ,0o %'e%! spelling in )ile , %yntax KD I as!ell checB filename ex!and ,?xpand tabs into spa%esL M expand tab)ile#txt P result#txt LooB give t'e mat%'es related or! )rom dire%tories# %yntax KD I looB word %ed Ostream editorP use to sear%' and repla%e pattern but original )ile ill be un%'anged# %yntax KD I sed Fs'9i>ay'amitG filename KD I sed Fs'9i>ay'amitG filename Qnew filename Osa9ing changes in another fileP.

%tring "rocessing with 0egular :x!ressions


re!, sed, awB, diff gre! 0'is %ommand is used to sear%' a ord in a )ile# %yntax KD I gre! FEAcDat filename KD I gre! +i FEfDrog filename Oi+ re!resents case H insensti9ityP %yntax KD I gre! +13 FcatG filename O1 stand for afterP KD I gre! +B3 FcatG filename OB stand for 3eforP , Crints lines o) )iles 'ere a pattern is mat%'ed M gre! amit 'etc'!asswd sed , +tream ?ditor G1 =eads a )ile . rites out t'e data per)orme sear%' and repla%e , original ill be un%'anged# M sed Fs'3ig'small'G somefile M sed Fs'3ig'small'gG somefile awB , Crogramming language )or editing text , M awB F '3ash' R !rint S F 'etc'!asswd diff t'is %ommand is used to ma!e a di))eren%e bet een / )iles# %yntax KD I diff file1 file2

/4

U*I$+4 TI78 1n 1d9anced $ext :ditor


Tim stand for O9isual im!ro9ed editorP8+ it is a advan%e version o) AI editor it %reate t'e text )ile in en%rypted )orm# %yntax8+ 9im +x filename Introduction of TI78+ Ne er version o) AI t'e standard UNIX text editor# 1# ?xe%uting AI runs AI: by de)ault# TI7 1 grap'i%al version o) AI:# 1# 3ppli%ation 9 Crogramming AI /# Croviding by AI: Ux 11 Ca%!age 1d9antage of TI78 +peedG do more it' )e er !eystro!es# +impli%ityG no dependen%e on mouse5&UI 3vailabilityG in%luded it' most UNIX li!e uses# /isad9antage of TI78 >i))i%ultyG steeper learning %urve t'an simpler editors# \eystro!e be'avior is dependent upon AI:2s mode In t'is AI: or AI editor you 'ave t'ree mode# 1# "ommand modeG (>e)ault) move %ursor8 %ut8 text8 %'ange mode# /# Insert modeG modi)ied text# 4# ?x1modeG save E Duit et%# 7o9ing 1round command mode8 :ove by ord 8b :ove by senten%e )8 ( :ove by Caragrap' R8 W Hump by line X X& Hump by end line & %hortcut of Aommand mode8 1 it stand )or append to t'e end line# I insert at beginning o) t'e line# o insert a ne line do n side# ( insert a ne line up side# U used )or undo
/-

=or mouse8 '1le)t8 $1do n8 !1up8 l1rig't# Aommand for word re!lacement8 VJ T GSs5old ord5ne ord

7ani!ulating $ext Aommand mode


;ord Line Letter ;ord %entence ahead %entence 3ehind "aragra!h a3o9e "aragra!h 3ehind Ahange O0e!laceP AA cl cw cP cO cR cS /elete OAutP dd dl dw dP dO dR dS UanB OAo!yP yy yl yw yP yO yR yS

Line wise "aste


p used )or paste belo t'e line C used )or paste above t'e line

Aharacter wise 2 word wise


p used )or paste a)ter t'e %ursor C used )or paste be)ore t'e %ursor

/B

U*I$+1L Basic %ystem Aonfiguration $ools


I" 1ddressing
Is a 4/bit Logi%al 3ddress 'i%' ma!e %omputer to %ommuni%ate to ea%' ot'ers using 0"C5IC proto%ol# >e)ined in di))erent %lasses From 3 to ? "lass 3O 1 to 1/6 "lass 7O 1/@ to 191 "lass "O 19/ to //4 ;e can assign I" 1ddress to com!uter 3y using two methods 1# +tati% I :anually J /# >ynami% I Using >;"C +erver J

*etworB Aonfiguration Aommands


ifconfig Used to vie t'e properties o) a%tive and ina%tive net or! inter)a%es ifconfig Ifconfig Ha O to display in)ormation about ina%tive net or! inter)a%e ifu! ' ifdown Used to a%tivating and dea%tivating a net or! inter)a%e ifdown ethL ifu! ethL mii+tool 0ool allo s a system administrator to vie 8 monitor8 log and %'ange t'e negotiated speed o) ?t'ernet net or! %ards mii+tool H9 O to vie t'e %urrent status o) net or! inter)a%e %ard mii+tool H9 ++force 1LL3ase$x+=/ ethL 0o %'ange t'e negotiated speed o) ?t'ernet net or! %ard

*etworB Aonfiguration Utilities


neat ' neat+tui 0ext1based net or! %on)iguration tool *nly rites %on)ig )iles# >oes not a%tivate devi%e or %'anges# Use i)up5i)do n to a%tive %'anges or restart t'e net or! servi%e Used by !ud(u 'en ne net or! %ard )ound at boot time /6

system+config+networB &N*:?1based net or! %on)iguration tool "an be laun%'ed by a non1privileged user8 but reDuires aut'enti%ation as root#

"rinting in Linux
Crinter may be lo%al or net or!ed# Crint reDuests are sending to Dueues# eueued $obs are sent to t'e printer on a )irst %ome )irst serve basis# Hobs may be %an%elled be)ore or during t'e printing# L!r command is used to !rint the file. %ystem+config+!rinter

U*I$+11 In9esting and 7anaging "rocesses


;hat is a "rocess<
3 pro%ess in an exe%uting program it' several %omponents and properties# 3 pro%ess is a s'ell %ommand or a program in exe%ution# <'en you log in8 a pro%ess is %reated# 0'is pro%ess is exe%uting t'e s'ell <'en you exe%ute a s'ell %ommand8 a ne pro%ess is %reated# <'en t'e %ommand terminates8 t'e ne pro%ess dies# 3 single user %an 'ave many pro%esses exe%uting at t'e same time

!s command
0'e %ommand ps is used to determine t'e status o) a%tive pro%esses# 0'e %ommand returns t'e pro%ess id (CI>) number and ot'er in)ormation su%' as t'e amount o) "CU time t'e pro%ess 'as used (0I:?) and t'e %ommand 'i%' invo!ed t'e pro%ess (":>)# *ptions may be %ombined#

to! command
0'e %ommand top is used to s'o a real1time vie o) Linux tas!s top %an be used to display t'e "CU5memory usage o) ea%' tas! to!

$erminate "rocesses
ki is used to terminate pro%esses or to send signal to pro%esses# ?xamplesG M Bill "I/ M 0erminate t'e pro%ess it' t'e pro%ess id (CI>)#

/7

U*I$+12
Aonfiguring the Bash %hell
;hat is Bash %hell< It is t'e de)ault s'ell )or Linux operating system it as introdu%ed in 197B#

3liasesG1
3liases let you %reate s'ort%uts to %ommands# Use alias by it sel) to see all set aliases# Use alias )ollo ed by an alias name to see alias value#

/@

U*I$+13
=inding and "rocessing =iles
Locate8+ eueries a pre1built database o) pat's o) )iles on t'e system# /# >atabase must be updated by administrator# 4# Full pat' is sear%'ed8 not $ust )ile name# :ay only sear%' dire%tories 'ere t'e user 'as read and exe%ute permission# *ote8+ Lo%ate %ommand is used to sear%' t'e )ull pat' o) )ile8 and display i) lo%ate %ommand does not run t'en )irstly run Kupdatedb2 %ommand at root login a)ter t'at run ,Lo%ateL %ommand# %yntax8+ VJ T lo%ate dirname slocate and find slo%ate , +ear%' )or )iles , M slocate somefile )ind , +ear%' )or )iles , M find 'home Hname somefile M find 'home Hiname somefile E case+insensiti9e search D M find 'home Huser amit Hgrou! amit somefile M find 'home H!erm )## M find 'home Hsi@e 1LLLB3 M find 'home Huser username M find 'home Huser username Ho Huser username =ind 21ccess $ime 1# Uatime 'en )ile as last read# /# U%time 'en )ile data as last %'anged# 4# Umtime 'en )ile data or metadata last %'anged# %yntax8+ VJ T )ind U%time day2s no# ()ile modi)ied less t'en 10 days ago#) VJ T )ind Uatime B (loo!s )or )iles 'ose last a%%ess time stamp exa%t B days ago# VJ T )ind Uatime 9B (loo!s )or )ile 'ose last a%%ess time stamp is more t'en B days ago# =ind 2 "ermission "an mat%' o ners'ip by name or I># 1# VJ T )ind 5'ome Uuser username 1o 1uid B00
/9

"an mat%' o%tal or symboli% permissions# 1# VJ T )ind 1prem 97BB (mat%'es i) mode is exa%t) /# VJ T )ind 1prem 9/// (mat%'es i) anyone %an rite) 4# VJ T )ind 1prem 1/// (mat%'es i) everyone %an rite) =ind 2 *umeric Ariteria8 :any )ind %riteria ta!e numeri% values VJ T )ind 1si(e 10/-!b 1# Files it' a si(e o) exa%tly 1 megabyte# VJ T )ind 1si(e 910/-!b 1# Files it' a si(e over 1 megabyte# VJ T )ind 1si(e 110/-!b 1# Files it' a si(e less t'en 1 megabyte#

U*I$+14 *etworB Alients


=irefox
Fast8 lig't eig't8 Feature1ri%' eb bro ser# 0abbed bro sing# Copup bro sing# "oo!ie management# :ulti1engine sear%' bar# +upport )or many popular plug1in# 0'emes and ?xtension#

:linBs
7est linux text1based eb %lient ( eb bro ser ) Full support )or )rames and ++L I 'ttps ebsites J ?xampleG VJ T elin!s 'ttpG55 #red'at#%om# >o nload manager 7oo!mar!

wget
=etrieves )iles via ;00C and F0C Non1intera%tive1 use)ul in s'ell s%ripts "an )ollo lin!s and traverse dire%tory trees on t'e remote server ?xample wget htt!8''www.download.com'songs!layer'm!layer.exe

aim
:ulti1proto%ol Instant messaging %lient +upports 3I:8 :+N8 F3;**8 I"e8 Habber8 &adu1&adu8 +IL"8 &roup<ise :essenger8 I=" and ]ep'yr net or!s Clugins %an be used to add )un%tionality

g=$"
3ppli%ations5Internet5gF0C
40

&rap'i%al F0C "lient 3llo s >rag1and1>rop 0rans)ers *ptional se%ure trans)er via ss' ( s)tp )

:9olution
>e)ault ?mail "lient so)t are "an maintain multiple a%%ounts and on%e

mutt
0ext based ?mail %lient +upports C*C8 I:3C and Lo%al mail boxes :appable 'ot !eys#

ssh8 %ecure %hell


ss' allo s remote logins and remote %ommand exe%ution via a se%ure en%rypted %onne%tion# +e%ure repla%ement )or older remote1a%%ess tools# 3llo s aut'enti%ated8 en%rypted a%%ess to remote systems ?xample ssh rootVstation1.exam!le.com

sc!8 %ecure Ao!y


s%p or!s li!e %p8 ex%ept it %opies )rom one 'ost to anot'er in a se%ure en%rypted %'annel ?xample sc! somefile rootVstation1.exam!le.com8

resync8 ?))i%iently )ile syn%


?))i%iently "opies )iles to or )rom remote systems# Users se%ure ss' %onne%tion )or transport# Faster t'an s%p# %yntax VJ T rsyn% sour%e destination add# VJ T ss' rootcipaddress VJ T s%p rootcipaddress8'root'dirname 'root VJ T rsyn% rootcipaddress8 'root'dirname 'root

Introduction to %hell %cri!ting


;hat is shell scri!t <
+'ell s%ripts are text )iles t'at %ontains a series o) %ommands or statements to be exe%uted +'ell s%ripts are use)ul )or 3utomating %ommonly used %ommands Cer)orming system administration and troubles'ooting "reating simple appli%ations

Areating %hell %cri!ts


"reate a )ile using vi text editor
41

Use T )or %omments I In)ormation J ?nter %ommands related to s%ripts :a!e t'e s%ript exe%utable chmod aCx scri!tWname 0o ?xe%ute t'e ne s%ript Cla%e t'e s%ript in a dire%tory in t'e exe%utable pat' *r +pe%i)y t'e absolute or relative pat' to t'e s%ript on t'e %ommand line

:xit %tatus
?very %ommand returns an exit status# 0'e exit status ill be a number in t'e range o) 0 to /BB and it indi%ates 'et'er or not t'e %ommand ran su%%ess)ully# 0 )or su%%ess8 1 to /BB )or )ailure ?xit status o) most re%ently exe%uted %ommand is !ept in t'e [X Aariable $ust li!e return values )rom s'ell )un%tions ?xampleG1 echo J<

U*I$+1# 1d9anced $o!ic in Users, "ermissions


;hat is User 1ccount <

rou! and

<'en a %omputer is used by many people it is usually ne%essary to di))erentiate bet een t'e users8 )or example8 so t'at t'eir private )iles %an be !ept private# 0'is is important even i) t'e %omputer %an only be used by a single person at a time8 as it' most %omputers# 0'us8 ea%' user is given a uniDue username8 and t'at name is used to log in#

;hat is

rou! <

Is a %olle%tion o) users 'i%' ma!e easy )or administrators to per)orm t'e tas! o) administration level 'en t'ey need to apply permissions and restri%tions it' same level to many o) t'e users8 t'en su%' permission and restri%tions %an be applied to related group#

$he ,root. user


0'e root userG a spe%ial administrative a%%ount M +ame li!e ,AdministratorL e %alled in <inZ M +ometimes %alled t'e ,superuserL M root 'as %omplete %ontrol over t'e system M 3n unlimited %apa%ity to damage t'e systemQ

Areating Users useradd options user 1 "reates a ne user# M 1% 3ssigns )ull name to user#

4/

Uses to de)ine 'ome )olders lo%ation# Uses to de)ine userfs s'ell# (Use 5sbin5nologin )or users you is' to restri%t )rom 'aving s'ell a%%ess)# M 1g 3dd user to group ( Crimary &roup ) M 1& 3dd user to group ( +e%ondary &roup ) usermod options user 1 :odi)ies user a%%ount M +ame options as useradd. userdel options user 1 >eletes user a%%ount# M 1r G =emove userfs 'ome dire%tory# pass d user 1 "'anges t'e pass ord o) t'e spe%i)ied user# M I) no user is spe%i)ied8 ill %'ange t'e pass ord o) t'e %urrent user#

M 1d M 1s

Aonfiguration =iles
5et%5pass d 5et%5s'ado 5et%5group 5et%5gs'ado O O O O )ile %ontains user database )ile %ontains user pass ord database )ile %ontains group database )ile %ontains group pass ord database

User Information Aommands


Find out 'o you are M 'oami Find out 'at groups you belong to M groups8 id Find out 'o is logged in M users8 'o8 Login5reboot 'istory M last

Linux file security


?very )ile is o ned by a UI> and a &I># ?very pro%ess runs as a UI> and one or more &I>2s# usually determined by 'o runs t'e pro%ess# 0'ree a%%ess %ategories# Cro%ess running it' t'e same UI> as t'e )ile (user)# Cro%ess running it' t'e same &I> as t'e )ile (group)# 3ll ot'er pro%ess (ot'er)#

;hat is "ermission <


+pe%i)ies 'at rig'ts are you granting to users to a%%ess t'e resour%es are available in t'e %omputer8 so t'at important resour%es su%' as )iles are prote%ted )rom unaut'ori(ed users#

44

7ethods of Im!lementing "ermissions


+ymboli% :et'od Numeri% :et'od

1!!lying "ermission with *umeric 7ethod


-# - ()or read) B# / ()or rite) 6# 1 ()or exe%ute) :xam!le8 + KD I %'mod 6-0 )ile name I) u ants to give t'e read8 rite8 permission to o ner t'en %ombined t'e bot' digit %ode (-9/O6)8 and read permission to group (-)8 and )or ot'er2s on permission t'en (0)# chmod %ommand is used to %'ange a%%ess modes Numeri% :et'od M chmod &&4 somefile )ile name (&rants =ead and <rite a%%ess to o ner and group but read only it to and ot'er# ) M chmod &LL somefile )ile name ( +ets read and rite permission to o ner8 it' exe%ute turned o))8 it' ot'ers and group 'ave no permissions ) M chmod 444 somefile )ile name ( :a!e t'e )ile orld1readable )

UmasB
umas! is a value 'i%' is subtra%ted )rom de)ault to determine ne )ile5 dire%tory permissions >e)ault permission )or )iles is 666 >e)ault permission )or dire%tories is 777 /efault "ermission H UmasB M :ffecti9e "ermission M Non1Crivileged Users umasB is 00/ Files ill 'ave permissions o) 66 >ire%tories ill 'ave permission o) 77B M root2s umas! is 0// M ?xample G1 M 666 U 00/ O &&4 M 666 U /-- O 422 M 777 U /// O ### M 777 U 0/7 O )#L

4-

Permissions
r w x r x r x Owner has read Owner has write Owner has execute Group has read Group does not have write Group has execute Others have read Others do not have write Others have execute

%!ecial "ermission for directories8


%ticBy 3it8 t'e sti%!y bit )or a dire%tory sets a spe%ial restri%tion on deletion o) )ilesG it' t'e sti%!y bit set8 only t'e o ner o) t'e )ile and super user (root) %an delete )iles it'in t'e dire%tory# +ti%!y bit is (1) :xam!le VJ T %'mod 1777 dirname %gid8 )iles %reated in dire%tories it' t'e sgid bit set 'ave group a))iliations o) t'e group t'e dire%tory# (/) :xam!le VJ T %'mod /770 dirname (ften 3oth the sti%!y bit and sgid permission ill be set on a group dire%tory# :xam!le

4B

VJ T %'mod :xam!le VJ T %'mod

4770 -BB1

dirname pass d

U*I$+1& $he Linux =ile system in+/e!th


Basic =ile %ystem $y!es
3 )ile system is t'e logi%al stru%ture and so)t are routines t'at %ontrol a%%ess to t'e storage spa%e on dis!s# Unli!e most operating systems8 Linux supports several )ile system types# 0'e ?xt/ (+e%ond ?xtended) )ile system is t'e most %ommon Linux )ile system and is t'e se%ond version o) t'e ?xt )ile system 0'e ?xt/ )ile system as designed to over%ome de)i%ien%ies )ound in t'e ?xt )ile system 0'e ?xt )ile system %an 'andle partitions up to / gigabytes (&7) in si(e8 'ereas ?xt/ %an 'andle partitions up to - terabytes (07) in si(e

=eatures of :xt2
0'e ?xt/ )ile system 'as many ot'er advan%ed )eatures in%luding provision )or )ilenames up to /BB %'ara%ters long ?xt/ also reserves dis! spa%e on t'e partition )or t'e superuser# 0'is means t'at i) a dis! develops a problem8 t'e superuser %an still a%%ess t'at dis! and re%ti)y it

:xt3 file system


In Linux 7#/8 ext/ is t'e de)ault )ile system =eDuire %'e%! )or %onsisten%y (e/)s%!) 'en system is not properly s'ut do n ?xt OP ext/ OPext4 +upport /B6 %'ar )ilenames8 - 0era byte max )ilesi(e *t'ers :+1>os8 F304/8 N0F+8 I+*9660 +tarting )rom Linux 7#48 ext4 is t'e de)ault )ile system Crovide stronger data integrity in event o) un%lean s'utdo n "'e%! )or %onsisten%y is needed only on rare 'ard are )ailure ;ig'er t'roug'put8 as it is optimi(es 'ard drive 'ead motion Crovide easy transition )rom ext/ to ext4

46

ot'er %ommon )ilesystem are :+1>*+ (F304/8 N0F+8 I+*9660) 0'e ext4 )ile system is essentially an en'an%ed version o) t'e ext/ )ile system# 3dvantages areG

19aila3ility
3)ter an po er )ailure or system %ras' (also %alled an unclean system shutdown)8 ea%' mounted ext/ )ile system on t'e ma%'ine must be %'e%!ed )or %onsisten%y by t'e e2fscB program# 0'is is a time1%onsuming pro%ess t'at %an delay system boot time signi)i%antly8 espe%ially it' large volumes# 0'e $ournaling provided by t'e ext4 )ile system means t'at t'is sort o) )ile system %'e%! is no longer ne%essary a)ter an un%lean system s'utdo n# 0'e only time a %onsisten%y %'e%! o%%urs using ext4 is in %ertain rare 'ard are )ailure %ases8 su%' as 'ard drive )ailures#

/ata Integrity
0'e ext4 )ile system prevents loss o) data integrity in t'e event t'at an un%lean system s'utdo n o%%urs# 0'e ext4 )ile system allo s you to %'oose t'e type and level o) prote%tion t'at your data re%eives#

"artition and =ile %ystem


>is! drives are divided into partitions Cartition are )ormatted it' )ile system8 allo s users to store data M >e)ault )ile systemG ext48 t'e 0'ird ?xtended Linux File +ystem M *t'er %ommon )ile systemsG M ext/ and v)at M iso9660 ( typi%ally used )or ">s)

LinBs
3 lin! is a )ile t'at points to anot'er )ile# ,lnL %reates a ,lin!L )rom t'e original )ile to a ne ,)ileL in your dire%tory# :ost programs ill a%%ess t'e lin! as i) it as t'e )ile# 0'is is similar to a ,s'ort%utL in <indo s# 0'is allo s )or aliasing ( 'en t o or more names %an exist )or t'e same ob$e%t) ?asy ay to point to a really long absolute pat'name or )ilename

Using LinBs
$wo ty!es of linBs can 3e created M +ymboli% ( +o)t ) M ;ard ln +s main soft ( 0'is ill %reate an so)t lin! o) )ile ,mainL ) ln main hard ( 0'is ill %reate an 'ard lin! o) )ile ,mainL )

7ounting the media


,:ountingL means ma!ing a partition to a%%ess )rom an a%%ess point typi%ally a )older to store and a%%ess data )rom it# "ommands to mount media

47

mount 'media'flo!!y mount 'media'cdrom mount 'media'/e9ice I/ "ommands to unmount media umount 'media'flo!!y umount 'media'cdrom umount 'media'/e9ice I/

O O

:ounts )loppy drive to your %omputer O :ounts %drom drive to your %omputer :ounts usb dis! to your %omputer

O O O

Unmounts )loppy drive to your %omputer Unmounts %drom drive to your %omputer Unmounts usb dis! to your %omputer

1rchi9e =iles
3r%'iving pla%es many )iles into one target )ile ?asier to ba%! up8 store8 and trans)er tar U +tandard Linux ar%'iving %ommand

Using 1rchi9e files H tar command


tar c9f archi9eWname files.. ( 0o %reate ar%'ive )ile ) tar t9f archi9eWname files.. ( 0o display )iles under ar%'ive )ile ) tar x9f archi9eWname files.. ( 0o extra%t )iles )rom ar%'ive )ile ) tar r9f archi9eWname files.. ( 0o append ar%'ive )ile )

=ile Aom!ression
=esults in smaller )ile si(e 0ext )iles %an be %ompressed over 7BS tar ar%'ives are o)ten %ompressed

Aom!ression Utilities
g@i!, gun@i! M +tandard Linux %ompression utility M Up to 7BS %ompression )or text )iles 3@i!2, 3un@i!2 M Ne er Linux %ompression utility M &enerally a%'ieves better %ompression t'an g(ip

Using Aom!ression
g@i! somefile ( 0o %reate %ompressed )ile ) gun@i! somefile ( 0o un%ompress a %ompressed )ile ) 3@i!2 somefile ( 0o %reate %ompressed )ile ) 3un@i!2 somefile ( 0o un%ompress a %ompressed )ile )

4@

*oteG 1 <e %an use @ for g@i! and > for 3@i!2 type o) %ompression it' tar

U*I$+1) :ssential %ystem 1dministration $ools


0ed Hat "acBage 7anager 2 Uum %er9er
0"78+ 0'e =C: Ca%!age manager greatly simpli)ies t'e distribution8 installation8
upgrading8 and removal o) so)t are on =ed ;at ?nterprise Linux +ystem# 0'e lo%al =C: database is maintained in 5var5lib5rpm# 0'e database stores in)ormation about installed pa%!ages su%' as )ile attributes and pa%!ages prereDuisites# r!m is a ba%!end )or ot'er programs su%' as yum or system+config+!acBages. 0'e tools provide signi)i%ant advantages su%' as automati% dependen%y resolution#

"rimary 0"7 o!tions8+


rpm rpm rpm rpm rpm 1I 1U 1F 1e 1iv' )ilename )ilename )ilename )ilename )ilename ()or install) (upgrade) ()or )res'en) ()or erase) ()or update)

(ut!ut (!tion8+

+9 +h

OUsed )or print pa%!age nameP OUsed )or print 'as' mar!sP

0"7 Xueries8+ =C: provide robust Duerying8


49

'i%' is invo!ed it' r!m +N or r!mNuery. euery option )all into one o) t o %ategoriesG t'ose t'at spe%i)y 'i%'

pa%!ages to Duery8 and t'ose t'at spe%i)y 'at in)ormation to retrieve# 0'e )irst must be spe%i)ied. t'e se%ond de)aults to t'e pa%!age name# %yntax8 + r!m +Na Yless r!m +Nf filename Os'o o ning pa%!ageP r!m +Ni !acBageWname Ogeneral in)ormationP r!m +Nl !acBageWname Olists )iles in pa%!ageP

0"7 Terification8+ veri)ying an installed pa%!age %ompares t'e )ile si(es8


permission8 type8 o ner8 group8 :>B %'e%!sum8 and modi)y time against t'e =C: database# 3ny in%onsisten%y ill be reported# 3n installed pa%!age %an also be veri)ied against a pa%!age )ile as ellG %yntax8 + r!m +T @i! veri)ies t'e installed (ip rpm against t'e =C: database# r!m +Ta veri)ies all installed =C:+ against t'e =C: database# r!m +T! @i!+2.3+5.i35&.r!m veri)ies t'e installed (ip pa%!age against t'e (ip pa%a!age )ile#

-0