Lin u x G u i d e La s t revi s e d : 28/03/200 7 By K e v i n Dr y s d a l e © 2 0 0 7 io m a r t

Page 1

Table of Contents
1 2
2. 1 2.2 2.3

Intr o d u c t i o n C o n n e c t i n g to a Li n u x ser v e r
Thi n g s to kn o w bef o r e yo u co n n e c t If yo u ar e usi n g W i n d o w s If yo u ar e usi n g Lin u x , M a c O S X, or an y oth e r U N I X

3
3. 1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9

B a s i c co n c e p t s an d co m m a n d s
Listi n g the co n t e n t s of a dir e c t o r y File o w n e r s h i p s an d per m i s s i o n s A furt h e r w o r d ab o u t se c u r i t y su d o Th e co n t e n t s of the ro ot dir e c t o r y C h a n g i n g an d dis p l a y i n g the curr e n t dir e c t o r y C o p y i n g a file fro m on e pla c e to an o t h e r M o v i n g a file fro m on e pla c e to an o t h e r R e m o v i n g a file Cr e a t i n g a ne w dire c t o r y R e m o v i n g a dire c t o r y Vie w i n g the co n t e n t s of a file E n d- of-se c ti o n su m m a r y

3. 1 0 3. 1 1 3. 1 2 3. 1 3

4
4. 1 4.2 4.3 4.4 4.5

Fu r t h e r co n c e p t s an d co m m a n d s
W o r k i n g wit h m ul ti p l e file s an d dire c t o r i e s si m u l t a n e o u s l y A ca u ti o n a r y w o r d R e m o v i n g dire c t o r i e s wit h o u t m a n u a l l y e m p t y i n g the m first A n o t h e r ca u ti o n a r y w o r d S e a r c h i n g the co n t e n t s of file s

Page 2

4.6 4.7 4.8 4.9 4. 1 0 4. 1 1 4. 1 2 4. 1 3 4. 1 4

S or ti n g the co n t e n t s of file s Fin d i n g a file Pip e s Inp u t an d out p u t re-dire c t i o n C h a n g i n g yo u r pa s s w o r d C h a n g i n g the o w n e r an d gr o u p of a file or dir e c t o r y C h a n g i n g the per m i s s i o n s on a file or dire c t o r y S y m b o l i c link s E n d- of-se c ti o n su m m a r y

5
5. 1 5.2 5.3 5.4 5.5 5.6 5.7 5.8

A d v a n c e d co m m a n d s
sort revi s it e d find revi s it e d grep revi s it e d Th e awk co m m a n d Th e sed co m m a n d S o m e oth e r us e f u l tex t pr o c e s s i n g co m m a n d s Th e man co m m a n d , an d co m m a n d - line hel p E n d- of-se c ti o n su m m a r y

6
6. 1 6.2 6.3 6.4

A d v a n c e d co n c e p t s
Pr o c e s s e s Pr o c e s s m a n a g e m e n t Reso u r c e monitorin g C o m m o n ser v e r soft w a r e 6.4. 1 6.4.2 6.4.3 6.4.4 W e b ser v e r - A p a c h e F T P ser v e r - vsft p d D a t a b a s e ser v e r – M y S Q L E m a i l ser v e r - se n d m a i l

7

Conclu si o n

Page 3

1. dr o p m e a line wit h det a il s of w h a t yo u thin k sh o u l d be incl u d e d an d I will be ha p p y to writ e so m e t h i n g up. Thi s gui d e is co n s t a n t l y un d e r de v e l o p m e n t . or ind e e d w hi c h ar e inc o r r e c t . an d w o r k i n g on fro m the r e to m o r e ad v a n c e d co n c e p t s . Introduction Th e pur p o s e of thi s gui d e to pr o v i d e the re a d e r wit h an intr o d u c t i o n to usi n g Lin u x . Y o u do n’t ne e d an y pri or kn o w l e d g e of eit h e r Lin u x or an y ot h e r U N I X. Page 4 . an d to ba s i c sy st e m s ad m i n i s t r a t i o n . an d so an y an d all fee d b a c k is ver y w el c o m e . ple a s e let m e kn o w . If the r e ar e an y se c ti o n s that in yo u r opi ni o n ar e un cl e a r in an y w a y. Si m i l a r l y if the r e ar e an y topi c s yo u feel that sh o u l d be co v e r e d that pr e s e n t l y ar e not.ba s e d op e r a t i n g sy s t e m to be n e f i t – w e will be star ti n g wit h the ver y ba si c s .

H o w ex a c t l y yo u will est a b l i s h an S S H co n n e c t i o n to the ser v e r de p e n d s on w h e t h e r or not yo u r o w n P C is alr e a d y ru n n i n g Lin u x . Connecting to a Linux server 2. In or d e r to co n n e c t . Th e pa s s w o r d is as s o c i a t e d wit h yo u r us e r n a m e . Y o u r us e r n a m e will al w a y s sta y the sa m e thr o u g h o u t the co u r s e of yo u r tim e wit h the co m p a n y . you should NEV E R give your pas s w ord to anyone ! If so m e o n e els e lear n s yo u r pa s s w o r d . the y m a y be abl e to log in to the Li n u x sy st e m . an d act s as a se c u r e m e a n s of en s u r i n g that yo u ar e the onl y per s o n w h o ca n log in wit h yo u r us e r n a m e .2.the S ec u r e Sh ell – as the soft w a r e that pr o v i d e s this co n n e c t i o n . All file s that yo u o w n or cr e a t e on the ser v e r will be as s o c i a t e d wit h yo u r us e r n a m e alo n e . Th e pa s s w o r d is yo u r PI N nu m b e r – the ad d i t i o n a l co m p o n e n t that onl y yo u kn o w . Y o u ca n ch a n g e yo u r pa s s w o r d to an y t h i n g yo u like – m o r e ab o u t this lat e r. an d ide n t ifi e s yo u to the sy s t e m . so it is in the o r y ext r e m e l y diffi c u l t if not im p o s s i b l e for an y o n e to int e r c e p t an y t h i n g yo u typ e as it tra v e l s fro m yo u r o w n P C to the ho s t Lin u x sy st e m . B y w a y of an ex a m p l e .1 Thing s to know before you connect Th e ver y first st e p in usi n g an y Lin u x sy st e m is to est a b l i s h a co n n e c t i o n to it. yo u will ne e d a username an d a pas s w ord . All m o d e r n U N I X. K e e p i n g yo u r us e r n a m e co n f i d e n t i a l is not so im p o r t a n t . Th e car d is yo u r us e r n a m e – the pu b li c l yvie w a b l e res o u r c e that ide n t i fi e s yo u to the A T M . A s yo u mi g h t ex p e c t fro m the ab o v e . Th e us e r n a m e is uni q u e to yo u. thi n k of usi n g a ba n k car d to wit h d r a w m o n e y fro m a ca s h m a c h i n e . ho w e v e r .ba s e d op e r a t i n g sy s t e m s us e S S H . Inst r u c t i o n s for bot h will be pr o v i d e d her e. an d the log s on the sy s t e m w o u l d indi c a t e that an y t h i n g the y did w a s do n e by yo u. so that ev e n if yo u r car d fall s in to the wr o n g ha n d s yo u r m o n e y is not ac c e s s i b l e by an y thir d par t y. Page 5 . Y o u r us e r n a m e an d pa s s w o r d will be su p p l i e d to yo u by an o t h e r m e m b e r of the sy st e m s ad m i n i s t r a t i o n tea m . S S H en c r y p t s all traffi c that pa s s e s fro m yo u r o w n co m p u t e r to the ser v e r . or if yo u ar e usi n g Wi n d o w s .

H o w e v e r .uk/~sgtatham/putty/download. C h e c k to se e if yo u r P C alr e a d y ha s a pr o g r a m call e d PuTT Y inst a l l e d .org.html 2. O n c e P u T T Y ha s be e n do w n l o a d e d or loc a t e d on yo u r P C.clic k on the P u T T Y ico n. typ e in the ho s t n a m e or IP ad d r e s s of the re m o t e Lin u x sy s t e m yo u w a n t to co n n e c t to. the n yo u do not ne e d to do w n l o a d it. an d is av a il a b l e for do w n l o a d at no co st. do u b l e.chiark. In “Host Name (or IP addres s) ”. A wi n d o w like the follo w i n g will the n ap p e a r : 3.2 If you are using Window s 1. P u T T Y is an S S H clie n t for Wi n d o w s .greenend.2. yo u ca n do w n l o a d it her e: http://www. If yo u r P C alr e a d y ha s P u T T Y inst all e d . Page 6 . if yo u do not se e m to ha v e it alr e a d y .

Ty p e this in als o. an d is ins e c u r e . no w. yo u r us e r n a m e is ca s e. Page 7 .ca s e. sin c e Lin u x disti n g u i s h e s bet w e e n the lo w e r. like m o s t thi n g s in the Lin u x w o r l d. wit h o u t perf o r m i n g an y teln e t or S S H ne g o t i a t i o n bef o r e h a n d .ob s o l e t e m e t h o d of co n n e c t i n g to U N I X. an d pr e s s ret u r n . A wi n d o w si m i l a r to the follo w i n g will the n ap p e a r : 5.4. like yo u r us e r n a m e . A g a i n . an d that S S H is yo u r co n n e c t i o n m e t h o d . R a w co n n e c t i o n s si m p l y m a k e a dir e c t co n n e c t i o n bet w e e n yo u r co m p u t e r an d the re m o t e sy st e m . 7. Thi s m e a n s that if the r e ar e an y ca pit a l lett e r s in yo u r us e r n a m e . an d pr e s s ret u r n .styl e sy s t e m s . Y o u will ne x t be pr o m p t e d for yo u r pa s s w o r d .an d up p e r. this is ca s e se n s i t i v e . N o t e that. yo u m u s t typ e the s e in up p e r. inst e a d of eit h e r “Raw ” or “Telnet ”. O n c e yo u ar e sur e that the ho s t n a m e or IP ad d r e s s is the on e yo u w a n t. clic k the “Open ” butt o n .ca s e vari a n t s of all lett e r s.se n s i t i v e . typ e yo u r us e r n a m e . Tel n e t is an old e r. At the “login as: “ pr o m p t . 6. M a k e sur e that the “S S H ” ra di o butt o n is sel e c t e d . Y o u will al m o s t ne v e r ne e d to us e eit h e r of the s e opti o n s .

us e r n a m e .8. an d pa s s w o r d w e r e all cor r e c t . Page 8 . If yo u r ho s t n a m e . Th a t’ s it ! Y o u ar e no w co n n e c t e d via S S H to the re m o t e Lin u x sy s t e m . yo u will no w ha v e a P u T T Y wi n d o w that loo k s like this: 9.

Aft e r yo u pr e s s ret u r n . 3. Bri n g up yo u r ter m i n a l pr o g r a m of ch oi c e – e. it is ca s ese n s i t i v e).g. In ot h e r w o r d s . 4. At the sh el l pr o m p t . gt e r m . like yo u r us e r n a m e .155.com's password: Ty p e yo u r pa s s w o r d (note that. Ma c OS X. Fo r ex a m p l e .se n s i t i v e .3 If you are using Linux.iomart. yo u will rec e i v e a pa s s w o r d pr o m p t su c h as: drysdalk@stimpy.com drysdalk@stimpy.iomart. 1. like m o s t is ca s e. Th a t’ s it ! Y o u ar e no w log g e d in.an d lo w e r.iomart. yo u w o u l d typ e: ssh drysdalk@stimpy. 2. etc. if yo u m u s t typ e the s e in up p e r. yo u r us e r n a m e it co n t a i n s an y ca pit a l lett e r s.ca s e thin g s in Lin u x . typ e: ssh <username>@<hostname or IP> an d pr e s s ret u r n . as Lin u x disti n g u i s h e s vari a n t s of all lett e r s. bet w e e n the up p e r. xter m .2.iomart.7. an d yo u r ter m i n a l will loo k so m e t h i n g like this: [root@zurg root]# ssh drysdalk@stimpy. sin c e yo u alr e a d y ha v e all the soft w a r e yo u ne e d for an S S H co n n e c t i o n inst all e d on yo u r m a c h i n e .ca s e . ko n s o l e .com's password: Last login: Thu Feb 15 20:11:10 2007 from 10.com It’s im p o r t a n t to not e that. if yo u r us e r n a m e w a s ‘drysdalk’ an d yo u w a n t e d to co n n e c t to ‘stimpy.com’.170 [drysdalk@stimpy drysdalk]$ Page 9 . or any other UNI X If yo u ar e usi n g Li n u x on yo u r P C the pr o c e s s is far si m p l e r .iomart. an d pr e s s ret u r n .

lev e l dir e c t o r y is call e d the root directory . S o. it is a pr o g r a m file w hi c h ca n be ru n. yo u ca n just typ e ls on its o w n to se e the co n t e n t s of the dir e c t o r y yo u ar e cur r e n t l y in: [drysdalk@stimpy drysdalk]$ ls Copy of Redbus Rack Usage. P a g e 10 . an d so m e t h i n g els e – an ent r y call e d slash. At its si m p l e s t .xls Scolocate Rack Usage. Th e r e ar e als o vari o u s se c u r i t y m e c h a n i s m s for rest ri c t i n g ac c e s s to sp e c i f i c us e r s for cert a i n file s an d dir e c t o r i e s . Ba si c concept s and comm a nd s Lik e all m o d e r n op e r a t i n g sy st e m s .xls [drysdalk@stimpy drysdalk]$ IPInformation. script. 3. Th e for w a r dsla s h at the en d of this indi c a t e s that it is an o t h e r dir e c t o r y . rat h e r tha n si m p l y bei n g a dat a file.doc script. ha s an ast e r i s k at the en d. as yo u mi g h t ex p e c t . Th e ver y top. insi d e our cur r e n t dir e c t o r y . Fla g s ar e ext r a opti o n s that w e pa s s to the pr o g r a m s w e us e. w h e n w e r e the y last ch a n g e d ? To w h o m do the y bel o n g ? W h a t sort s of thi n g s ca n w e do wit h the m ? Th e ls co m m a n d ca n tell us this.xls DC1 Rack Usage.xls Corporate Customers with Support. w h a t if w e w a n t m o r e inf or m a t i o n on the s e file s – for ex a m p l e .1 Listing the contents of a directory Y o u ca n vie w the co n t e n t s of an y dir e c t o r y on the sy s t e m wit h the ls co m m a n d . N o w .sh* [drysdalk@stimpy drysdalk]$ slash as follo w s : H e r e w e ca n se e thr e e ot h e r file s insi d e the slash dir e c t o r y . if re q u i r e d . w e ca n se e the co n t e n t s of [drysdalk@stimpy drysdalk]$ ls slash import.xls Redbus Rack Usage.3. Lin u x ke e p s its file s insi d e dir e c t o r i e s . to tell the m to fun c t i o n in a diff e r e n t w a y fro m the def a u l t.csv Report. wit h (co-inci d e n t a l l y) a / at the en d. an d all ot h e r dir e c t o r i e s br a n c h off fro m it. Thi s indi c a t e s that it is ex e c u t a b l e – that is.xls slash/ H e r e w e ca n se e se v e n Ex c e l spr e a d s h e e t s . too. if w e su p p l y it wit h the ap p r o p r i a t e flags .sh.xls DC1 Assett List. O n e of the m .

her e w e ha v e a lot m o r e inf o r m a t i o n ab o u t the s e file s. an d onl y sh o w the dat e. an d is als o as s o c i a t e d wit h a gr o u p .csv Feb 15 21:11 Report. O n e byt e is eq u a l to on e sin g l e ch a r a c t e r (so to stor e the w o r d ‘byt e’. Fil e s m o d i f i e d bef o r e the star t of the cur r e n t ye a r do not sh o w the ti m e. Th e ne x t tw o fiel d s tell us w hi c h user an d group o w n the file (the us e r is the leftha n d fiel d.W h a t w e ne e d her e is to tell ls to giv e us a lon g e r . yo u will als o se e the tim e sta m p in ad d i ti o n to the dat e. but in al m o s t Page 11 . Thi s is do n e wit h the –l fla g: [drysdalk@stimpy drysdalk]$ ls -l total 924 -rwxr-xr-1 drysdalk drysdalk 67584 -rwxr-xr-1 drysdalk drysdalk 27136 -rwxr-xr-1 drysdalk drysdalk 17408 drwxrwxr-x 2 drysdalk drysdalk 4096 [drysdalk@stimpy drysdalk]$ ls -l slash total 0 -rw------1 drysdalk sys 12662 -rw------1 drysdalk sys 24910 -rwx-----1 drysdalk sys 82 [drysdalk@stimpy drysdalk]$ Mar Mar Jan Feb 27 2006 deprov.digit nu m b e r for all the file s w e’ v e loo k e d at. Let’s loo k at w h a t ea c h of the s e extr a bit s of dat a m e a n s . It get s a little m o r e co m p l i c a t e d no w .sh* 14 20:10 dns.sh* 27 2006 easyshare. ev e r y file on a Lin u x sy s t e m is o w n e d by on e sin g l e us e r on the sy st e m . m o r e det a il e d dir e c t o r y listi n g. Fo r no w w e’ll ign o r e this – w e’ll dis c u s s it ag a i n m u c h lat er. Fo r se c u r i t y pur p o s e s .sh* N o w . the gr o u p is the rig ht. If a file ha s be e n ch a n g e d in the cur r e n t ye a r.rig ht col u m n sh o w s the na m e of ea c h file.doc Feb 15 21:12 script.2 File ownership s and permis sion s S o far. All us e r s on the sy st e m ar e the m s e l v e s m e m b e r s of at lea s t on e gr o u p . W e will star t at the farrig h t. an d w o r k our w a y al o n g to the left. or to the o w n e r an d m e m b e r s of the gr o u p to w hi c h the file als o bel o n g s .sh* 15 21:12 slash/ Feb 15 21:12 import. so go o d . A c c e s s to file s ca n be rest ri c t e d to onl y the o w n e r . yo u w o u l d ne e d 4 byt e s). in byt e s. Th e ne x t fiel d co n t a i n s a nu m b e r – this is the siz e of the file. 3. Th e ne x t pie c e of dat a is the dat e an d/or tim e that the file w a s last m o d i f i e d .ha n d). Th e far. just as it ap p e a r e d bef o r e . Th e ne x t fiel d is a sin g l e. Th e first thi n g yo u will noti c e is that ea c h file no w ha s its o w n de d i c a t e d line in the listi n g.

as w ell as w h a t all ot h e r us e r s on the sy st e m w h o ar e not a m e m b e r of the gr o u p ca n do. Th e fin al fiel d is als o part of ho w Lin u x de a l s wit h file se c u r i t y. Thi s fiel d is ar g u a b l y the m o s t co m p l e x in the listin g. w W r it e ac c e s s . the file ca n be writt e n to. so w e will loo k at it in m o r e det a il. the file ca n be op e n e d for re a d. an d if the file is a vali d bin a r y ex e c u t a b l e or scri p t. it is po s s i b l e to sp e c i f y pr e c i s e l y w h a t the o w n e r us e r an d gr o u p ca n do wit h the file. x Ex e c u t e ac c e s s . ac c e s s of the sp e c i f i c typ e the ch a r a c t e r re pr e s e n t s is de n i e d for the Page 12 . It sh o w s the permis sion s on the file or dir e c t o r y in qu e s t i o n . If this is set. the s e br e a k do w n as foll o w s : Gr o u p 1 – Th e per m i s s i o n s for the owner of the file Gr o u p 2 – Th e per m i s s i o n s for the group the file is as s o c i a t e d wit h Gr o u p 3 – Th e per m i s s i o n s for everyone else on the sy st e m Th e act u a l ch a r a c t e r s the m s e l v e s al w a y s ap p e a r in the follo w i n g or d e r .onl y ac c e s s .to-da y us e for it. In ad d i ti o n to rest ri c t i n g ac c e s s to file s ba s e d on the us e r or gr o u p that o w n s the m . w e will br e a k it in to blo c k s as foll o w s : rwx 1 r-x 2 r-- 3 Ign o r i n g the first of the s e fiel d s (the sin gl e. If thi s is set. an d al w a y s ha v e the foll o w i n g m e a n i n g s : r R e a d ac c e s s .ch a r a c t e r on e). H e r e ar e the per m i s s i o n s for ea c h of the file s in the cur r e n t dir e c t o r y : -rw-r-xr-- To m a k e un d e r s t a n d i n g thi s ea si e r .all ca s e s yo u’ll ne v e r ne e d to loo k at this field or ha v e an y da y. it ca n be run as a pr o g r a m . If thi s is set. – A da s h indi c a t e s that the ap p r o p r i a t e per m i s s i o n is not set – in ot h e r w o r d s .

file. Page 13 .

Th e up s h o t of all this. In ot h e r w o r d s . an d ev e r y o n e els e ha s rea d. ev e n if it is a vali d pr o g r a m . the n. the y ex e c u t a b l e for the o w n e r of the file rea d per m i s s i o n is set. but ca n n o t ex e c u t e it. Th e y ca n n o t m a k e an y ch a n g e s to it. w hi c h det e r m i n e s the per m i s s i o n s for ev e r y o n e els e. ho w e v e r .csv -rw------1 drysdalk sys 24910 Feb 15 21:11 Report. rea d s : r-- S o ev e r y o n e els e on the sy st e m ca n re a d the file.sh* [drysdalk@stimpy drysdalk]$ Page 14 . the o w n e r ha s rea d. sin c e the y do not ha v e writ e ac c e s s . w o r k i n g file) the y ca n ru n it as a pr o g r a m . an d if it is a vali d pr o g r a m ca n als o ru n it. m e m b e r s of the file’s gr o u p ca n rea d an d ex e c u t e the m . Gr o u p 2 sh o w s us the per m i s s i o n s that ot h e r m e m b e r s of the file’s gr o u p ha v e : r-x R e a d an d ex e c u t e ac c e s s – so m e m b e r s of the gr o u p ca n se e w h a t is in the file.doc -rwx-----1 drysdalk sys 82 Feb 15 21:12 script.onl y ac c e s s . Gr o u p 1: rwx tell s us that per m i s s i o n file’s o w n e r is in it. writ e is set. thi n g s ar e diff e r e n t w h e n w e loo k at the per m i s s i o n s on the co n t e n t s of the slash/ dir e c t o r y . an d ex e c u t e per m i s s i o n is set. Gr o u p 3. N o r ca n the y m a k e an y ch a n g e s to it. To rec a p the rele v a n t porti o n : [drysdalk@stimpy drysdalk]$ ls -l slash total 0 -rw------1 drysdalk sys 12662 Feb 15 21:12 import. the ca n do an y t h i n g the y like to it – the y ca n op e n it to se e w h a t ca n ch a n g e its co n t e n t s . an d (so lon g as it is a vali d. is that for all the file s in the cur r e n t dir e c t o r y (whic h yo u will se e ha v e the sa m e per m i s s i o n s).S o. N o w . writ e an d ex e c u t e ac c e s s to the m .

3. w e ha v e no re a d. or ev e n re m o v e entir e l y. ev e n if the y ar e a m e m b e r of the sys gr o u p . H o w e v e r . the r e ar e cert a i n sy s t e m s ad m i n i s t r a t i o n tas k s that onl y root ca n car r y out. REALLY have to ! U n til yo u ar e ver y co m f o r t a b l e wit h the da y. the r e is a w a y to bri d g e the ga p bet w e e n reg u l a r us e r ac c o u n t s an d the su p e r u s e r ac c o u n t . A s yo u mi g h t im a g i n e . To su m m a r i s e the per m i s s i o n s on import. w e ha v e rea d an d writ e per m i s s i o n . no dir e c t o r y . for the file’s o w n e r . an d ha s the us e r n a m e of root . Th e les s o n to tak e fro m this is: Do not log on as root unless you really. A s root.csv w e ha v e : - rw. the file’s o w n e r . writ e or ex e c u t e ac c e s s .on e els e on the sy st e m ca n do an y t h i n g at all wit h it. no co m p o n e n t of the sy s t e m that yo u ca n n o t ad d to.3 A further word about security Li n u x .--— S o.csv. it is be s t to av oi d the root ac c o u n t alt o g e t h e r . an d onl y us e the el e v a t e d pri vil e g e s of the su p e r u s e r ac c o u n t w h e n yo u w a n t to. Th e root ac c o u n t by p a s s e s all the se c u r i t y ch e c k s that the op e r a t i n g sy s t e m nor m a l l y car ri e s out to pr e v e n t us e r s fro m m o d i f y i n g part s of the sy st e m that the y ar e not all o w e d to. an d for bot h the m e m b e r s of the file’s gr o u p an d for ev e r y o n e els e.--. an d the ac c o u n t us e d for sy s t e m s ad m i n i s t r a t i o n . ch a n g e . Page 15 . drysdalk. ha s re a d an d writ e ac c e s s . yo u ca n liter a ll y do an y t h i n g – ther e is no file. Thi s sp e c i a l ac c o u n t is call e d the superuser account . m a k e s a cle a r disti n c t i o n bet w e e n the lev e l of tru s t giv e n to re g u l a r us e r s of a sy st e m .styl e op e r a t i n g sy st e m s .to-da y us a g e of a Lin u x sy s t e m an d car r y i n g out ba s i c sy st e m s ad m i n i s t r a t i o n tas k s . it is just as tru e that it is entir e l y po s s i b l e to ac ci d e n t a l l y do a gr e a t de a l of da m a g e to a Lin u x sy st e m if yo u ar e not ver y car e f u l w h e n log g e d in as root. N o. H o w e v e r . Th e r e is a Lin u x pr o g r a m that allo w s yo u to log on wit h yo u r o w n us e r ac c o u n t . for import.A g a i n ign o r i n g the ver y first ch a r a c t e r . like all U N I X.

Y o u’r e do n e wit h it no w . the file is no w go n e .csv [drysdalk@stimpy files]$ ls -l total 0 [drysdalk@stimpy files]$ A s yo u ca n se e. Page 16 .csv'? y rm: cannot remove `file.3. in or d e r to re m o v e this file. S o. Th e ide a is that yo u sh o u l d sp e n d al m o s t all yo u r tim e log g e d in wit h the rig ht s of a reg u l a r us e r.csv': Permission denied [drysdalk@stimpy files]$ A s yo u ca n se e fro m the out p u t of ls. the file is o w n e d by root. so w h e n yo u try to del e t e it. yo u ca n n o t – this is the w h o l e poi n t of file per m i s s i o n s . it w a s run as root. an d yo u try to re m o v e a file that is not o w n e d by yo u an d w hi c h yo u do not ha v e writ e per m i s s i o n to. w e will ne e d to m a k e us e of the sp e c i a l pri vil e g e s as s o c i a t e d wit h the root ac c o u n t by usi n g sudo to ru n rm.4 sudo Th e pr o g r a m that m a k e s this po s s i b l e is call e d sudo . W h e n yo u ar e log g e d on as a reg u l a r us e r. an d ev e r y o n e els e ca n onl y re a d fro m it. an d no lon g e r ne e d it. H o w e v e r . the follo w i n g ha p p e n s : [drysdalk@stimpy files]$ ls -l total 4 -rw-r--r-1 root root 170 Feb 15 20:50 file. [drysdalk@stimpy files]$ sudo rm file.csv [drysdalk@stimpy files]$ rm file. so yo u de ci d e to re m o v e it. as pr e v i o u s l y m e n t i o n e d . Thi s gr e a t l y red u c e s the ch a n c e s of yo u ac ci d e n t a l l y doi n g so m e t h i n g that co ul d da m a g e the sy st e m . an d so w a s abl e to re m o v e the file that yo u did not ha v e ac c e s s to yo u r s e l f .csv rm: remove write-protected regular file `file. an o t h e r m e m b e r of the sy st e m s ad m i n i s t r a t i o n tea m co p i e d a file in to yo u r ho m e dir e c t o r y on stimpy. W h e n rm w a s ru n via sudo. or ha v e co n s e q u e n c e s that yo u did not int e n d . Fo r ex a m p l e : a w hil e ag o. an d onl y m a k e us e of the privil e g e s of the ro ot ac c o u n t w h e n the r e is a par ti c u l a r co m m a n d yo u ne e d to us e that req u i r e s the m . an d not writ e. Th e co m m a n d for del e t i n g file s is rm. the file is o w n e d by root. It allo w s yo u to car r y out cert a i n sp e c i f i c tas k s as the su p e r u s e r .

dir e c t o r y that ha p p e n s to ha v e the na m e root/.lev e l dir e c t o r y on the sy s t e m . an d ha v e thei r o w n parti c u l a r us e. H e r e ar e the int e n d e d pur p o s e s of the m o s t im p o r t a n t of the m : ( O h. Thi s is re p r e s e n t e d by a sin g l e / ch a r a c t e r . boot/ All the criti c a l file s that a Lin u x ser v e r ne e d s to star t up ar e loc a t e d in her e. w hi c h is al w a y s re pr e s e n t e d sol e l y by / ) bin/ U s e d for st ori n g the pr o g r a m s yo u will co m m o n l y w a n t to us e – this is w h e r e thi n g s like ls an d mv live. dev/ Insi d e her e ar e file s that allo w the sy s t e m to ac c e s s the har d w a r e of the ph y s i c a l ser v e r – the har d driv e s . an d do n’t be co n f u s e d by the dir e c t o r y call e d root/ un d e r n e a t h the / dir e c t o r y its elf – this is si m p l y a su b. an d is the dir e c t o r y that yo u star t off in w h e n yo u first log in. home/ E a c h us e r on a Lin u x sy s t e m ha s w h a t is call e d their o w n home directory . /home is the def a u l t loc a t i o n un d e r n e a t h w hi c h the s e ho m e dir e c t o r i e s ar e loc a t e d . S o if w e w a n t to se e the co n t e n t s of the ro ot dir e c t o r y .5 The contents of the root directory A s yo u mi g h t rec a l l. Thi s is a dir e c t o r y that is as s o c i a t e d wit h the m sp e c i f i c a l l y. sy s t e m m e m o r y . Th e m a j o r i t y of the s e dir e c t o r i e s ar e co m m o n to all Lin u x an d U N I X. Page 17 . all dir e c t o r i e s on a Lin u x sy st e m ar e loc a t e d un d e r n e a t h the ro ot dir e c t o r y . w e ca n typ e: [drysdalk@stimpy drysdalk]$ ls / bin/ dev/ home/ lib/ boot/ etc/ initrd/ lost+found/ [drysdalk@stimpy drysdalk]$ misc/ mnt/ opt/ proc/ root/ sbin/ tmp/ usr/ var/ H e r e w e se e m a n y ot h e r dir e c t o r i e s loc a t e d wit hi n the root dir e c t o r y . etc/ Thi s is w h e r e all the ke y co n f i g u r a t i o n file s for the sy st e m ar e st or e d .styl e sy s t e m s . w hi c h is the ver y hig h e s t. an d is not the ro ot dir e c t o r y . U S B de v i c e s .3. an d so on.

Tr a d i t i o n a l l y . or an y ot h e r thir d.inst al l e d pr o g r a m s that ar e not a cor e part of the sy st e m ar e inst a l l e d her e. so that w h e n soft w a r e de v e l o p e r s ar e writi n g pr o g r a m s the y do not ha v e to writ e routi n e s to tell their pr o g r a m s ho w to.lib/ Thi s is w h e r e sy st e m libr a r y file s ar e ke p t. Thi s line ha s be e n blur r e d so m e w h a t in rec e n t ye a r s an d ther e is no w quit e a bit of cr o s s o v e r bet w e e n /bin an d /sbin. Th e s e ar e bin a r y. usr/ U s e r. writ e file s to dis k or to pri nt to the scr e e n . Th e per m i s s i o n s on /tmp ar e su c h that an y o n e ca n cr e a t e an y t h i n g the y like in it. R a t h e r . like /bin.rea d a b l e fas h i o n . for ex a m p l e . proc/ Inf o r m a t i o n ab o u t the run n i n g sy st e m ca n be fou n d in her e – tho u g h not al w a y s in a hu m a n. tmp/ Te m p o r a r y file s ar e ke p t in her e. the y ca n call fun c t i o n s for the s e pur p o s e s co n t a i n e d wit hi n the sy st e m libr a r i e s . ho w the dis c driv e s in the sy st e m ar e bei n g ac c e s s e d . Page 18 . w h a t har d w a r e is in us e by the sy s t e m . an d m a k e s up d a t i n g the s e fun c t i o n s acr o s s all pr o g r a m s ea s i e r . Th e y co n t a i n inf or m a t i o n ab o u t ho w to car r y out co m m o n tas k s.re a d a b l e file s that stor e inf or m a t i o n that the rest of the pr o g r a m s on the sy s t e m ca n m a k e us e of. It is m e a n t to be a dir e c t o r y that pr o g r a m s ca n saf e l y writ e to wit h o u t per m i s s i o n s getti n g in the w a y. or sp e c i f i c a l l y for sy st e m s ad m i n i s t r a t i o n pur p o s e s . but that’ s the ide a be h i n d it. an d so on. U s u a l l y the bin a r y co m p o n e n t s of soft w a r e su c h as W e b ser v e r s .part y pr o g r a m that is not dir e c t l y par t of the op e r a t i n g sy st e m itself will be inst a ll e d her e.lin e pr o g r a m s ar e loc a t e d . Thi s ke e p s the siz e s of their o w n pr o g r a m s do w n . is an o t h e r dir e c t o r y wit hi n w hi c h co m m a n d . but the y ca n onl y re m o v e ite m s that the y cr e a t e d . sbin/ Thi s. m a i l ser v e r s . no nhu m a n. ho w e v e r . Sy s t e m utilit y pr o g r a m s us e the inf o r m a t i o n in her e to fin d out ho w m u c h m e m o r y is av ail a b l e . if the y ne e d to cr e a t e file s in the ba c k g r o u n d in the co u r s e of doi n g w h a t e v e r the sy s t e m ’ s us e r s re q u i r e of the m . this w o u l d be us e d for tho s e pr o g r a m s that w o u l d be ru n by root onl y.

an d pri nt our cur r e n t loc a t i o n . ch a n g e in to a dir e c t o r y w e fin d wit hi n it.var/ /var w a s ori gi n a l l y int e n d e d to st or e tho s e file s w hi c h w o u l d be vari a b l e – that is. M o s t oft e n it is us e d for stori n g inc o m i n g e-m a il for m a il ser v e r s . w h o s e co n t e n t s or exi st e n c e w o u l d ch a n g e duri n g the ru n n i n g of the sy s t e m . an d sp e c i a l te m p o r a r y file s that ar e us e d to det e r m i n e w h a t pr o g r a m s ar e run n i n g at an y giv e n tim e on the sy s t e m . w h a t if w e w a n t to kn o w w h a t dir e c t o r y w e ar e in ? Thi s is do n e wit h the pwd co m m a n d . w e ch a n g e to the ro ot dir e c t o r y . N o w if w e w a n t to loo k in on e of the m . In the foll o w i n g ex a m p l e . w e ca n ag a i n us e ls: [drysdalk@stimpy drysdalk]$ ls adamh/ aroberts/ colinn/ agoodall/ ben/ colinw/ anne/ callum/ davidh/ [drysdalk@stimpy drysdalk]$ /home derek/ drysdalk/ graemep/ iainr/ ian/ markd/ patc/ paulj/ rcassidy/ richard/ tomd/ H e r e w e se e the ho m e dir e c t o r i e s for ea c h of the loc a l us e r s set up on the sy st e m . but w h a t if w e w a n t to act u a l l y m o v e fro m on e dir e c t o r y to an o t h e r ? Thi s is ac h i e v e d wit h the cd co m m a n d . an d tak e a dir e c t o r y listi n g. W e the n list the co n t e n t s of /tmp. pri nt job s for de s k t o p sy s t e m s . Si m il a r l y. [drysdalk@stimpy drysdalk]$ cd / [drysdalk@stimpy /]$ ls bin/ dev/ home/ lib/ boot/ etc/ initrd/ lost+found/ [drysdalk@stimpy /]$ ls tmp foo/ lost+found/ [drysdalk@stimpy /]$ cd /tmp/foo [drysdalk@stimpy foo]$ pwd /tmp/foo [drysdalk@stimpy foo]$ misc/ mnt/ opt/ proc/ root/ sbin/ tmp/ usr/ var/ Page 19 . W e b sit e co n t e n t for W e b ser v e r s . 3.6 Chan gin g and displaying the current directory W e ha v e fairl y w ell co v e r e d ho w to se e w h a t is in an y dir e c t o r y by this poi n t. that co v e r s w h a t ea c h of the s e dir e c t o r i e s be n e a t h / ar e for. S o.

Al s o. sin c e w e w e r e alr e a d y in the root dir e c t o r y ? C o u l d w e ha v e ch a n g e d in to tmp. /]$ pwd P a g e 20 .co ul d n’ t w e ha v e o m i t t e d the initi al /. the dir e c t o r y that is on e ‘up’ in the tre e fro m yo u r pr e s e n t loc a t i o n is rep r e s e n t e d by tw o dot s. S o if yo u w a n t e d to m o v e up to the root dir e c t o r y inst e a d of ret u r n i n g ho m e .. an d the n in to foo ? Th e an s w e r in ea c h ca s e is ye s: [drysdalk@stimpy drysdalk]$ cd / [drysdalk@stimpy /]$ ls tmp foo/ lost+found/ [drysdalk@stimpy /]$ cd tmp/foo [drysdalk@stimpy foo]$ pwd /tmp/foo [drysdalk@stimpy foo]$ [drysdalk@stimpy drysdalk]$ cd / [drysdalk@stimpy /]$ ls tmp foo/ lost+found/ [drysdalk@stimpy /]$ cd tmp [drysdalk@stimpy tmp]$ cd foo [drysdalk@stimpy foo]$ pwd /tmp/foo [drysdalk@stimpy foo]$ Y o u ca n m o v e ba c k to yo u r ho m e dir e c t o r y at an y tim e by typi n g its o w n : [drysdalk@stimpy /home/drysdalk [drysdalk@stimpy [drysdalk@stimpy /tmp [drysdalk@stimpy [drysdalk@stimpy /home/drysdalk [drysdalk@stimpy drysdalk]$ pwd drysdalk]$ cd /tmp tmp]$ pwd tmp]$ cd drysdalk]$ pwd drysdalk]$ cd on Y o u ca n als o ret u r n ho m e by typi n g cd ~ (cd follo w e d by a tild e sy m b o l).W h y di d w e ha v e to sp e c i f y that w e w a n t e d to ex p li c itl y ch a n g e to /tmp/foo w h e n w e w e r e alr e a d y in the root dir e c t o r y . at all ti m e s . yo u co ul d typ e: [drysdalk@stimpy /home/drysdalk [drysdalk@stimpy [drysdalk@stimpy /tmp [drysdalk@stimpy [drysdalk@stimpy / drysdalk]$ pwd drysdalk]$ cd /tmp tmp]$ pwd tmp]$ cd .

txt [drysdalk@stimpy drysdalk]$ ls drysdalk]$ mv file.txt [drysdalk@stimpy [drysdalk@stimpy newname.txt files drysdalk]$ ls drysdalk]$ ls files drysdalk]$ 3.txt [drysdalk@stimpy [drysdalk@stimpy files/ file.[drysdalk@stimpy /]$ S o no w w e kn o w ho w to m o v e fro m on e dir e c t o r y to an o t h e r .txt in to the files/ dir e c t o r y . w e ca n us e the mv co m m a n d . w h e r e bot h ar e loc a t e d in our ho m e dir e c t o r y : [drysdalk@stimpy files/ file. w e m o v e the file test. to list the co n t e n t s of dir e c t o r i e s .txt files drysdalk]$ ls drysdalk]$ ls files drysdalk]$ Thi s is als o ho w w e re-na m e file s an d dir e c t o r i e s in Lin u x (if yo u thin k ab o u t it.txt newname. w e co p y the file test.txt [drysdalk@stimpy drysdalk]$ ls drysdalk]$ cp file.8 Moving a file from one place to another To m o v e a file fro m on e dir e c t o r y to an o t h e r .7 Copying a file from one place to another To co p y a file to a ne w loc a t i o n . w e us e the cp co m m a n d .txt [drysdalk@stimpy drysdalk]$ ls drysdalk]$ mv file.t xt in to the file/ dir e c t o r y .9 Removin g a file P a g e 21 .txt [drysdalk@stimpy file. 3.txt [drysdalk@stimpy [drysdalk@stimpy files/ [drysdalk@stimpy file. In the foll o w i n g ex a m p l e . an d to ch e c k w h e r e w e ar e at an y giv e n tim e.txt drysdalk]$ ls drysdalk]$ 3. re-na m i n g a file is just ‘mo vi n g’ it fro m its old na m e to its ne w na m e): [drysdalk@stimpy file. w h e r e bot h ar e loc a t e d in our ho m e dir e c t o r y : [drysdalk@stimpy files/ file. In the foll o w i n g ex a m p l e .

.A n d as pr e v i o u s l y se e n .csv [drysdalk@stimpy drysdalk]$ rmdir files rmdir: `foo': Directory not empty [drysdalk@stimpy drysdalk]$ S o w e ne e d to m a n u a l l y re m o v e the co n t e n t s of files/ bef o r e w e ca n re m o v e the dir e c t o r y its elf: [drysdalk@stimpy drysdalk]$ files/ more_files/ [drysdalk@stimpy drysdalk]$ import. w h e n w e try to re m o v e it w e rec e i v e the follo w i n g err o r: [drysdalk@stimpy drysdalk]$ ls files import.csv [drysdalk@stimpy drysdalk]$ [drysdalk@stimpy files]$ rm [drysdalk@stimpy files]$ cd P a g e 22 ls ls files cd files import. w e ca n re m o v e file s wit h the [drysdalk@stimpy files/ file..csv .txt [drysdalk@stimpy [drysdalk@stimpy files/ [drysdalk@stimpy drysdalk]$ ls drysdalk]$ rm file.10 Creating a new directory W e ca n cr e a t e ne w dir e c t o r i e s wit h the mkdir co m m a n d : [drysdalk@stimpy test]$ ls files/ [drysdalk@stimpy test]$ mkdir more_files [drysdalk@stimpy test]$ ls files/ more_files/ [drysdalk@stimpy test]$ 3.e m p t y dir e c t o r i e s wit h [drysdalk@stimpy drysdalk]$ ls files/ more_files/ [drysdalk@stimpy drysdalk]$ rmdir more_files [drysdalk@stimpy drysdalk]$ ls files/ [drysdalk@stimpy drysdalk]$ rmdir: N o w w h a t if a dir e c t o r y is not alr e a d y e m p t y ? In that ca s e .txt drysdalk]$ ls drysdalk]$ rm co m m a n d : 3.11 Removin g a directory A n d w e ca n re m o v e alr e a d y.

txt This is the text inside file.[drysdalk@stimpy drysdalk]$ rmdir files [drysdalk@stimpy drysdalk]$ ls more_files/ [drysdalk@stimpy drysdalk]$ 3.12 Viewin g the contents of a file Y o u ca n vie w the co n t e n t s of an y file on the sy st e m that yo u ha v e rea d ac c e s s to wit h the cat co m m a n d : [drysdalk@ioprov2 drysdalk]$ ls file.txt [drysdalk@ioprov2 drysdalk]$ cat file.txt [drysdalk@ioprov2 drysdalk]$ P a g e 23 .

S e e the co n t e n t s of the ro ot dir e c t o r y .3. in this se c ti o n w e ha v e lear n e d ho w to: .13 End.R e.R e m o v e an alr e a d y.of-section summ ary S o. REALLY have to ! . To rec a p .Vi e w the co n t e n t s of a file P a g e 24 .S e e an d un d e r s t a n d file o w n e r s h i p s an d per m i s s i o n s .R e m o v e a file .List the co n t e n t s of a dir e c t o r y .Not to use the root account unles s you really. an d un d e r s t a n d their pur p o s e .C o p y a file fro m on e pl a c e to an o t h e r .na m e a file or dir e c t o r y .e m p t y dir e c t o r y .U s e sudo to saf e l y ru n co m m a n d s as root inst e a d .Cr e a t e a ne w dir e c t o r y .C h a n g e fro m on e dir e c t o r y to an o t h e r . that’s the ver y ba si c s .M o v e a file or dir e c t o r y to a ne w loc a t i o n .

Li n u x pr o v i d e s a w a y for yo u to do this via the us e of wildcards . w e ca n us e a wil d c a r d to re m o v e all the s e file s at on c e . 4. yo u co u l d re m o v e ea c h of the s e file s in tur n wit h the r m co m m a n d . an d m o r e be s i d e s . ho w to set the per m i s s i o n s . or to ev e r y file wit h cert a i n ch a r a c t e r s in its na m e . In Lin u x .1 Working with multiple files and directories simultaneou sly At ti m e s . wit h o u t ha v i n g to sp e c i f y in ad v a n c e ex a c t l y w h a t tho s e ch a r a c t e r s sh o u l d be. Y o u will lear n ho w to w o r k wit h m u l ti p l e file s an d dir e c t o r i e s at on c e . Fo r ex a m p l e – in yo u r ho m e dir e c t o r y . it is co n v e n i e n t to be abl e to ref e r to a w h o l e gr o u p of file s in on e go. par ti c u l a r l y if the r e is on e sp e c i f i c thin g that yo u ne e d to do to ev e r y file in a dir e c t o r y . S o. to re m o v e all the ch a r a c t e r s in our ho m e dir e c t o r y . Inst e a d . A wil d c a r d is a sp e c i a l sy m b o l us e d at the co m m a n d line to re pr e s e n t on e or m o r e ch a r a c t e r s . o w n e r an d gr o u p on file s an d dir e c t o r i e s . the wil d c a r d yo u will us e the m o s t oft e n is * (an ast e r i s k). but this w o u l d be a ver y lon g an d clu n k y co m m a n d to typ e. an d yo u ne e d to re m o v e the m all: [drysdalk@ioprov2 drysdalk]$ ls file file10 file12 file14 file2 file1 file11 file13 file15 file3 [drysdalk@ioprov2 drysdalk]$ file4 file5 file6 file7 file8 file9 N o w . w e will ex p a n d on w h a t w e co v e r e d in S e c t i o n 3. yo u ha v e the follo w i n g file s. Th e ast e r i s k in all U N I X. Further concept s and comm a nd s In this se ct i o n .styl e op e r a t i n g sy st e m s m a t c h e s zer o or m o r e ch a r a c t e r s .4. w e co u l d typ e: [drysdalk@ioprov2 drysdalk]$ ls file file10 file12 file14 file2 file1 file11 file13 file15 file3 file4 file5 file6 file7 file8 file9 P a g e 25 .

[drysdalk@ioprov2 drysdalk]$ rm * [drysdalk@ioprov2 drysdalk]$ ls [drysdalk@ioprov2 drysdalk]$ A n d as yo u ca n se e. P a g e 26 . the y ar e no w all go n e .

but the sh ell scri p t s saf e l y re m a i n .txt script1. file* to re m o v e all file s that be g a n wit h the w o r d ‘file’. G o i n g ba c k to our first ex a m p l e .txt script2.sh* [drysdalk@ioprov2 drysdalk]$ file5. im a g i n e a m o r e co m p l i c a t e d sc e n a r i o .sh an d script2.sh* script2.txt file4.txt script1. P a g e 27 .sh* or aft e r a w e co ul d sp e c i f y an d the n ha d poi n t on w a r d .txt file3.N o w .txt file5. in this ca s e . but w e w a n t to ke e p the sh e ll scri p t s script1.sh* [drysdalk@ioprov2 drysdalk]$ file4. W e co u l d ha v e do n e so in the foll o w i n g w a y: [drysdalk@ioprov2 drysdalk]$ ls file file11 file13 file15 file3 file5 file7 file9 file10 file12 file14 file2 file4 file6 file8 [drysdalk@ioprov2 drysdalk]$ rm file1* [drysdalk@ioprov2 drysdalk]$ ls file file2 file3 file4 file5 file6 file7 file8 file9 S o w e ar e left wit h all file s ex c e p t tho s e w h o s e na m e s be g i n wit h file1.sh* W e ar e do n e wit h ea c h of the text file s. A n d no w the text file s ar e go n e . It is po s s i b l e to sp e c i f y a set of ch a r a c t e r s eit h e r bef o r e wil d c a r d to qu a l if y it furt h e r .sh.txt file2. zer o or m o r e furt h e r ch a r a c t e r s in their na m e fro m that Fo r ex a m p l e : [drysdalk@ioprov2 drysdalk]$ ls file1.txt file2. let’s sa y w e ha d onl y w a n t e d to re m o v e all the file s fro m file10 up w a r d s .txt script2. W e ha v e the follo w i n g file s in our ho m e dir e c t o r y : [drysdalk@ioprov2 drysdalk]$ ls file1.sh* [drysdalk@ioprov2 drysdalk]$ rm file* [drysdalk@ioprov2 drysdalk]$ ls script1. For ex a m p l e .txt file3.

the en d res u l t is ide n t i c a l.txt file4.txt script1. an d not the text file s. Wil d c a r d s ca n w o r k wit h an y co m m a n d at all.sh* -rwxr-xr-x 1 drysdalk drysdalk 24 Feb 16 14:45 script2.sh [drysdalk@ioprov2 drysdalk]$ ls -l script* -rwxr-xr-x 1 drysdalk drysdalk 54 Feb 16 14:45 script1.sh* [drysdalk@ioprov2 drysdalk]$ file5.sh* script3.sh* [drysdalk@ioprov2 drysdalk]$ rm fi*txt [drysdalk@ioprov2 drysdalk]$ ls script1.Wil d c a r d s ca n als o co m e at the st art of a file n a m e .sh* file2.txt script1.txt file3.txt file4. too. tho u g h not quit e as oft e n as the ast e r i s k . allo w i n g yo u to sp e c i f y that yo u w a n t to w o r k wit h all file s w h o s e na m e ha s a cert a i n en d i n g .sh* A n d the res u l t is the sa m e .txt file2. be c a u s e the us e of the qu a l i fi e d wil d c a r d onl y m a t c h e d the m .txt script2. w e co u l d ha v e typ e d : [drysdalk@ioprov2 drysdalk]$ ls file1.txt file2.sh* O n c e ag a i n . wil d c a r d s ca n go an y w h e r e in a file n a m e at all: [drysdalk@ioprov2 drysdalk]$ ls file1.txt script2. Th e r e is on e ot h e r wil d c a r d that yo u mi g h t so m e t i m e s ha v e to us e.sh* script2.txt script2. unli k e the ast e r i s k .sh* [drysdalk@ioprov2 drysdalk]$ rm *txt [drysdalk@ioprov2 drysdalk]$ ls script1. reg a r d l e s s of thei r be g i n n i n g . but onl y for the sh e ll scri p t s an d not the text file s: [drysdalk@ioprov2 drysdalk]$ ls file1.txt file5.sh* [drysdalk@ioprov2 drysdalk]$ file5. Th a t’ s ? (a qu e s t i o n m a r k). w hi c h m a t c h e s fro m zer o to an y nu m b e r of ch a r a c t e r s .txt file3.txt file3.txt file4.sh* -rw-rw-r-1 drysdalk drysdalk 189 Feb 16 14:45 script3. A qu e s t i o n m a r k m a t c h e s on e single ch a r a c t e r .txt script1. Let’s sa y w e w a n t e d a lon g dir e c t o r y listi n g.sh* script2. In fact. P a g e 28 . S o ag a i n in our ex a m p l e of w a n t i n g to ke e p the sh el l scri p t s but dis c a r d ev e r y t h i n g els e.sh [drysdalk@ioprov2 drysdalk]$ W e onl y sa w a lon g dir e c t o r y listi n g for the sh ell scri p t s an d not the file s.

S o inst e a d : [drysdalk@ioprov2 drysdalk]$ ls file1 file11 file13 file15 file3 file5 file7 file9 file10 file12 file14 file2 file4 file6 file8 [drysdalk@ioprov2 drysdalk]$ rm file?? [drysdalk@ioprov2 drysdalk]$ ls file1 file2 file3 file4 file5 file6 file7 file8 file9 [drysdalk@ioprov2 drysdalk]$ S o as yo u ca n se e. an d lea v e s us wit h onl y w h a t w e w a n t e d . w e ca n co m b i n e ? wild c a r d s to m a t c h a se q u e n c e of sin g l e. W h a t if w e w a n t e d to onl y re m o v e the file s that ha d a sin g l e.Let’s loo k at our ex a m p l e of fifte e n file s in a dir e c t o r y on c e ag a i n . be c a u s e that w o u l d re m o v e all of the m . w e ca n do this: [drysdalk@ioprov2 drysdalk]$ ls file1 file11 file13 file15 file10 file12 file14 file2 [drysdalk@ioprov2 drysdalk]$ rm [drysdalk@ioprov2 drysdalk]$ ls file10 file11 file12 file13 [drysdalk@ioprov2 drysdalk]$ file3 file4 file? file14 file5 file6 file15 file7 file8 file9 Thi s giv e s the de si r e d res u l t. Fi n a l l y. an d lea v e the do u b l e. an d w h o s e na m e en d e d wit h wi p e. N o w w h a t if w e ha d w a n t e d to do the op p o s i t e – to onl y re m o v e the do u b l e.digit nu m b e r in thei r na m e . Im a g i n e yo u ha v e the follo w i n g file s in yo u r ho m e dir e c t o r y : [drysdalk@ioprov2 drysdalk]$ ls file-aa-keep file-a-keep file-bb-keep file-aa-wipe file-a-wipe file-bb-wipe [drysdalk@ioprov2 drysdalk]$ file-b-keep file-b-wipe If w e w a n t e d to er a s e all file s that ha d pr e c i s e l y tw o lett e r s in the mi d d l e of the file n a m e . S o inst e a d .ch a r a c t e r s in a ro w.digit file s ? Y o u r first tho u g h t mi g h t be to do rm file1*. but this w o u l d als o re m o v e file1 itself. w e co u l d do this: [drysdalk@ioprov2 drysdalk]$ ls file-aa-keep file-a-keep file-bb-keep file-b-keep file-aa-wipe file-a-wipe file-bb-wipe file-b-wipe [drysdalk@ioprov2 drysdalk]$ rm file-??-w* [drysdalk@ioprov2 drysdalk]$ ls P a g e 29 . sin c e an ast e r i s k m a t c h e s zer o or m o r e ch a r a c t e r s .digit s ? W e co u l d n ’ t do rm file*. w e ca n co m b i n e bot h typ e s of wild c a r d s in on e fairly co m p l e x co m m a n d .

txt file4. like m o s t Lin u x co m m a n d s . Th a t’ s w h y w e got the err o r: P a g e 30 . H o w e v e r . S o.txt file5. check. wil d c a r d s ca n be ver y us e f u l.g. and check again ! S p e c i f i c a l l y.txt file2.2 A cautionary word A s yo u ha v e se e n . as yo u m a y ha v e co m e to re ali s e .file-aa-keep file-a-keep file-a-wipe file-b-wipe [drysdalk@ioprov2 drysdalk]$ file-bb-keep file-b-keep A s yo u ca n se e. 4.lett e r file s at all. THINK. an d trie d to re m o v e it – it did n’t fin d on e. rm first loo k e d for a file si m p l y call e d file.txt file3. thi s ha s left us wit h all do u b l e. it is very ea s y to re m o v e or ot h e r w i s e aff e c t a file or dir e c t o r y that yo u di d not int e n d to.sh* [drysdalk@ioprov2 drysdalk]$ rm file * rm: cannot lstat `file': No such file or directory [drysdalk@ioprov2 drysdalk]$ ls [drysdalk@ioprov2 drysdalk]$ W h a t w e n t wr o n g ? W h a t ha p p e n e d w a s that ther e w a s a sp a c e bet w e e n the file an d the * in the ar g u m e n t s pa s s e d to the rm co m m a n d . yo u mi g h t w a n t to as k yo u r s e l f the follo w i n g bef o r e ru n n i n g an y co m m a n d inv ol v i n g wil d c a r d s : • • • • W o u l d the wil d c a r d act u a l l y w o r k . an d ha s ha d no eff e c t on sin gl e. not mi s t a k e n l y typi n g rm inst e a d of mv ? H a v e I actually ty p e d w h a t I think I’ve typ e d ? O n that last topi c.txt script1.sh* script2.lett e r file s w h o s e na m e s en d e d wit h ‘ke e p’. Th e nu m b e r. her e’ s a cla s s i c mi st a k e : [drysdalk@ioprov2 drysdalk]$ ls file1. an d cat c h all the files or dire c t o r i e s I w a n t ? A m I sur e that no oth e r file s or dir e c t o r i e s will be affe c t e d by w h a t I’m ab o u t to do ? A m I typi n g the rig h t co m m a n d – e. rm. is ca p a b l e of taki n g m u l ti p l e ar g u m e n t s on the co m m a n d lin e at on c e . be c a u s e no su c h file exi s t s.on e rule w h e n w o r k i n g wit h wil d c a r d s is: Stop. the y ca n als o be extremely dangerou s ! If yo u ar e not m o s t car e f u l.

Fo r ex a m p l e : file5. fix yo u r wild c a r d . Th e rm co m m a n d its elf ha s a saf e t y feat u r e . Al w a y s . To that en d.txt'? y rm: remove regular file `file3. B e c a u s e on c e tho s e file s ar e go n e .txt'? y rm: remove regular file `file2. B ef o r e ru n n i n g yo u r rm co m m a n d . Lo o k at the file list that is ret u r n e d – is it exactly w h a t yo u ex p e c t e d ? Ar e the r e an y file s mi s s i n g ? Ar e the r e an y extra file s or dir e c t o r i e s ? If so. Thi s. Th e r e’ s no R e c y c l e Bi n or Tr a s h in Li n u x – w h e n thi n g s ar e del e t e d . or si m p l y do n e the wr o n g thi n g. bef o r e pr e s s i n g ret u r n. the n yo u ca n pr o c e e d wit h yo u r rm co m m a n d .txt script2. her e ar e tw o go o d tec h n i q u e s for av o i d i n g rm wil d c a r d dis a s t e r s : 1.txt'? y rm: remove regular file `file5.rm: cannot lstat `file': No such file or directory S o.txt'? y rm: remove regular file `file4. an d yo u will be as k e d ab o u t ea c h of the m in tur n.sh* 2. the –i fla g. as it will ex p a n d yo u r wil d c a r d out to m a t c h the list of file s that w o u l d be re m o v e d . E xt r a sp a c e s bet w e e n ch a r a c t e r s an d wild c a r d s ca n sp ell dis a s t e r . an d ch e c k ag a i n . an d so all file s w e r e irre v e r s i b l y del e t e d . un d e r s t a n d a b l y . [drysdalk@ioprov2 drysdalk]$ ls file1.txt file2.sh* [drysdalk@ioprov2 drysdalk]$ rm -i file* rm: remove regular file `file1. W h e n yo u ar e sur e it is saf e.txt script1. w e’ v e wi p e d the entir e co n t e n t s of the dir e c t o r y .sh* script2. the y va ni s h inst a n t l y an d per m a n e n t l y . m a t c h e d all file s in the dir e c t o r y . Thi s is a big pr o b l e m . Thi s is a go o d thin g w h e n usi n g wil d c a r d s . sin c e inst e a d of re m o v i n g file*. the y ar e not co m i n g ba c k . w hi c h w a s our int e n t i o n .txt file4.txt'? y [drysdalk@ioprov2 drysdalk]$ ls script1.txt file3. run an ls wit h the ex a c t sa m e fla g s an d wil d c a r d .ch e c k yo u r sy n t a x w h e n w o r k i n g wit h wild c a r d s ! Y o u m u s t be certain that yo u ha v e not m a d e an y typi n g err o r s. always do u b l e. Thi s m a k e s the sy st e m pr o m p t yo u to co n f ir m that yo u re all y do w a n t to re m o v e the file s yo u ar e tryi n g to del e t e. it m o v e d on to the ne x t ar g u m e n t – our wil d c a r d . run an o t h e r ls.sh* [drysdalk@ioprov2 drysdalk]$ P a g e 31 .

H o w e v e r . the r e is a w a y to re m o v e an entir e dir e c t o r y an d all its co n t e n t s in on e go.dir e c t o r i e s bef o r e re m o v i n g the m . yo u w e r e sh o w n ho w to re m o v e a dir e c t o r y . Y o u w o u l d the n ha v e to e m p t y out the s e su b. it w a s poi n t e d out that yo u ha v e to re m o v e its co n t e n t s m a n u a l l y first. H o w e v e r .3 Removin g directories without emptying them manually first In the pr e v i o u s se c t i o n . Y o u ca n als o us e rm –r wit h wild c a r d s : [drysdalk@ioprov2 files1/ files2/ [drysdalk@ioprov2 [drysdalk@ioprov2 [drysdalk@ioprov2 drysdalk]$ ls files3/ drysdalk]$ rm -r * drysdalk]$ ls drysdalk]$ A n d all thr e e of the s e dir e c t o r i e s ar e si m u l t a n e o u s l y re m o v e d . 4. rm –r w a s su c c e s s f u l l y us e d to re m o v e it an d all its co n t e n t s in on e sin g l e co m m a n d . Thi s is do n e by usi n g the –r fla g of rm. an d so our rmdir co m m a n d did not all o w us to re m o v e it. w hi c h co n t a i n m o r e file s the m s e l v e s . A s yo u mi g h t ex p e c t . the dir e c t o r y files/ co n t a i n e d fold e r s .4. For ex a m p l e : [drysdalk@ioprov2 drysdalk]$ ls files/ [drysdalk@ioprov2 drysdalk]$ rmdir files rmdir: `files': Directory not empty [drysdalk@ioprov2 drysdalk]$ ls files file1 file2 file3 [drysdalk@ioprov2 drysdalk]$ rm -r files [drysdalk@ioprov2 drysdalk]$ ls [drysdalk@ioprov2 drysdalk]$ In this ex a m p l e . so yo u co u l d fin all y re m o v e the par e n t dir e c t o r y yo u w a n t e d to del e t e in the first pla c e . Th e y ca n P a g e 32 . the co m b i n a t i o n of the tw o ca n be de v a s t a t i n g . B ut. Thi s ca n be a pai n – par ti c u l a r l y if a dir e c t o r y co n t a i n s m a n y su b.4 Another cautionary word A s if wil d c a r d s an d rm –r w e r e not pot e n t i a l l y da n g e r o u s en o u g h on thei r o w n .dir e c t o r i e s . like wil d c a r d s . this is as pot e n t i a l l y da n g e r o u s as it is us e f u l.

if yo u ab s o l u t e l y m u s t us e rm –r wit h a wild c a r d . yo u ar e str o n g l y en c o u r a g e d to av oi d the co m b i n a t i o n of rm an d wil d c a r d s alt o g e t h e r . the n as bef o r e the ke y qu e s t i o n s to as k yo u r s e l f ar e: • • W o u l d the wil d c a r d act u a l l y w o r k . or to as k a m o r e ex p e r i e n c e d m e m b e r of the sy st e m s ad m i n i s t r a t i o n tea m to ch e c k ov e r the co m m a n d yo u ar e ab o u t to run to m a k e sur e it is saf e. the gol d e n rul e is: Stop. but wit h on e mi st a k e yo u co ul d er a s e a w h o l e gr o u p of file s yo u did n’t int e n d to. or ev e n de s t r o y the sy st e m entir e l y if yo u per f o r m a sudo rm –r w hil s t in the ro ot dir e c t o r y or in so m e ot h e r vit al loc a t i o n . H o w e v e r . check. an d cat c h all the files or dire c t o r i e s I w a n t ? A m I sur e that no oth e r file s or dir e c t o r i e s will be affe c t e d by w h a t I’m ab o u t to do ? P a g e 33 . and check again ! W h e n yo u ar e just st ar ti n g out in the w o r l d of Lin u x .sa v e yo u a lot of ti m e an d ha s s l e w h e n us e d cor r e c t l y an d saf e l y. O n c e ag a i n . THINK.

4.txt furby. ? O n c e yo u ar e sati sf i e d that the an s w e r to all of the s e qu e s t i o n s is ‘yes’. w hi c h inv e r t s the def a u l t be h a v i o u r : P a g e 34 .uk [drysdalk@ioprov2 drysdalk]$ A s yo u ca n se e. or. let’s sa y yo u ha v e a file call e d domains.txt [drysdalk@ioprov2 drysdalk]$ grep furby domains. an d yo u will w a n t to fin d on e sp e c i f i c ite m co n t a i n e d wit hi n the m .. in the or d e r that the y w e r e fou n d in the file. S o grep ca n allo w yo u to qui c k l y se a r c h ver y lar g e file s for sp e c i f i c pi e c e s of inf or m a t i o n . or /usr. the n – an d only the n – sh o u l d yo u pr o c e e d .co. w hi c h co n t a i n s a nu m b e r of do m a i n na m e s . Lin u x pr o v i d e s a co m m a n d lin e utilit y for this pur p o s e . Thi s is do n e by usi n g the –v ar g u m e n t .com furbyforum. tot all y. ab s o l u t e l y certain I a m not in the ro ot dir e c t o r y . H e r e’ s ho w w e co u l d do this. m o s t im p o r t a n t l y of all w h e r e rm –r an d wild c a r d s ar e co n c e r n e d : • • • H a v e I actually ty p e d w h a t I think I’ve typ e d ? A m I in the dir e c t o r y I thin k I a m in ? A m I defi nit e l y . yo u will ha v e a coll e c t i o n of file s that co n t a i n a lar g e a m o u n t of inf o r m a t i o n .com adoptafurby. an d is quit e oft e n an es s e n t i a l tool.A n d. Th e grep utilit y ca n als o per f o r m the op p o s i t e fun c t i o n – it ca n sh o w yo u all line s in a file that do not co n t a i n the phr a s e yo u su p p l y . usi n g grep: [drysdalk@ioprov2 drysdalk]$ ls -l total 888 -rw-r--r-1 drysdalk drysdalk 903719 Feb 16 16:56 domains. Fo r ex a m p l e . thr e e res u l t s w e r e ret u r n e d . call e d grep.txt. Y o u ha v e be e n giv e n the tas k of fin di n g all do m a i n s co n t a i n i n g the phr a s e ‘fur b y’.5 Searching the contents of files S o m e t i m e s .

sort e d or d e r .co.com easyspace. 4.co.co.com nicnames.co.com furby. grep –v di d ind e e d ret u r n all line s in the file that did not co n t a i n the stri n g ‘fur b y’.com furbyforum.com furby.uk internetters.txt iomart.uk [drysdalk@ioprov2 drysdalk]$ grep -v furby file.uk internetters. Fo r ex a m p l e : P a g e 35 .com nicnames. Thi s cr e a t e s a ne w co p y of the file wit h all the sa m e inf or m a t i o n as the ori gi n a l.co.uk [drysdalk@ioprov2 drysdalk]$ A s yo u ca n se e.com furbyforum. wit h the –o ar g u m e n t .txt adoptafurby.uk [drysdalk@ioprov2 drysdalk]$ Y o u ca n sp e c i f y a ne w file n a m e that the sort e d ver si o n sh o u l d be stor e d in. Y o u ca n eit h e r si m p l y get the sort e d co n t e n t s of a file to be dis pl a y e d on the co m m a n d lin e: [drysdalk@ioprov2 drysdalk]$ sort file.co.txt file.uk internetters.co.uk adoptafurby.6 Sorting the contents of files Th e co n t e n t s of file s ca n be sort e d wit h the sort co m m a n d .com easyspace.uk iomart.txt [drysdalk@ioprov2 drysdalk]$ cat file.txt iomart. but in alp h a b e t i c a l l y.com nicnames.com easyspace.[drysdalk@ioprov2 drysdalk]$ ls domains.co.

7 Finding a file Let’s sa y yo u w a n t to fin d a sp e c i f i c file that yo u kn o w is so m e w h e r e on the sy st e m .co.txt. but on c e yo u ha v e us e d it a fe w ti m e s yo u will qui c k l y get us e d to it.uk [drysdalk@ioprov2 drysdalk]$ 4.uk iomart.co.com furby. It’s a bit m o r e inv ol v e d to us e tha n grep or sort. Th e ba si c sy n t a x of find br e a k s do w n as follo w s : find <starting location> -name <filename to search for> Fo r ex a m p l e .w o r t h per s e v e r i n g wit h. Th e Lin u x co m m a n d for se a r c h i n g for a file is call e d find.txt /home/drysdalk/files1/passwords.uk internetters. an d yo u re m e m b e r that yo u call e d it passwords. but yo u ca n no lon g e r re m e m b e r w h e r e . S o.txt file.txt [drysdalk@ioprov2 drysdalk]$ cat file-sorted. yo u ca n fin d it like thi s: [drysdalk@ioprov2 drysdalk]$ ls files1 files2 files3 [drysdalk@ioprov2 drysdalk]$ find ~ -name passwords. H o w e v e r .com nicnames.[drysdalk@ioprov2 drysdalk]$ sort -o file-sorted.co. W e ca n als o se a r c h for file s star ti n g wit h the ro ot dir e c t o r y itself. It’s w ell. sin c e it ca n be an inv al u a b l e tool. ea c h of w hi c h co n t a i n s a qu a n t i t y of file s. yo u ca n’t re m e m b e r w h e r e yo u put it.txt [drysdalk@ioprov2 drysdalk]$ R e m e m b e r that ~ re p r e s e n t s yo u r ho m e dir e c t o r y – so w e told find to st ar t its se a r c h in that loc a t i o n . Y o u’ll als o noti c e that find ret u r n e d the co m p l e t e pat h to the file w e w e r e loo k i n g for.txt adoptafurby.com furbyforum. st arti n g fro m the root dir e c t o r y an d w o r k i n g its w a y do w n . Let’s sa y yo u w a n t to kn o w w h e r e the bin a r y file for the co m m a n d ls is loc a t e d : P a g e 36 .com easyspace. O n e of the s e file s is a list of pa s s w o r d s that yo u ne e d . let’s sa y yo u ha v e a nu m b e r of dir e c t o r i e s .

S o w e ca n se a r c h for all file s w h o s e na m e s en d wit h . let’s sa y yo u ha d pr e v i o u s l y us e d on e of the m for st ori n g di git a l ph o t o g r a p h s yo u ha d tak e n . or els e w e w o u l d ha v e rec e i v e d se v e r a l err o r s su c h as this: [drysdalk@ioprov2 drysdalk]$ find / -name ls find: /lost+found: Permission denied find: /boot/lost+found: Permission denied find: /home/lost+found: Permission denied find: /home/nonis: Permission denied find: /home/adamh: Permission denied find: /home/agoodall: Permission denied find: /home/aroberts: Permission denied find: /home/callum: Permission denied .jpg like this: [drysdalk@ioprov2 drysdalk]$ find ~ -name *. Thi s usi n g pipes . Goin g ba c k to our first ex a m p l e .jpg /mnt/home/drysdalk/drysdalk/files2/furby.. M o s t of the im p o r t a n t part s of the sy st e m ar e o w n e d by root an d ar e loc k e d do w n to that us e r onl y. find is as its m o s t us e f u l w h e n it is co m b i n e d wit h wil d c a r d s . B ut w h y di d w e us e sudo to ru n find ? R e m e m b e r that w h e n ru n n i n g as a reg u l a r us e r. tho u g h . Y o u ca n thi n k of a pip e as so m e t h i n g thr o u g h inf o r m a t i o n flo w s (hen c e the na m e). w h e r e w e ha v e a coll e c t i o n of dir e c t o r i e s that co n t a i n vari o u s file s.jpg [drysdalk@ioprov2 drysdalk]$ 4. so that pr o d u c e d by on e is tak e n as the inp u t us e d by an o t h e r . yo u will onl y be abl e to se a r c h or ot h e r w i s e ac c e s s dir e c t o r i e s w h o s e per m i s s i o n s sp e c i f y yo u ha v e ac c e s s to. so to be sur e that w e fin d so m e t h i n g w h e n se a r c h i n g the entir e sy s t e m w e ne e d su p e r u s e r privil e g e s . Thi s is on e of the m o s t P a g e 37 the out p u t is do n e by w hi c h po w e r f u l .jpg /mnt/home/drysdalk/drysdalk/files2/cat2.jpg /mnt/home/drysdalk/drysdalk/files2/cat1.[drysdalk@ioprov2 drysdalk]$ sudo find / -name ls /bin/ls [drysdalk@ioprov2 drysdalk]$ Thi s m a k e s se n s e . Y o u ca n’t re m e m b e r w hi c h on e..8 Pipes It is po s s i b l e to link tw o or m o r e co m m a n d s tog e t h e r . S o sudo ha d to be us e d her e. an d is w h e r e w e w o u l d ex p e c t to fin d ls an d ot h e r co m m o n co m m a n d s – yo u will rec a ll fro m the pr e v i o u s se c t i o n that /bin is us e d for stori n g tho s e sy s t e m bin a r i e s that ar e int e n d e d for reg u l a r us e r s to run.

W e co u l d do this: P a g e 38 .styl e op e r a t i n g sy st e m s . an d allo w s us to do so m e ver y co m p l i c a t e d thin g s in a fairly str ai g h t f o r w a r d fas h i o n .an d us e f u l feat u r e s of Li n u x an d U N I X. Th e ea si e s t w a y to get to gri p s wit h pip e s is to se e so m e ex a m p l e s . se p a r a t e d by a | sy m b o l (a verti c a l bar – us u a l l y loc a t e d on the ba c k s l a s h ke y). Pi p e s ar e us e d by typi n g the co m m a n d s yo u w a n t to link tog e t h e r . Fo r inst a n c e . let’s sa y at a gl a n c e w e w a n t e d to kn o w at a gla n c e w h a t file s w e ha d co n t a i n i n g inf or m a t i o n fro m Ja n u a r y 2007. im a g i n e w e ha v e a dir e c t o r y wit h the follo w i n g file s: [drysdalk@ioprov2 drysdalk]$ ls file-20061201 file-20061214 file-20061222 file-20070207 file-20070215 file-20070223 file-20061207 file-20061215 file-20061223 file-20070208 file-20070218 file-20070224 file-20061209 file-20061216 file-20061229 file-20070211 file-20070219 file-20070225 file-20061210 file-20061217 file-20061230 file-20070212 file-20070220 file-20070226 file-20061212 file-20061220 file-20070107 file-20070213 file-20070221 file-20070227 file-20061213 file-20061221 file-20070127 file-20070222 file-20070109 file-20070115 file-20070116 file-20070123 file-20070126 file-20070206 file-20070129 file-20070130 file-20070201 file-20070204 file-20070205 file-20070214 [drysdalk@ioprov2 drysdalk]$ N o w .

an d the n se a r c h e d that inp u t for the stri n g 200 7 0 1 .txt furby. the out p u t w a s fed in to a pip e. H o w e v e r . all in on e go: [drysdalk@ioprov2 drysdalk]$ ls -l total 888 -rw-r--r-1 drysdalk drysdalk 903719 Feb 16 16:56 domains.uk A n d the res u l t s ar e no w alp h a b e t i c a l l y sort e d .com furby. S o the en d res u l t w a s to giv e us a dir e c t o r y listi n g onl y for tho s e file s wit h 2007 0 1 in their file n a m e . H e r e’ s an o t h e r ex a m p l e – let’s sa y that aft e r our earli e r se a r c h thr o u g h domains.com furbyforum.txt [drysdalk@ioprov2 drysdalk]$ grep furby domains. an d inst e a d pa s s e s it on to the pr o g r a m at the ot h e r en d of the pip e. an d of writi n g its out p u t to the ter m i n a l .uk P a g e 39 .co.txt | grep –v adopt | sort furby.com adoptafurby. w hi c h co n s i s t e d of the dir e c t o r y listi n g that w e sa w ab o v e pr e v i o u s l y . w e the n de ci d e d that w e w a n t e d the res u l t s to be alp h a b e t i c a l l y sort e d . it the n pri nt e d out to the ter m i n a l all lin e s it fou n d that m a t c h e d the patt e r n it ha d be e n giv e n .uk [drysdalk@ioprov2 drysdalk]$ grep furby domains. Y o u ca n als o co m b i n e as m a n y pip e s as yo u like in on e go: [drysdalk@ioprov2 drysdalk]$ grep furby domains.txt | sort adoptafurby. A s is its def a u l t be h a v i o u r . S o grep rec e i v e d as its inp u t the co m p l e t e dir e c t o r y listin g.com furbyforum. Thi s pr e v e n t s it fro m bei n g writt e n to the ter m i n a l. it ca n fun c t i o n at eit h e r en d of a pip e. S o lon g as a co m m a n d is ca p a b l e of taki n g its inp u t fro m the ke y b o a r d . Al m o s t an y tw o Li n u x co m m a n d s ca n be att a c h e d by a pip e.txt for do m a i n s co n t a i n i n g the w o r d ‘fur b y’.[drysdalk@ioprov2 drysdalk]$ ls | grep 200701 file-20070107 file-20070109 file-20070115 file-20070116 file-20070123 file-20070126 file-20070127 file-20070129 file-20070130 [drysdalk@ioprov2 drysdalk]$ H e r e .com furbyforum.co. w e too k the out p u t fro m ls.co. rat h e r tha n se n d i n g that out p u t to the scr e e n as is the def a u l t.

feat u r e of Li n u x . it is als o po s s i b l e for a co m m a n d to get its inp u t fro m a pr e. the ea si e s t w a y to un d e r s t a n d ho w the s e w o r k is to ju m p str ai g h t in wit h so m e ex a m p l e s .co.txt [drysdalk@ioprov2 drysdalk]$ furby.com furbyforum.9 Input and output re-direction In ad d i t i o n to linki n g up co m m a n d s usi n g pip e s . w e w a n t to st or e the res u lt s in a file.uk [drysdalk@ioprov2 drysdalk]$ ls grep furby domains.tha n sig n). Im a g i n e that yo u ha v e alr e a d y writt e n a scri p t to car r y out this tas k. pip e s ar e a ver y ver s a t il e. an d us e f u l. Thi s is ac c o m p l i s h e d by re-directing the input an d output of co m m a n d s . the file results w a s cr e a t e d w h e n w e re-dir e c t e d the out p u t of the grep co m m a n d to it.com adoptafurby.exi s ti n g file. an d out p u t re-dir e c t i o n is re p r e s e n t e d by a > sy m b o l (a gr e a t e r. N o w per h a p s w e w e r e ori gi n a l l y loo ki n g for this list so that w e co u l d per f o r m a par ti c u l a r tas k on the s e sp e c i f i c do m a i n s .uk [drysdalk@ioprov2 drysdalk]$ [drysdalk@ioprov2 drysdalk]$ domains.co.tha n sig n).com furbyforum.sh P a g e 40 . S o yo u co u l d do so m e t h i n g like: [drysdalk@ioprov2 drysdalk]$ . rat h e r tha n si m p l y ha v e the m ap p e a r on our ter m i n a l: [drysdalk@ioprov2 drysdalk]$ domains. Let’s sa y that duri n g our pr e v i o u s ex a m p l e of se a r c h i n g for do m a i n na m e s .txt > results ls cat results A s yo u ca n se e. or to se n d out p u t that w o u l d nor m a l l y be pri nt e d on yo u r ter m i n a l to a pr e.com adoptafurby. an d that it will pr o m p t yo u to typ e ea c h do m a i n na m e to be pr o c e s s e d .S o as yo u ca n se e.txt grep furby domains. an d its co n t e n t s ar e ide n t i c a l to the out p u t of our ori gi n a l grep. Inp u t re-dir e c t i o n is ac c o m p l i s h e d by usi n g a < sy m b o l (a les s.exi s ti n g or ne w file. 4./script.txt results [drysdalk@ioprov2 drysdalk]$ furby. A g a i n .

txt >> results cat results un-related to this search A g a i n .co.com Domain processed .furby.com furbyforum. as wit h pip e s . For ex a m p l e : [drysdalk@ioprov2 drysdalk]$ I contain something entirely [drysdalk@ioprov2 drysdalk]$ [drysdalk@ioprov2 drysdalk]$ I contain something entirely furby.com Domain processed .co. For ex a m p l e : [drysdalk@ioprov2 drysdalk]$ domains.com Domain processed . furby.uk [drysdalk@ioprov2 drysdalk]$ B ut w e co ul d als o us e an inp u t re-dir e c t o r to aut o m a t i c a l l y fee d our results file in to the scri p t to sa v e us typi n g m a n u a l l y .uk [drysdalk@ioprov2 drysdalk]$ In clo si n g .uk [drysdalk@ioprov2 drysdalk]$ ls cat results un-related to this search grep furby domains.10 Chan gin g your pas s w ord P a g e 41 . and press return after each one.co. it will be entir e l y ov e r w r i t t e n .furbyforum.com furbyforum. and press return after each one.co. w hi c h is >> (two gr e a t e rtha n sig n s). her e’ s a ca u t i o n a r y w o r d ab o u t the out p u t re-dir e c t o r – if yo u sp e c i f y a file that alr e a d y exi s t s. like so: [drysdalk@ioprov2 drysdalk]$ .furby.com adoptafurby.com adoptafurby.Enter domain names.com furbyforum. Domain processed .adoptafurby. 4.uk [drysdalk@ioprov2 drysdalk]$ cat results un-related to this search grep furby domains.furbyforum. yo u ne e d to us e the append re-dir e c t o r .txt results [drysdalk@ioprov2 drysdalk]$ I contain something entirely [drysdalk@ioprov2 drysdalk]$ [drysdalk@ioprov2 drysdalk]$ furby./script.adoptafurby.uk Domain processed .sh < results Enter domain names.com adoptafurby.txt > results cat results If yo u w a n t to pr e s e r v e the co n t e n t s of the file yo u ar e re-dir e c t i n g out p u t to.co. inp u t an d out p u t re-dir e c t i o n will w o r k wit h an y Li n u x co m m a n d that ca n eit h e r rea d its inp u t fro m the ke y b o a r d or writ e its out p u t to the ter m i n a l .com Domain processed .

N o w w e’ll se e ho w to act u a l l y ch a n g e the s e . [drysdalk@ioprov2 drysdalk]$ passwd Changing NIS account information for drysdalk on nis01.Y o u mi g h t w a n t to ch a n g e the pa s s w o r d that yo u w e r e first iss u e d wit h – thi s is fin e.iomart.sh* -rwxr-x--1 drysdalk sys 48 Feb 19 15:19 script2. [drysdalk@ioprov2 drysdalk]$ 4.sh* 67 Feb 19 15:19 script3.iomart. an d yo u will the n be tak e n thr o u g h the pa s s w o r d.sh* 48 Feb 19 15:19 script2. yo u si m p l y typ e passwd on its o w n. an d not so m e str a n g e r w h o is tryi n g to loc k yo u out be c a u s e the y’ v e co m e w a n d e r i n g pa s t yo u r unl o c k e d ter m i n a l . in or d e r to m a k e sur e that the per s o n iss ui n g the pa s s w o r d ch a n g e req u e s t is re all y yo u. to m a k e sur e yo u ar e typi n g it cor r e c t l y.11 Chan gin g the owner and group of a file or directory W e’ v e alr e a d y lear n e d ho w to se e the o w n e r an d gr o u p as s o c i a t e d wit h a par ti c u l a r file or dir e c t o r y . If yo u ent e r it cor r e c t l y.sh* P a g e 42 . wit h the follo w i n g o w n e r s h i p s : [drysdalk@ioprov2 drysdalk]$ ls -l total 12 -rwxr-x--1 drysdalk drysdalk -rwxr-x--1 drysdalk drysdalk -rwxr-x--1 drysdalk drysdalk [drysdalk@ioprov2 drysdalk]$ 12 Feb 19 15:19 script1. an d Lin u x pr o v i d e s yo u wit h a si m p l e m e c h a n i s m for doi n g thi s.com.iomart. Please enter old password: Changing NIS password for drysdalk on nis01.sh* N o w . Please enter new password: Please retype new password: The NIS password has been changed on nis01. Im a g i n e yo u ha v e the foll o w i n g file s. let’s sa y w e w a n t e d to giv e all m e m b e r s of the ‘sys’ gr o u p ac c e s s to the s e file s.com.ch a n g i n g pr o c e s s . yo u will the n be as k e d for yo u r ne w pa s s w o r d twi c e.com. Y o u will first be pr o m p t e d for yo u r exi st i n g pa s s w o r d . as foll o w s : [drysdalk@ioprov2 drysdalk]$ sudo chgrp sys * [drysdalk@ioprov2 drysdalk]$ ls -l total 12 -rwxr-x--1 drysdalk sys 12 Feb 19 15:19 script1. To ch a n g e yo u r pa s s w o r d . P a s s w o r d s ar e ch a n g e d wit h the passwd co m m a n d . W e us e the chgrp co m m a n d to ch a n g e a file’s gr o u p .

12 Chan gin g the permis sion s on a file or directory In the last se c ti o n . S p e a k i n g of sudo.sh* A n d no w the file s ar e no lon g e r o w n e d by the origi n a l us e r or gr o u p at all. the y w o u l d ha v e to us e sudo to eit h e r ac c e s s the m as the su p e r u s e r . or to ch a n g e the o w n e r s h i p s ba c k to a suit a b l e val u e . yo u’ll noti c e w e ha d to us e it in all the s e ex a m p l e s – thi s is be c a u s e onl y root ca n ch a n g e gr o u p s an d o w n e r s h i p s on file s. To rec a p usi n g on e of the file s fro m our pr e v i o u s ex a m p l e : -rwxr-x--1 drysdalk drysdalk 12 Feb 19 15:19 script1. N o t e that unl e s s the ori gi n a l us e r is als o a m e m b e r of the ‘sys’ gr o u p . w e sa w ho w to vie w an d un d e r s t a n d the per m i s s i o n s that ap p e a r in a lon g dir e c t o r y listin g. w h e r e a s it w a s the us e r’ s o w n priv a t e gr o u p bef o r e . 4.sh* 48 Feb 19 15:19 script2. S o thi s is on e tas k yo u’ d us u a l l y al w a y s ha v e to us e sudo for. the y w o u l d no lon g e r ha v e an y ac c e s s to the s e file s. to an entir e l y diff e r e n t per s o n ? Thi s is do n e wit h the chown co m m a n d : [drysdalk@ioprov2 drysdalk]$ sudo chown [drysdalk@ioprov2 drysdalk]$ ls -l total 12 -rwxr-x--1 aroberts sys -rwxr-x--1 aroberts sys -rwxr-x--1 aroberts sys [drysdalk@ioprov2 drysdalk]$ aroberts * 12 Feb 19 15:19 script1.-rwxr-x--1 drysdalk sys [drysdalk@ioprov2 drysdalk]$ 67 Feb 19 15:19 script3. the ‘sys’ gr o u p no w is as s o c i a t e d wit h the s e file s. If the y ev e r ne e d e d to us e the m ag a i n .sh* A s yo u ca n se e. w h a t if w e w a n t to giv e a w a y o w n e r s h i p of the s e file s alt o g e t h e r .sh* H e r e w e ca n se e that the per m i s s i o n s br e a k do w n as follo w s : - Owner rwx Gr o u p r-x --- E v e r y o n e els e P a g e 43 . S o be car e f u l w h e n ch a n g i n g o w n e r s h i p s an d gr o u p s on file s – it is po s s i b l e to loc k reg u l a r us e r s out of file s or dir e c t o r i e s entir e l y.sh* 67 Feb 19 15:19 script3. N o w .

chmod ha s the follo w i n g ba si c sy n t a x : chmod <permissions to use> <files to have their permissions changed> Th e per m i s s i o n s to us e ha v e their o w n uni q u e sy n t a x . all> <set or un s e t > <per m i s s i o n s > P a g e 44 . W h a t if w e w a n t e d to ch a n g e the s e per m i s s i o n s ? Thi s is do n e wit h the chmod co m m a n d .sh at all.S o the file’s o w n e r ‘dry s d a l k’ ha s re a d. ot h e r m e m b e r s of the gr o u p ‘dry s d a l k’ ha v e rea d an d ex e c u t e ac c e s s onl y. of the for m: <o w n e r . an d ev e r y o n e els e on the sy s t e m ha s no ac c e s s to script1. writ e an d ex e c u t e ac c e s s . gr o u p .

w e w o u l d us e u+w : [drysdalk@ioprov2 drysdalk]$ chmod u+w script1. writ e an d ex e c u t e Thi s m a y se e m quit e da u n t i n g at first.sh [drysdalk@ioprov2 drysdalk]$ ls -l script1. Let’s sa y that w e w a n t e d to re m o v e our o w n writ e ac c e s s to the file.sh* [drysdalk@ioprov2 drysdalk]$ chmod u-w script1.sh -r-xr-x--1 drysdalk drysdalk 12 Feb 19 15:19 script1. re p r e s e n t e d by S o if w e w a n t e d to re-ad d writ e per m i s s i o n .sh -rwxr-x--1 drysdalk drysdalk 12 Feb 19 15:19 script1.sh [drysdalk@ioprov2 drysdalk]$ ls -l script1.Where: u g o A n d: + – A n d fin all y: rwx P o s s i b l e set of per m i s s i o n s – re a d.sh* [drysdalk@ioprov2 drysdalk]$ O w n e r of the file Gr o u p as s o c i a t e d wit h the file All ot h e r us e r s on the sy st e m S et the foll o w i n g per m i s s i o n( s) U n s e t the foll o w i n g per m i s s i o n(s) W e us e d ‘u-w ’ as the per m i s s i o n s be c a u s e : u u – w W e ar e re m o v i n g per m i s s i o n s Th e per m i s s i o n w e wis h to ch a n g e is writ e per m i s s i o n W e ar e ch a n g i n g per m i s s i o n s for the o w n e r . to en s u r e w e co u l d not ac ci d e n t a l l y ov e r w r i t e it. W e w o u l d ne e d to typ e: [drysdalk@ioprov2 drysdalk]$ ls -l script1. but w h e n yo u se e a fe w ex a m p l e s it will be g i n to be c o m e cle a r.sh -rwxr-x--1 drysdalk drysdalk 12 Feb 19 15:19 script1.sh* [drysdalk@ioprov2 drysdalk]$ P a g e 45 .

that poi n t s to the ‘real’ co p y of the file so m e w h e r e els e on the sy s t e m . w e w o u l d ne e d to us e the m o d e g-rwx : [drysdalk@ioprov2 drysdalk]$ chmod g-rwx script1.sh* [drysdalk@ioprov2 drysdalk]$ A n d as a last ex a m p l e .txt. S y m b o l i c link s ar e set up wit h the ln co m m a n d .13 Symbolic links A sy m b o l i c link is a ‘virt u a l’ file. an d ha v e all ot h e r inst a n c e s of the file as sy m b o l i c link s poi n t i n g to it. Y o u will als o noti c e that the ver y first P a g e 46 . w e w o u l d us e o+r : [drysdalk@ioprov2 drysdalk]$ chmod o+r script1.sh [drysdalk@ioprov2 drysdalk]$ ls -l script1. if w e w a n t e d to ad d rea d per m i s s i o n for all ot h e r us e r s on the sy st e m not a m e m b e r of the ‘dry s d a l k’ gr o u p . all ‘co pi e s’ ar e al w a y s poi n t i n g to the lat e s t ver si o n of the file.txt is (quite liter a ll y) poi n t i n g to file1.txt lrwxrwxrwx 1 drysdalk drysdalk 9 Feb 19 17:11 file2.txt -> file1.sh -rwx-----1 drysdalk drysdalk 12 Feb 19 15:19 script1. Thi s w a y.txt file2. Th e sy n t a x re q u i r e d to cr e a t e a sy m b o l i c link is as follo w s : ln –s <original file> <new link to be created> Fo r ex a m p l e : [drysdalk@ioprov2 drysdalk]$ ls -l total 4 -rw-rw-r-1 drysdalk drysdalk 27 Feb 19 17:11 file1.sh -rwx---r-1 drysdalk drysdalk 12 Feb 19 15:19 script1.txt [drysdalk@ioprov2 drysdalk]$ H e r e w e ca n se e in a lon g dir e c t o r y listin g that file2.txt [drysdalk@ioprov2 drysdalk]$ ln -s file1.sh [drysdalk@ioprov2 drysdalk]$ ls -l script1.sh* [drysdalk@ioprov2 drysdalk]$ 4.If w e w a n t e d to tak e a w a y all per m i s s i o n s for m e m b e r s of the ‘dry s d a l k’ gr o u p .txt [drysdalk@ioprov2 drysdalk]$ ls -l total 4 -rw-rw-r-1 drysdalk drysdalk 27 Feb 19 17:11 file1. Th e ide a be h i n d sy m b o l i c link s is to be abl e to ref e r e n c e file s fro m m u lti p l e loc a t i o n s . m o r e or les s. Th e y als o ha v e the ad d e d ad v a n t a g e that an y ch a n g e s m a d e to the re al file its elf aff e c t ev e r y t h i n g link e d to it as w ell. Y o u do n’t ha v e to m a i n t a i n lot s of diff e r e n t co p i e s of a file – yo u ca n ke e p on e ce n t r a l co p y. wit h o u t ha v i n g to co p y the file itself an d thu s w a s t e dis c sp a c e .

S o r t file s al p h a b e t i c a l l y wit h the sort co m m a n d . sin c e it poi n t s to a de s t i n a t i o n that ha s be e n re m o v e d .dir e c t the inp u t or out p u t of co m m a n d s wit h re-dir e c t o r s ( < > >> ) .S e a r c h the co n t e n t s of file s wit h the grep co m m a n d .txt is re m o v e d . w e’ v e ex p a n d e d on the ba s i c s of usi n g Lin u x quit e a bit her e. VERY careful when doing either of the above ! .Be very.R e m o v e a dir e c t o r y w h e n it is not alr e a d y e m p t y . ho w e v e r . br o k e n link. is no w a sin gl e lo w e r.txt’s per m i s s i o n s (whic h up until no w ha s a sin g l e da s h).txt w a s not a real file – it w a s onl y a poi n t e r to the ge n u i n e articl e.of-section summ ary S o.ch a r a c t e r in file2.14 End.txt is re m o v e d . file1. If file2. sin c e file2. To rec a p .W o r k wit h m o r e tha n on e file or dir e c t o r y at on c e by usi n g wil d c a r d s .ca s e lett e r l.C h a n g e yo u r o w n pa s s w o r d . but it will no w be a us e l e s s . in thi s se c ti o n w e ha v e lear n e d ho w to: . an d ha v e intr o d u c e d so m e ne w co n c e p t s that ho p e f u l l y ha v e giv e n yo u so m e ide a of ho w ver s a t i l e an d po w e r f u l Lin u x ca n be at the co m m a n d lin e.C h a n g e the per m i s s i o n s on a file or dir e c t o r y .Fi n d file s ba s e d on their na m e s usi n g the find co m m a n d .txt will not be aff e c t e d .Cr e a t e an d vie w sy m b o l i c link s P a g e 47 . 4.txt will still exi st. Thi s tells yo u be y o n d a do u b t that it is a sy m b o l i c link. If file1. the dat a will be go n e – file2.R e.C h a n g e the o w n e r or gr o u p as s o c i a t e d wit h a file or dir e c t o r y .U s e the out p u t of on e co m m a n d as the inp u t of an o t h e r wit h pi p e s ( | ) .

sh* script5. Fo r ex a m p l e .5.sh* script3. It ca n do m o r e tha n that. Th e sort co m m a n d ca n be tol d to sort ba s e d on a sp e c i f i c field wit h the –k ar g u m e n t .sh* -rwxr-xr-1 drysdalk drysdalk 30 Feb 19 15:20 script8.1 sort revisited In the last se c ti o n .sh* -rwxr-xr-1 drysdalk drysdalk 47 Feb 19 15:20 script6. per f o r m a sort on on e par ti c u l a r porti o n of its inp u t.sh* -rwxr-xr-1 drysdalk drysdalk 20 Feb 19 15:20 script9.sh* -rwxr-xr-1 drysdalk drysdalk 12 Feb 19 15:19 script1.sh* -rwxr-xr-1 drysdalk drysdalk 67 Feb 19 15:19 script3.sh* script8. S o to sort thi s lon g dir e c t o r y listin g ba s e d on the val u e s in the fifth fiel d.sh* script7.sh* [drysdalk@ioprov2 drysdalk]$ P a g e 48 .sh* script6. w hi c h ar e ca p a b l e of far m o r e tha n yo u ha v e se e n so far.sh* script1. 5.sh* -rwxr-xr-1 drysdalk drysdalk 107 Feb 19 15:20 script7.sh* script2.sh* -rwxr-xr-1 drysdalk drysdalk 48 Feb 19 15:19 script2.sh* N o w . w h a t if w e w a n t to sort the s e file s in or d e r of their siz e ? Th e siz e is the fifth fiel d in the list. w e’ll ex p a n d on so m e of the co m m a n d s dis c u s s e d in the pr e v i o u s se c ti o n . Advan ced comm a nd s In this se ct i o n . an d m o r e .sh* script9.sh* -rwxr-xr-1 drysdalk drysdalk 176 Feb 19 15:20 script10. [drysdalk@ioprov2 drysdalk]$ ls -l total 40 -rwxr-xr-1 drysdalk drysdalk -rwxr-xr-1 drysdalk drysdalk -rwxr-xr-1 drysdalk drysdalk -rwxr-xr-1 drysdalk drysdalk -rwxr-xr-1 drysdalk drysdalk -rwxr-xr-1 drysdalk drysdalk -rwxr-xr-1 drysdalk drysdalk -rwxr-xr-1 drysdalk drysdalk -rwxr-xr-1 drysdalk drysdalk -rwxr-xr-1 drysdalk drysdalk [drysdalk@ioprov2 drysdalk]$ 176 12 48 67 36 4 47 107 30 20 Feb Feb Feb Feb Feb Feb Feb Feb Feb Feb 19 19 19 19 19 19 19 19 19 19 15:20 15:19 15:19 15:19 15:19 15:19 15:20 15:20 15:20 15:20 script10. W e’ll als o intr o d u c e a fe w ne w co m m a n d s w e ha v e n ’ t talk e d ab o u t bef o r e . ho w e v e r – it ca n w o r k wit h co m p l e x set s of dat a. w e sa w that sort ca n be us e d to sort inf o r m a t i o n al p h a b e t i c a l l y. co u n t i n g alo n g fro m the left. w e w o u l d typ e: [drysdalk@ioprov2 drysdalk]$ ls -l | sort -bn -k5 total 40 -rwxr-xr-1 drysdalk drysdalk 4 Feb 19 15:19 script5. im a g i n e yo u ha v e the follo w i n g lon g dir e c t o r y listin g.sh* -rwxr-xr-1 drysdalk drysdalk 36 Feb 19 15:19 script4.sh* script4.

sh* script2. wit h the –S fla g (note that’s an up p e r.sh* Thi s is als o a go o d op p o r t u n i t y to poi n t out so m e t h i n g els e ab o u t Lin u x co m m a n d fla g s – yo u ca n co m b i n e the m in an y or d e r . Y o u ca n eit h e r put ea c h of the m on thei r o w n as w e ha v e do n e ab o v e .ca s e S).sh* H o w e v e r .sh* script7. A n d no w w e ca n se e at a gla n c e w hi c h of the s e scri p t s is the s m a l l e s t . P a g e 49 .sh* script9. O h. Th e –r fla g rev e r s e s the or d e r of the sort. star ti n g wit h the big g e s t file an d w o r k i n g do w n to the s m a l l e s t . S o to get a pr e.sh* script5.sh* script7.sh* script1.sh* script4. for the sa k e of rea d a b i l it y.sh* script6.sh* script6.Th e –bn fla g tells sort to perf o r m a sort in nu m e r i c a l or d e r . rat h e r tha n al p h a b e t i c a l .sh* script8. fro m s m a l l e s t to big g e s t .sh* script4.sh* script2.sh* script3. an d w hi c h is the lar g e s t .sh* script8. W e ca n als o ea si l y rev e r s e the or d e r of a sort wit h the –r fla g: [drysdalk@ioprov2 drysdalk]$ ls -l | sort -bn -k5 -rwxr-xr-1 drysdalk drysdalk 176 Feb 19 -rwxr-xr-1 drysdalk drysdalk 107 Feb 19 -rwxr-xr-1 drysdalk drysdalk 67 Feb 19 -rwxr-xr-1 drysdalk drysdalk 48 Feb 19 -rwxr-xr-1 drysdalk drysdalk 47 Feb 19 -rwxr-xr-1 drysdalk drysdalk 36 Feb 19 -rwxr-xr-1 drysdalk drysdalk 30 Feb 19 -rwxr-xr-1 drysdalk drysdalk 20 Feb 19 -rwxr-xr-1 drysdalk drysdalk 12 Feb 19 -rwxr-xr-1 drysdalk drysdalk 4 Feb 19 total 40 [drysdalk@ioprov2 drysdalk]$ -r 15:20 15:20 15:19 15:19 15:20 15:19 15:20 15:20 15:19 15:19 script10.sh* script5.sh* script9. it’s us u a l l y a go o d ide a to se p a r a t e the m so yo u ca n ea s il y tell the m ap a r t. ls –lS w o u l d w o r k. or yo u ca n roll the m all in to on e an d the res u lt is the sa m e : [drysdalk@ioprov2 drysdalk]$ ls -l | sort -bnrk5 -rwxr-xr-1 drysdalk drysdalk 176 Feb 19 -rwxr-xr-1 drysdalk drysdalk 107 Feb 19 -rwxr-xr-1 drysdalk drysdalk 67 Feb 19 -rwxr-xr-1 drysdalk drysdalk 48 Feb 19 -rwxr-xr-1 drysdalk drysdalk 47 Feb 19 -rwxr-xr-1 drysdalk drysdalk 36 Feb 19 -rwxr-xr-1 drysdalk drysdalk 30 Feb 19 -rwxr-xr-1 drysdalk drysdalk 20 Feb 19 -rwxr-xr-1 drysdalk drysdalk 12 Feb 19 -rwxr-xr-1 drysdalk drysdalk 4 Feb 19 total 40 [drysdalk@ioprov2 drysdalk]$ 15:20 15:20 15:19 15:19 15:20 15:19 15:20 15:20 15:19 15:19 script10. so ls –lrS w o u l d rev e r s e the or d e r of the sort.sh* script1.sort e d lon g dir e c t o r y listi n g. on e last thi n g – not e that ls ca n act u a l l y aut o m a t i c a l l y sort its out p u t itself by siz e.sh* script3.

us u a l l y the nu m b e r of byt e s in qu e s t i o n c or k Th e nu m b e r is in byt e s.txt file2.txt Or: [drysdalk@ioprov2 drysdalk]$ find ~ -size +1024k /mnt/home/drysdalk/drysdalk/file3. Finding files based on their size Synta x: fin d <st ar ti n g poi n t> -siz e <siz e sp e c i f i c a t i o n > W h e r e the siz e sp e c i f i c a t i o n ha s the follo w i n g sy n t a x : + or – Fi n d file s big g e r tha n.txt /mnt/home/drysdalk/drysdalk/file1. but ther e ar e a gr e a t m a n y ot h e r s . or les s tha n. find is als o ca p a b l e of far m o r e tha n just se a r c h i n g for file s ba s e d on their na m e . w e as s u m e the follo w i n g co n t e n t s in yo u r ho m e dir e c t o r y : [drysdalk@ioprov2 drysdalk]$ ls -l total 8720 -rw-rw-r-1 drysdalk drysdalk -rw-rw-r-1 drysdalk drysdalk -rw-rw-r-1 drysdalk drysdalk -rw-rw-r-1 drysdalk drysdalk -rw-rw-r-1 drysdalk drysdalk [drysdalk@ioprov2 drysdalk]$ 2097152 1048576 1572864 4194304 524288 Feb Feb Feb Feb Feb 19 19 19 19 19 16:47 16:48 16:48 16:48 16:50 file1.txt /mnt/home/drysdalk/drysdalk/file4.txt file3. Th e -name fla g is the on e yo u will un d o u b t e d l y us e the m o s t .txt Fo r ex a m p l e .2 find revisited A s yo u mi g h t ha v e su s p e c t e d . yo u co ul d typ e: [drysdalk@ioprov2 drysdalk]$ find ~ -size +1048576c /mnt/home/drysdalk/drysdalk/file3.txt file5.txt file4. H e r e w e’ll loo k at so m e of the ot h e r m o r e co m m o n (and us e f u l) typ e s of find co m m a n d s yo u mi g h t ne e d to run.5. the follo w i n g siz e File size A w h o l e nu m b e r . to fin d all file s in yo u r ho m e dir e c t o r y big g e r tha n on e m e g a b y t e in siz e. or kilo b y t e s In ea c h of the foll o w i n g ex a m p l e s .txt P a g e 50 .

but if yo u ha p p e n to kn o w the ex a c t nu m b e r of byt e s in a m e g a b y t e (1. To fin d file s s m a l l e r tha n a m e g a b y t e : [drysdalk@ioprov2 drysdalk]$ find ~ -size -1024k /mnt/home/drysdalk/drysdalk/file5. but yo u’ll se e lat e r on that bei n g abl e to fin d all dir e c t o r i e s wit hi n a sp e c i f i c loc a t i o n is quit e us e f u l.5 7 6. . etc).txt /mnt/home/drysdalk/drysdalk/file4.txt [drysdalk@ioprov2 drysdalk]$ Y o u’ d us u a l l y w a n t to do 10 2 4 k . as it ha p p e n s) the eff e c t is ide n t i c a l . or like w i s e to onl y fin d file s an d not dir e c t o r i e s . sin c e w h a t w e reall y m e a n her e by ‘typ e’ is not the ext e n s i o n of a file n a m e (e.048. an d so on. a file.txt [drysdalk@ioprov2 drysdalk]$ Finding files based on their type Th e title of this se ct i o n is act u a l l y a slig h t mi s n o m e r . yo u co ul d typ e: P a g e 51 .txt.g. the sy n t a x is: find <starting location> -type <type to search for> W h e r e the typ e s yo u w o u l d m o s t co m m o n l y w a n t to se a r c h for ar e: d f l Dir e c t o r y Fil e S y m b o l i c link Fo r ex a m p l e . . a dir e c t o r y . .g.txt [drysdalk@ioprov2 drysdalk]$ Y o u ca n als o sp e c i f y the pr e c i s e siz e of file yo u w a n t to se a r c h for. to fin d all su b.sh.dir e c t o r i e s of yo u r o w n ho m e dir e c t o r y . Thi s mi g h t not se e m too us e f u l to be g i n wit h. by o m i t ti n g the – or + sy m b o l : [drysdalk@ioprov2 drysdalk]$ find ~ -size 1024k /mnt/home/drysdalk/drysdalk/file2./mnt/home/drysdalk/drysdalk/file1. In an y ev e n t . but the typ e as far as Lin u x itself is co n c e r n e d – e.jpg.

the y did n’t tell yo u ex a c t l y w h e r e a b o u t s un d e r n e a t h yo u r P a g e 52 .sh /mnt/home/drysdalk/notes/hosting. Fo r ex a m p l e . If w e se a r c h for file s an d not dir e c t o r i e s . Th e y ha d to us e sudo to do this.txt /mnt/home/drysdalk/notes/email. Thi s m a k e s se n s e . Thi s is do n e wit h the –user an d –group fla g s of find.jpg /mnt/home/drysdalk/files/email/business/aroberts /mnt/home/drysdalk/files/email/business/paulj /mnt/home/drysdalk/files/email/business/callum /mnt/home/drysdalk/files/email/business/richard /mnt/home/drysdalk/files/email/personal/furby-list /mnt/home/drysdalk/files/scripts/script1.jpg /mnt/home/drysdalk/files/images/cat2.jpg /mnt/home/drysdalk/files/images/furby.[drysdalk@ioprov2 drysdalk]$ ls files/ notes/ [drysdalk@ioprov2 drysdalk]$ find ~ -type d /mnt/home/drysdalk /mnt/home/drysdalk/files /mnt/home/drysdalk/files/images /mnt/home/drysdalk/files/email /mnt/home/drysdalk/files/email/personal /mnt/home/drysdalk/files/email/business /mnt/home/drysdalk/files/scripts /mnt/home/drysdalk/notes N o ti c e that the loc a t i o n of the ho m e dir e c t o r y its elf (/mnt/home/drysdalk) is ret u r n e d as the ver y first res u l t. w e fin d onl y the co n t e n t s of the dir e c t o r i e s but no res u l t s for the act u a l dir e c t o r i e s the m s e l v e s . sin c e the y ar e not file s: [drysdalk@ioprov2 drysdalk]$ find ~ -type f /mnt/home/drysdalk/files/images/cat1. H o w e v e r . that will by defi ni ti o n be the ver y first dir e c t o r y that yo u fin d. an d so the file is o w n e d by root. sin c e if yo u ar e star ti n g yo u r se a r c h for dir e c t o r i e s fro m the ho m e dir e c t o r y . let’s sa y that an o t h e r m e m b e r of the sy st e m s ad m i n i s t r a t i o n tea m ha s co pi e d a file co n t a i n i n g instr u c t i o n s for a tas k yo u ar e to car r y out int o so m e loc a t i o n un d e r n e a t h yo u r ho m e dir e c t o r y .txt [drysdalk@ioprov2 drysdalk]$ Finding files based on their owner or group Th e last typ e of fin d that yo u ar e likel y to ev e r ne e d to do is to loc a t e a file or dir e c t o r y ba s e d on the o w n e r or gr o u p as s o c i a t e d wit h it.sh /mnt/home/drysdalk/files/scripts/script2.

an d quit e a ti m e.txt [drysdalk@ioprov2 drysdalk]$ Askin g find to give you more information Th e r e is on e ot h e r feat u r e of find that yo u ca n us e alo n g wit h an y typ e of se a r c h yo u ar e car r y i n g out. sin c e quit e oft e n the ver y ne x t thin g yo u’ll do on c e fin d ha s fou n d w h a t e v e r yo u’r e loo k i n g for is per f o r m an ls –l on it.ho m e dir e c t o r y the y put it. P a g e 53 . if yo u kn e w that the file w a s as s o c i a t e d wit h the ‘sys’ gr o u p . Thi s ca n be ver y us e f u l.txt [drysdalk@ioprov2 drysdalk]$ Si m i l a r l y. It is po s s i b l e for find to aut o m a t i c a l l y per f o r m an ls –l on w h a t e v e r it fin d s. yo u co u l d ha v e tra c k e d it do w n like this: [drysdalk@ioprov2 drysdalk]$ find ~ -group sys /mnt/home/drysdalk/files/docs/your-instructions.sa v e r . Y o u co u l d tra c k it do w n wit h a find co m m a n d like thi s: [drysdalk@ioprov2 drysdalk]$ find ~ -user root /mnt/home/drysdalk/files/docs/your-instructions.

the r e’ s that lar g e nu m b e r at the ver y be g i n n i n g – yo u ca n ign o r e this for no w . or to ret u r n tho s e line s w hi c h do not co n t a i n the stri n g .sh 50430336 4 -rw-rw-r-1 drysdalk drysdalk 40 Feb 19 20:15 /mnt/home/drysdalk/scripts/script. but so m e ha v e mi x t u r e of lo w e r.insen sitive searchin g Let’s co n s i d e r the foll o w i n g sc e n a r i o . yo u’ll noti c e that the inf o r m a t i o n yo u get ba c k isn’t precisely like the lon g dir e c t o r y listi n g that an ls –l w o u l d giv e yo u. onl y wit h a twist. Lik e sort an d find. H e r e’ s a de s c r i p t i o n of a fe w of the ext r a thi n g s that grep ca n do. ho w e v e r . tho u g h . but not car e ab o u t w h e t h e r the stri n g is P a g e 54 . w h e r e all the lett e r s ar e in lo w e r. or in up p e r.txt furbyforum.ca s e .ca s e ha p p e n s if w e try our pr e v i o u s se a r c h the n ? do m a i n list fro m the na m e s in the file be e n writt e n in a alo n e . it’s ca p a b l e of a lot m o r e tha n su c h si m p l e se a r c h i n g . o w n e r . W h a t [drysdalk@ioprov2 drysdalk]$ cat domains.txt AdoptAFurby. w h a t w e ne e d to car r y out is a ca s e.COM furbyforum.st a m p an d na m e of the file. ha v e grep re p e a t our se a r c h . yo u’ v e se e n ho w to us e grep to se a r c h for a sp e c i f i c strin g in on e or m o r e file s in the cur r e n t dir e c t o r y .uk [drysdalk@ioprov2 drysdalk]$ A s yo u ca n se e. an d ho w yo u mi g h t like to us e the m .com FURBY. S o.an d up p e r. siz e.3 grep revisited S o far. Im a g i n e our last se c ti o n ag a i n . ho w e v e r .sh [drysdalk@ioprov2 drysdalk]$ N o w . S o m e do m a i n ha v e be e n writt e n all in lo w e r. In par ti c u l a r .uk [drysdalk@ioprov2 drysdalk]$ grep furby domains.ins e n s i t i v e se a r c h – that is.sh -ls 57409890 4 -rw-rw-r-1 drysdalk drysdalk 90 Feb 19 20:15 /mnt/home/drysdalk/script. Y o u ca n still cle a r l y se e the per m i s s i o n s . w e onl y got on e res u lt ba c k – onl y on e of the do m a i n s co n t a i n e d the exact stri n g ‘fur b y’. For ex a m p l e : [drysdalk@ioprov2 drysdalk]$ find ~ -type f -name *. ti m e. 5.ca s e.co.ca s e . gr o u p .Y o u ca n get fin d to do this wit h the –ls fla g.co. Ca se.

For ex a m p l e : [drysdalk@ioprov2 drysdalk]$ grep -l furby domains* domains-13 domains-36 domains-42 domains-55 domains-78 domains-93 [drysdalk@ioprov2 drysdalk]$ S o rat h e r tha n se ei n g ev e r y sin g l e line in the s e file s wit h the stri n g ‘fur b y’. but w e just w a n t to su m m a r i s e our res u lt s. W e w a n t to do the sa m e se a r c h as bef o r e . an d w hi c h w e ca n dis c a r d . w e ca n se e at a gla n c e w hi c h file s w e sh o u l d pa y m o r e att e n t i o n to. all co n t a i n i n g a wi d e vari e t y of do m a i n na m e s . domains-1 thr o u g h domains-100.ca s e . Thi s w a y. w e si m p l y sa w the na m e s of the file s that m a t c h e d our se a r c h . rat h e r tha n se ei n g ev e r y sin g l e lin e in ea c h file that m a t c h e s the res u l t s.co.ca s e lett e r L) of grep.COM furbyforum. W e do thi s wit h the –i fla g: [drysdalk@ioprov2 drysdalk]$ grep -i furby domains.com FURBY.txt AdoptAFurby. lo w e r. Thi s is do n e wit h the –l fla g (a lo w e r. W e w a n t to kn o w the na m e s of the file s w e fin d. or an y co m b i n a t i o n of the tw o.ca s e.fou n d in up p e r. P a g e 55 . W e ha v e in our cur r e n t dir e c t o r y on e hu n d r e d lar g e file s.uk [drysdalk@ioprov2 drysdalk]$ Summ ari sin g our results when dealing with large files Let’s im a g i n e a ne w sit u a t i o n .

an d w e sp e c i f i e d w e onl y w a n t e d to se e the na m e s of the file s fou n d rat h e r tha n the act u a l line s wit h the –l fla g. w e co ul d typ e: [drysdalk@ioprov2 drysdalk]$ grep -r furby * domains. foll o w e d by the act u a l line s that w e r e fou n d . Fo r ex a m p l e .co. an d is in fact a co m p l e t e pr o g r a m m i n g lan g u a g e in an d of itself. pr e c e d e d by its loc a t i o n if it is in a su b. as w ell as the file s in the cur r e n t dir e c t o r y . W e do n’t ne e d to w o r r y ab o u t that her e. A n y an d all of the fla g s of grep ca n be co m b i n e d to ac h i e v e d the de si r e d eff e c t.dir e c t o r i e s wit h the –r fla g.com ! [drysdalk@ioprov2 drysdalk]$ H e r e w e se e the na m e of ea c h file.txt:furby.com domains.4 The awk comm a nd N o w w e co m e to a co m m a n d that. E ntir e bo o k s co u l d be (and ha v e be e n) writt e n on the su b j e c t of this on e co m m a n d alo n e . Th e r e is on e parti c u l a r feat u r e of awk that is us e d m o r e oft e n tha n an y ot h e r . to se a r c h for ‘fur b y’ not onl y in the file s in the cur r e n t dir e c t o r y but in all su b. Thi s is do n e wit h the –r fla g. an d that is its abilit y to pri nt out an y sp e c i f i c field or gr o u p of fiel d s fro m the inp u t it P a g e 56 . so lon g as the y do not co n t r a d i c t ea c h ot h e r .directories Th e last feat u r e of grep that yo u ar e likel y to fin d of int e r e s t is its abilit y to se a r c h the co n t e n t s of su b.dir e c t o r y .com domains. tho u g h . w h e n co m b i n e d wit h pip e s .na m e d awk co m m a n d is on e of the m o s t ver s a t i l e an d po w e r f u l av ail a b l e in Lin u x .txt:furbyforum. Th e od d l y.Searching the contents of sub.txt:adoptafurby.dir e c t o r i e s of it.uk email/personal/furby-list:Hey ! Check out furby. 5.dir e c t o r i e s . w e per f o r m e d a ca s e ins e n s i t i v e se a r c h wit h the –i fla g. For ex a m p l e : [drysdalk@ioprov2 drysdalk]$ grep -ril furby * domains.txt email/personal/furby-list [drysdalk@ioprov2 drysdalk]$ H e r e . is ca p a b l e of so m e ver y us e f u l thi n g s . w e se a r c h e d file s in the cur r e n t dir e c t o r y an d all its su b.

If w e loo k at the out p u t of an ls –l no w : [drysdalk@ioprov2 drysdalk]$ ls -l total 24 -rw-rw-r-1 drysdalk drysdalk -rw-rw-r-1 drysdalk sys -rw-rw-r-1 drysdalk sys -rw-rw-r-1 drysdalk sys -rw-rw-r-1 drysdalk drysdalk -rwx-----1 aroberts sys [drysdalk@ioprov2 drysdalk]$ 13 36 62 30 91 73 Feb Feb Feb Feb Feb Feb 19 19 19 19 19 19 21:14 21:14 21:14 21:14 21:14 21:15 cat.jpg script. awk.rec e i v e s . Let’s sa y that w e w a n t to aut o m a t i c a l l y print out onl y the o w n e r of a file fro m a lon g dir e c t o r y listi n g. to pri nt the thir d fiel d.txt file2. ha s the abilit y to print out the co n t e n t s of a sp e c i f i c na m e d fiel d. for ex a m p l e .sh H e r e w e ca n se e a coll e c t i o n of mi x e d file s. w e w o u l d ne e d to us e the sy n t a x of: awk ‘{print $3}‘ S o let’s se e w h a t ha p p e n s if w e pip e the out p u t of an ls –l thr o u g h just su c h an awk co m m a n d : [drysdalk@ioprov2 drysdalk]$ ls -l | awk '{print $3}' drysdalk drysdalk drysdalk drysdalk drysdalk aroberts [drysdalk@ioprov2 drysdalk]$ W h y that initi al bl a n k lin e in the out p u t of awk ? B e c a u s e the ver y first line in the out p u t of the ls –l is: total 24 P a g e 57 . co u n t i n g al o n g fro m the left. It’s this sin g l e feat u r e that w e’ll ex a m i n e no w .txt file3.jpg file1. as pr e v i o u s l y m e n t i o n e d . an d als o opti o n a l l y to re-arr a n g e or re-for m a t the m . N o w the o w n e r of a file is the thir d field. wit h diff e ri n g o w n e r s h i p s an d per m i s s i o n s . Th e sy n t a x for this is as foll o w s : awk ‘{print $<number of field>}’ S o.txt furby.

qu o t e s . e m p t y line. w e ca n als o pla c e our o w n text in the out p u t of awk. by pla ci n g it in the pri nt co m m a n d in bet w e e n do u b l e. N o w this ca n be us e f u l. for ea c h of the file s. S o w e w o u l d ne e d to us e the follo w i n g co m m a n d : [drysdalk@ioprov2 drysdalk]$ ls -l | awk '{print $4}' drysdalk sys sys sys drysdalk sys [drysdalk@ioprov2 drysdalk]$ A n d on c e ag a i n . w h e r e w e us e d awk to pri nt out the o w n e r of the file s. w e ca n se e that the gr o u p is the fou r t h fiel d. let’s sa y w e w a n t e d to print the file n a m e .$3. La s t l y (and this is w h e r e thi n g s get quit e a bit m o r e co m p l i c a t e d). W h a t if w e w a n t e d to pri nt out onl y the gr o u p for ea c h of the file s ? C o u n t i n g al o n g fro m the left ag a i n . follo w e d by the thir d fiel d (the o w n e r).sh aroberts sys [drysdalk@ioprov2 drysdalk]$ S o her e w e pri nt e d out the ni nt h field (the file n a m e). but it is ev e n m o r e us e f u l if w e co m b i n e fiel d s tog e t h e r . S o the be s t that awk ca n do in thi s circ u m s t a n c e is dis p l a y a bla n k . an d en d i n g wit h the fou r t h fiel d (the gr o u p ). yo u will se e that w e ha v e ind e e d su c c e s s f u l l y pri nt e d out the o w n e r .jpg drysdalk drysdalk script. ho w e v e r . in the or d e r that the y ap p e a r e d in the lon g dir e c t o r y listi n g.jpg drysdalk drysdalk file1. foll o w e d by the o w n e r an d gr o u p . W e ca n se p a r a t e fiel d s wit h a co m m a in awk.txt drysdalk sys file3. For ex a m p l e .$4}' cat.Thi s lin e do e s not ha v e a thir d field – it onl y ha s tw o fiel d s in tot al. W e’ll loo k ag a i n at our ver y first ex a m p l e ab o v e . to get it to pri nt the m out se p a r a t e d by a sin gl e sp a c e : [drysdalk@ioprov2 drysdalk]$ ls -l | awk '{print $9. Let’s sa y w e w a n t e d to put a de s c r i p t i o n P a g e 58 .txt drysdalk sys file2. an d not h i n g els e. an d onl y the o w n e r . w e ha v e the inf or m a t i o n w e w e r e aft e r. Le a v i n g that asi d e .txt drysdalk sys furby. sin c e the r e is no dat a for it to pri nt.

jpg is owned by user drysdalk and group drysdalk The file file1.txt is owned by user drysdalk and group sys The file furby.$3}' Owner: Owner: drysdalk Owner: drysdalk Owner: drysdalk Owner: drysdalk Owner: drysdalk Owner: aroberts [drysdalk@ioprov2 drysdalk]$ H e r e’ s a m o r e co m p l e x ex a m p l e If w e w a n t e d to pr o d u c e a nic e hu m a nrea d a b l e re p o r t listi n g ea c h of the file s in the cur r e n t dir e c t o r y .jpg is owned by user drysdalk and group drysdalk The file script.txt is owned by user drysdalk and group sys The file file2. just as w e did ab o v e . an d the n putti n g a co m m a bet w e e n the text an d the fiel d w e w a n t to pri nt.jpg is owned by user drysdalk and group drysdalk The file file1.$4}' The file is owned by user and group The file cat.txt is owned by user drysdalk and group sys The file file3."is owned by user".txt is owned by user drysdalk and group sys The file file2. w e ha v e a bo g u s first lin e in the out p u t of awk. Fo r ex a m p l e : [drysdalk@ioprov2 drysdalk]$ ls -l | awk '{print “Owner:”.qu o t e s in the awk pri nt co m m a n d . be c a u s e the ver y first lin e of ls –l do e s n ’ t ha v e en o u g h fiel d s to pr o d u c e the inf o r m a t i o n w e’ v e as k e d for.jpg is owned by user drysdalk and group drysdalk The file script. If w e w a n t e d to. an d w h a t gr o u p the y ar e as s o c i a t e d wit h."and group". w e co ul d do this: [drysdalk@ioprov2 drysdalk]$ ls -l | awk '{print "The file".txt is owned by user drysdalk and group sys The file file3.$9. si m p l y by putti n g “O w n e r : “ in do u b l e.$3.txt is owned by user drysdalk and group sys The file furby. w e co u l d stri p out that first lin e fro m the out p u t of ls –l bef o r e it get s to awk in the pip e li n e . by first pipi n g the out p u t thr o u g h a grep co m m a n d like thi s: [drysdalk@ioprov2 drysdalk]$ ls -l | grep -v total | awk '{print "The file "$9" is owned by user "$3" and group "$4}' The file cat. Thi s ca n be do n e fairl y ea sil y.sh is owned by user aroberts and group sys [drysdalk@ioprov2 drysdalk]$ A g a i n .of the dat a at the star t – so m e t h i n g like “O w n e r : “.sh is owned by user aroberts and group sys [drysdalk@ioprov2 drysdalk]$ P a g e 59 . w h o o w n s the m .

an d wit h putti n g yo u r o w n text in bet w e e n the m . Pl a y ab o u t wit h pri nti n g out thi s fiel d or that fro m a dir e c t o r y listin g. that if an y of our file s ha d ‘tot al’ in an y part of their na m e or o w n e r s h i p s .H e r e . If this is the first tim e yo u’ v e en c o u n t e r e d it. an d so our bo g u s lin e got dr o p p e d out of the pi p e l i n e bef o r e it rea c h e d awk. W e’ll be ha p p y to hel p. Lo o k at the first fe w ex a m p l e s of printi n g out sin g l e fiel d s. our grep –v stri p p e d out all lin e s in the lon g dir e c t o r y listin g co n t a i n i n g the text ‘tot al’. that’s awk. Y o u ca n’t ev e r da m a g e or de s t r o y an y t h i n g w h e n usi n g the print co m m a n d in awk. Tal k to ot h e r pe o p l e ab o u t it. an d awk w o u l d not ha v e ha d the op p o r t u n i t y to giv e us a su m m a r y for the m . P a g e 60 . It ca n se e m ver y co m p l e x ind e e d w h e n yo u first us e it – an d that’ s be c a u s e it is. this w o u l d ha v e ca u s e d the m to be dr o p p e d als o. E v e n bett e r – try it out on yo u r o w n sy s t e m . S o. N ot e. ho w e v e r . yo u mi g h t w ell be loo ki n g at the s e last tw o ex a m p l e s an d fin di n g the m ver y diffi c u l t to foll o w . an d the n tak e it fro m ther e. G e t t i n g to gri p s wit h awk is w ell w o r t h the eff o r t. D o n’t w o r r y. if the r e’ s an y t h i n g yo u w a n t to clarif y. Fe e l fre e to as k ot h e r m e m b e r s of the sy s t e m s ad m i n i s t r a t i o n tea m an y qu e s t i o n s yo u mi g h t ha v e . sin c e all it do e s w h e n us e d in this w a y is m o d i f y the out p u t of ot h e r co m m a n d s .

w e us e d the inp u t re-dir e c t o r < to fee d the file greeting. it is als o a pr o g r a m m i n g lan g u a g e in its o w n rig h t. sed m o d i f i e s the out p u t of ot h e r pr o g r a m s . To sa v e the out p u t an d m a k e it per m a n e n t . that co n t a i n s the text ‘Hell o!’. in m a n y w a y s . W e w a n t to ch a n g e ev e r y oc c u r r e n c e of ‘Hell o’ to ‘Go o d b y e ’ . It is als o extr e m e l y po w e r f u l . an d it perf o r m e d the de si r e d su b s t i t u t i o n .ch a n g e d for m.txt drysdalk]$ sed s/Hello/Goodbye/g < greeting. her e’ s a co m m o n earl y mi s t a k e that m a n y pe o p l e m a k e w hil s t usi n g sed: P a g e 61 . t x t. N o w . Th e sy n t a x for this is as foll o w s : sed s/<old text>/<new text>/g Fo r ex a m p l e .txt drysdalk]$ H e r e .5.txt in to sed. unl e s s yo u tell it ot h e r w i s e . Let’s sa y w e ha v e a file call e d gr e e t i n g . B ut as bef o r e .txt – yo u’ll se e fro m that fin al cat that it w a s still un c h a n g e d . w e us e an out p u t re-dir e c t o r to se n d the m o d i f i e d text to a file. an d dis pl a y s the m in their ne w l y. is quit e si mil a r to awk. sed si m p l y dis p l a y s on the ter m i n a l the ch a n g e d text. A g a i n m u c h like awk. N o t e als o that it did not act u a l l y ch a n g e the file greeting. O n e thin g it ca n do ver y w ell an d ver y qui c k l y is su b s t i t u t e on e pie c e of text for an o t h e r .5 The sed comm a nd H e r e’ s an o t h e r co m m a n d that. an d it ha s als o ha d w h o l e bo o k s writt e n ab o u t it.txt drysdalk]$ cat greeting. w e’r e onl y int e r e s t e d her e in the on e parti c u l a r bit of its fun c t i o n a l i t y that yo u ar e likel y to w a n t to us e oft e n. W e ca n do thi s as follo w s : [drysdalk@ioprov2 Hello! [drysdalk@ioprov2 Goodbye! [drysdalk@ioprov2 Hello! [drysdalk@ioprov2 drysdalk]$ cat greeting.

txt > drysdalk]$ cat greeting. S o the r e is not h i n g for it to do.txt for writi n g . the file greeting. W e do ha v e the ne w gr e e t i n g .txt.txt drysdalk]$ sed s/Hello/Goodbye/g < greeting. sin c e that is all that w a s in greeting.txt [drysdalk@ioprov2 Hello! Goodbye! [drysdalk@ioprov2 drysdalk]$ cat greeting. but the old on e is still ther e too. sin c e thi s tim e w h e n Lin u x pr e p a r e d greeting. sin c e the sy s t e m kn e w that it w a s to be de s t i n a t i o n for the out p u t of sed. an d so did not wi p e the file an d st art it afr e s h bef o r e pa s s i n g it to sed. w hi c h w a s to be ov e r w r i t t e n (rem e m b e r that > si m p l y ov e r w r i t e s a file. as yo u’ll se e fro m that fin al cat co m m a n d . it kn e w w e w e r e usi n g ap p e n d out p u t re-dir e c t i o n .txt drysdalk]$ A n d the y ar e ind e e d .txt drysdalk]$ sed s/Hello/Goodbye/g < greeting. S o bef o r e sed w a s act u a l l y ru n. Th e sy s t e m sa w that the out p u t of the co m m a n d it ha d be e n pa s s e d w a s to go to a file call e d greeting. thi s still isn’t quit e w h a t w e w a n t e d .txt >> drysdalk]$ cat greeting.txt w a s e m p t i e d out an d pr e p a r e d for ne w dat a.txt P a g e 62 . the s e ar e the first thi n g s that Lin u x de a l s wit h. w h a t w e n t wr o n g her e ? Y o u pr o b a b l y ex p e c t e d greeting.e m p t y greeting. S o the pr o p e r w a y to re pl a c e our ori gi n a l file wit h the ne w gr e e t i n g w o u l d be: [drysdalk@ioprov2 drysdalk]$ cat greeting. an d it quit e rig ht l y writ e s its out p u t – w hi c h is not h i n g at all.txt w h e n sed op e n e d it – ba c k to the file. the file is no w e m p t y – its co n t e n t s w e r e de s t r o y e d . w o u l d the co n t e n t s ha v e be e n pr e s e r v e d ? Let’s try it an d se e: [drysdalk@ioprov2 Hello! [drysdalk@ioprov2 greeting.txt to co n t a i n the text ‘Go o d b y e!’. H o w e v e r .txt. Th e rea s o n for thi s is that an y tim e inp u t or out p u t re-dir e c t o r s ar e us e d . sed is act u a l l y run – an d tak e s as its inp u t the ne w l y. bef o r e act u a l l y ru n n i n g the co m m a n d that us e s the m .txt [drysdalk@ioprov2 [drysdalk@ioprov2 drysdalk]$ cat greeting.[drysdalk@ioprov2 Hello! [drysdalk@ioprov2 greeting.txt drysdalk]$ S o. Inst e a d . an d do e s not ap p e n d to it). S o if w e ha d us e d ap p e n d out p u t re-dir e c t i o n . N o w that the out p u t file is rea d y .

an d as yo u ca n se e all the ot h e r text w a s left ex a c t l y as it ori gi n a l l y w a s. Thi s w a y. on e that do e s not yet exi st (or w hi c h w e do n’t car e ab o u t ov e r. The awk command is scary. P a g e 63 . W e the n m o v e thi s ne w l y.txt drysdalk]$ W h a t w e ha v e to do is writ e our out p u t to a diff e r e n t file.txt | sed s/cd/ls/g The grep command can be used to search files.txt greeting. fin all y repl a c i n g it in a saf e m a n n e r .txt drysdalk]$ cat greeting.txt to co n t a i n the cor r e c t inf o r m a t i o n . Fo r ex a m p l e : [drysdalk@ioprov2 drysdalk]$ cat linux-info. W e no w ha v e su c c e s s f u l l y up d a t e d greeting. The awk command is scary.Hello! [drysdalk@ioprov2 greeting2.txt drysdalk]$ mv greeting2.txt The grep command can be used to search files.txt > drysdalk]$ cat greeting2. The ls command can be used to obtain a directory listing.cr e a t e d file on top of the ori gi n a l. [drysdalk@ioprov2 drysdalk]$ H e r e w e su c c e s s f u l l y up d a t e d linux-info. The cd command can be used to obtain a directory listing. our out p u t is sa v e d to a diff e r e n t loc a t i o n fro m the origi n a l.txt to rea d ‘Go o d b y e!’ rat h e r tha n ‘Hell o!’ U si n g se d do e s not aff e c t an y t h i n g ex c e p t the text that it m a t c h e s .txt [drysdalk@ioprov2 Goodbye! [drysdalk@ioprov2 [drysdalk@ioprov2 Goodbye! [drysdalk@ioprov2 drysdalk]$ sed s/Hello/Goodbye/g < greeting. [drysdalk@ioprov2 drysdalk]$ cat linux-info.writi n g).

like m o s t Lin u x co m m a n d s . The uniq comm a nd P a g e 64 . The wc comm a nd Th e a m u s i n g l y. that’s sed. 5. Its sy n t a x is fairly str ai g h t f o r w a r d .txt 3 15 64 example.txt [drysdalk@ioprov2 drysdalk]$ A n d that’s re all y all ther e is to sa y ab o u t wc. w e onl y w a n t to us e wc to get the nu m b e r of line s.na m e d wc co m m a n d is us e d to giv e yo u a w or d c ou n t for a file. I am the second line.S o.ca s e s cor r e c t in the text yo u w a n t to se a r c h for an d repl a c e . an d the kin d of sit u a t i o n s that yo u mi g h t w a n t to us e the m in.6 Some other useful text proce s sin g comm a n d s W e’ll en d this se ct i o n on a light e r not e. Th a t’ s do n e wit h the –l fla g: [drysdalk@ioprov2 drysdalk]$ wc -l example. or gr o u p of file s. I am the third line. but yo u ca n run in to so m e na s t y sit u a t i o n s if yo u’r e not car e f u l ab o u t the de s t i n a t i o n s of yo u r out p u t re-dir e c t o r s . W e’ll loo k at so m e ot h e r si m p l e co m m a n d s that ar e us e f u l for text pr o c e s s i n g pur p o s e s . so w e’ll ju m p str ai g h t in wit h an ex a m p l e : [drysdalk@ioprov2 drysdalk]$ cat example. S o m a k e sur e yo u get yo u r lo w e r.txt I am the first line.txt 3 example. an d it’s ca s e se n s i t i v e . [drysdalk@ioprov2 drysdalk]$ wc example. O h. N ot quit e as sc a r y as awk. to be ho n e s t).txt [drysdalk@ioprov2 drysdalk]$ Th e thr e e nu m b e r s w e’ v e be e n giv e n for the file br e a k do w n as follo w s : 1 st nu m b e r – nu m b e r of line s 2 n d nu m b e r – nu m b e r of w o r d s 3 rd nu m b e r – nu m b e r of ch a r a c t e r s S o m e t i m e s (most ti m e s .an d up p e r.

Th e uniq co m m a n d ca n onl y w o r k on sort e d dat a. the sy n t a x is ver y str ai g h t f o r w a r d . so w e’ll star t wit h an ex a m p l e : [drysdalk@ioprov2 drysdalk]$ cat example. if ther e ar e thr e e ‘cat’ line s sc a t t e r e d thr o u g h o u t the file (as in our se c o n d ex a m p l e).txt | uniq cat furby cat furby cat furby dog furby dog [drysdalk@ioprov2 drysdalk]$ Th e rea s o n that uniq co u l d n ’ t pr o v i d e us wit h the uni q u e line s in the file is that thi s ti m e. an d se e if yo u ca n gu e s s w h y it do e s n ’ t w o r k: [drysdalk@ioprov2 drysdalk]$ cat example.txt | uniq cat dog furby [drysdalk@ioprov2 drysdalk]$ S o far.Th e pur p o s e of uniq is to ret u r n onl y tho s e lin e s in a file w hi c h ar e uniq ue. an d not rep e a t i n g du p l i c a t e s . sin c e it eli m i n a t e s du p l i c a t e s ba s e d on their dir e c t pr o x i m i t y to on e an o t h e r . P a g e 65 . so go o d . H o w e v e r . the inf o r m a t i o n in the file w a s n’ t alr e a d y alp h a b e t i c a l l y sort e d sort e d .txt cat furby cat furby cat furby dog furby dog [drysdalk@ioprov2 drysdalk]$ cat example. sin c e the y ar e reg a r d e d as se p a r a t e oc c u r r e n c e s of the stri n g. Lik e wc. the y all get allo w e d thr o u g h . B ut tak e a loo k at this ne x t ex a m p l e . For ex a m p l e .txt cat cat cat dog dog furby furby furby furby [drysdalk@ioprov2 drysdalk]$ cat example. if it se e s thr e e line s sa yi n g ‘cat’ in a ro w it will re d u c e the m to onl y on e.

as their na m e s va g u e l y im p l y. fro m lea s t fre q u e n t to m o s t : [drysdalk@ioprov2 drysdalk]$ cat example.txt | sort | uniq -c | sort -bn 2 dog 3 cat 4 furby [drysdalk@ioprov2 drysdalk]$ The head and tail comm a nd s N o w w e’ll loo k at tw o ot h e r co m m a n d s that ar e ver y us e f u l. head an d tail. w e ca n of co u r s e sort this out p u t nu m e r i c a l l y . Fo r ex a m p l e : [drysdalk@ioprov2 drysdalk]$ cat example. w e ne e d to pip e it thr o u g h sort first.txt | sort | uniq -c 3 cat 2 dog 4 furby [drysdalk@ioprov2 drysdalk]$ A n d if yo u like.S o.txt cat furby cat furby cat furby dog furby dog [drysdalk@ioprov2 drysdalk]$ cat example. like so: [drysdalk@ioprov2 drysdalk]$ cat example. bef o r e pa s s i n g it to uniq: [drysdalk@ioprov2 drysdalk]$ cat example.txt | sort | uniq cat dog furby [drysdalk@ioprov2 drysdalk]$ Th e r e is on e par ti c u l a r fla g of uniq that yo u’r e likel y to us e m o r e tha n an y ot h e r. to get the m in or d e r . an d ver y si m p l e . for a file like this. Thi s m a k e s uniq print the nu m b e r of ti m e s that ea c h line oc c u r r e d in a file. an d that’s the –c fla g. res p e c t i v e l y . giv e yo u the first fe w line s of a file an d the last fe w line s of a file.txt The first line. P a g e 66 .

The seventh line. The eighth line.txt The first line. The ninth line. [drysdalk@ioprov2 drysdalk]$ S o in ea c h ca s e. The eighth line. The third line. The second line. Fo r ex a m p l e : P a g e 67 . The eleventh line. The thirteenth line. The sixth line. The thirteenth line. The eleventh line. [drysdalk@ioprov2 drysdalk]$ A n d her e’ s w h a t w e se e wit h tail: [drysdalk@ioprov2 drysdalk]$ tail example. The fourth line. The fourteenth line. The fifteenth line. The fifteenth line. W h a t if w e w a n t a diff e r e n t nu m b e r of lin e s.The second line. The seventh line. The ninth line. [drysdalk@ioprov2 drysdalk]$ H e r e’ s w h a t w e se e wit h head: [drysdalk@ioprov2 drysdalk]$ head example. The fifth line. The sixth line. tho u g h ? E a s y – w e just us e the nu m b e r of line s w e w a n t as the fla g w e pa s s to the co m m a n d . The twelfth line. The third line. The tenth line. The seventh line. The tenth line.txt The sixth line. The ninth line. The tenth line. The eighth line. The fourteenth line. The fourth line. The fifth line. The twelfth line. w e se e eit h e r the first ten line s or the last ten lin e s – thi s is the def a u l t be h a v i o u r for bot h the s e co m m a n d s .

txt The thirteenth line. Thi s is ver y us e f u l w h e n yo u w a n t to ke e p an ey e on a log file. [drysdalk@ioprov2 drysdalk]$ [drysdalk@ioprov2 drysdalk]$ tail -3 example. an d that is the –f fla g. w e co ul d do this: [drysdalk@ioprov2 drysdalk]$ cat example. the s e co m m a n d s ar e n’t terri bl y us e f u l.txt | sort | uniq -c | sort –bg | tail -1 4 furby [drysdalk@ioprov2 drysdalk]$ Th e r e’ s an o t h e r feat u r e of tail sp e c i f i c a l l y that’s extr e m e l y us e f u l. The third line. N o w .[drysdalk@ioprov2 drysdalk]$ head -3 example. Fo r ex a m p l e . an d ke e p s up d a t i n g yo u r ter m i n a l ev e r y ti m e ne w line s ap p e a r at the en d of that file. A n d so on. Thi s file is up d a t e d on c e a mi n u t e .log 20/02/2007 11:14 Nothing happening.line help P a g e 68 .txt ? W e l l.7 The man comm a nd. but w h a t it do e s is att a c h to a file. The second line. A s I sa y. w h a t if w e onl y w a n t e d to kn o w the ter m that oc c u r r e d the m o s t in example. a bit har d to eff e c t i v e l y de m o n s t r a t e on pa p e r . or an y ot h e r file that is ch a n g i n g in re al. this is a bit har d to de m o n s t r a t e in an ex a m p l e on a writt e n pa g e .log 20/02/2007 11:14 Nothing happening. goi n g ba c k to our pr e v i o u s uniq ex a m p l e s . on e mi n u t e lat er yo u r ter m i n a l mi g h t loo k like: [drysdalk@ioprov2 drysdalk]$ tail -f server. B ut w h e n co m b i n e d wit h ot h e r co m m a n d s in pip e s .txt The first line. For inst a n c e . the y ar e. 20/02/2007 11:15 Nothing happening. Y o u ca n att a c h a tail to it as foll o w s : [drysdalk@ioprov2 drysdalk]$ tail -f server. N o w .log. The fifteenth line. 5. let’s sa y yo u w a n t to ke e p an ey e on the file server.ti m e that yo u w a n t to m o n i t o r . and comm a n d. The fourteenth line. [drysdalk@ioprov2 drysdalk]$ O n their o w n . but that’s the ge n e r a l ide a be h i n d tail –f.

La s t l y, w e’ll loo k at a co m m a n d that is us e d to giv e yo u on- line hel p. Li n u x m a i n t a i n s its o w n built- in m a n u a l , listin g the sy n t a x an d us a g e inf o r m a t i o n for al m o s t all of its co m m a n d s . N o w yo u mi g h t w ell be w o n d e r i n g w h y this w a s n ’ t the ver y first thin g that w e talk e d ab o u t – the rea s o n is that w hil s t so m e m a n u a l pa g e s ca n be ver y us e f u l, ot h e r s ca n be ver y co n f u s i n g , es p e c i a l l y w h e n yo u’r e ne w to Lin u x . Thi s on- lin e m a n u a l is ac c e s s e d wit h the man co m m a n d . Th e sy n t a x is ver y si m p l e :
man <name of command whose manual page you want to read>

Fo r ex a m p l e , to re a d the m a n u a l pa g e for ls, yo u w o u l d typ e:
[drysdalk@ioprov2 drysdalk]$ man ls

A n d the m a n u a l pa g e w o u l d the n ap p e a r . Y o u ca n na v i g a t e thr o u g h m a n u a l pa g e s on e scr e e n at a tim e by pr e s s i n g the sp a c e b a r to m o v e for w a r d , an d the b ke y to m o v e ba c k w a r d s . Y o u ca n als o us e the cur s o r ke y s to m o v e ba c k an d fort h on e line at a tim e. S o m e co m m a n d s ca n als o giv e yo u inf or m a t i o n ab o u t their us a g e or sy n t a x , by usi n g on e of tw o sp e c i f i c fla g s. M o s t Lin u x co m m a n d s will un d e r s t a n d the fla g s –? an d ––help (note that the r e ar e tw o da s h e s in thi s last on e). Fo r ex a m p l e , let’s sa y yo u w a n t e d full inf o r m a t i o n on the us a g e an d sy n t a x of wc. Y o u co ul d typ e:
[drysdalk@ioprov2 drysdalk]$ wc --help Usage: wc [OPTION]... [FILE]... Print byte, word, and newline counts for each FILE, and a total line if more than one FILE is specified. With no FILE, or when FILE is -, read standard input. -c, --bytes print the byte counts -m, --chars print the character counts -l, --lines print the newline counts -L, --max-line-length print the length of the longest line -w, --words print the word counts --help display this help and exit --version output version information and exit Report bugs to <bug-coreutils@gnu.org>. [drysdalk@ioprov2 drysdalk]$

S o if ev e r yo u ar e st u c k, this is a go o d thin g to re m e m b e r – tho u g h so m e t i m e s un d e r s t a n d i n g w h a t a co m m a n d ’ s so- call e d “hel p” is tryi n g to tell yo u ca n be as diffi c u l t as fig u r i n g it out yo u r s e l f.
P a g e 69

P a g e 70

5.7 End- of-section summ ary W e l l, w e’ v e st e p p e d thi n g s up quit e a bit in this se ct i o n . D o n’t w o r r y if an y of it – par ti c u l a r l y the us a g e of awk an d sed – isn’t too cle a r to yo u yet. Th e be s t w a y to get to gri p s wit h co m m a n d s this co m p l e x is to try usi n g the m yo u r s e l f, on yo u r o w n sy s t e m . To rec a p , the n, in thi s se c t i o n w e ha v e lear n e d ho w to: - Use - Use - Use - Use - Use - Use file - U s e uniq to obt a i n onl y tho s e lin e s in a file w hi c h ar e uni q u e - U s e head an d tail to vie w the be g i n n i n g an d en d of a file, res p e c t i v e l y - C o n s u l t on- lin e hel p wit h the man co m m a n d , or the -? A n d ––help fla g s
sort to perf o r m m o r e co m p l e x typ e s of sorti n g find to loc a t e a wi d e r vari e t y of diff e r e n t file s an d dir e c t o r i e s grep to car r y out m o r e co m p l e x an d in-de p t h se a r c h e s awk to pri nt out sp e c i f i c field s in the out p u t of a co m m a n d sed to se a r c h for an d repl a c e par ti c u l a r phr a s e s wit hi n a file wc to obt a i n a co u n t of the lin e s, w o r d s an d ch a r a c t e r s in a

P a g e 71

but ev e r y re m o t e or loc a l us e r w h o is log g e d on to a Li n u x sy st e m ha s thei r o w n ter m i n a l as s o c i a t e d wit h the m . TTY Thi s sh o w s the ter m i n a l that the us e r w h o lau n c h e d the pr o c e s s (in this ca s e . tho u g h old PI D nu m b e r s ca n be re-us e d w h e n w h a t e v e r pr o c e s s w a s usi n g the m is finis h e d . Th e ide a s an d co m m a n d s w e’ll be loo ki n g at her e ar e ba si c a l l y w h a t co m p r i s e the fun d a m e n t a l skills of sy st e m s ad m i n i s t r a t i o n . W e ha v e fou r col u m n s . TI M E an d C M D . it is loa d e d in to m e m o r y .6. Th e PI D is a uni q u e ide n t i fi e r as s o c i a t e d wit h ev e r y pr o c e s s . 6. A ter m i n a l ca n be tho u g h t of as a virt u a l ke y b o a r d an d m o n i t o r – it is the virt u a l P a g e 72 . yo u ca n just typ e ps on its o w n to se e so m e ba si c inf o r m a t i o n ab o u t all pr o c e s s e s cur r e n t l y run n i n g on the sy st e m that bel o n g to yo u: [drysdalk@ioprov2 drysdalk]$ ps PID TTY TIME CMD 1648 pts/7 00:00:00 bash 31574 pts/7 00:00:00 ps [drysdalk@ioprov2 drysdalk]$ Let’s loo k at ea c h bit of this pr o c e s s listi n g in tur n. TT Y . yo u) w a s co n n e c t e d to w h e n it be g a n ru n n i n g . w h e n yo u ru n ls. Y o u ca n vie w the pr o c e s s e s run n i n g on a sy s t e m wit h the ps co m m a n d . an d a pr o c e s s is cr e a t e d that car ri e s out w h a t e v e r tas k yo u as k e d ls to per f o r m . At its si m p l e s t . an d rel e a s e s the m ba c k to the sy st e m .1 Proce s s e s E v e r y run n i n g pr o g r a m on a Lin u x sy st e m is kn o w n as a proces s . For ex a m p l e . PI D. N o tw o ru n n i n g pr o c e s s e s ca n ev e r ha v e the sa m e PI D . Thi s on e is a bit tric ki e r to ex p l a i n . Advan ced concept s In this se ct i o n w e’ll dis c u s s so m e ad v a n c e d Lin u x sy s t e m co n c e p t s . Th e y ea c h ha v e the follo w i n g meaning s PID Thi s sh o w s the P roc e s s ID of ea c h of the pr o c e s s e s . Y o u ca n thi n k of a pr o c e s s as an acti v e co p y in the sy st e m ’ s m e m o r y of a bi n a r y pr o g r a m that is stor e d on the sy st e m ’ s dis c.

de v i c e that is us e d to allo w the re m o t e Lin u x sy st e m to get its inp u t the ke y b o a r d att a c h e d to yo u r o w n P C, an d to se n d its out p u t ba c k yo u r o w n P C’ s m o n i t o r . E a c h us e r log g e d on to a sy st e m ha s a uni q u e ter m i n a l as s o c i a t e d the m . N o tw o us e r s ca n be co n n e c t e d to the sa m e ter m i n a l si m u l t a n e o u s l y . A g a i n , like PI D s , ter m i n a l s ca n be re-iss u e d w h e n per s o n w h o is cur r e n t l y usi n g the m log s off, thu s fre ei n g the m up.

fro m to wit h the

TIM E Th e TI M E col u m n do e s not sh o w yo u the tim e of da y that a pr o c e s s w a s lau n c h e d at, w hi c h is w h a t yo u mi g h t first ex p e c t . R at h e r , it sh o w s the tot al a m o u n t of cu m u l a t i v e C P U tim e that a pr o c e s s ha s co n s u m e d thr o u g h o u t its lifeti m e . N o w this isn’t as si m p l e as it so u n d s – if yo u st art a pr o g r a m at 1 P M an d ch e c k ag a i n at 2P M to se e ho w m u c h C P U tim e that it ha s co n s u m e d , yo u ar e likel y to fin d the val u e is onl y a fe w se c o n d s , or a fe w mi n u t e s at m o s t. Th e rea s o n for thi s is that a pr o c e s s do e s not st e a d i l y co n s u m e all the C P U ’ s ti m e w h e n it is ru n n i n g . If it did, the r e w o u l d be no op p o r t u n i t y for an y ot h e r pr o g r a m on the sy st e m to do an y t h i n g , sin c e the C P U w o u l d sp e n d its entir e ti m e ser vi n g on e sin g l e pr o c e s s . As a res u lt, it w o u l d ne v e r get the ch a n c e to giv e an y run- tim e to an y ot h e r pr o c e s s e s , incl u d i n g vital op e r a t i n g sy st e m on e s . In ot h e r w o r d s , the sy st e m w o u l d be co m p l e t e l y un- us a b l e . S o, Li n u x onl y giv e s as m u c h C P U tim e to ea c h pr o c e s s as it ab s o l u t e l y req u i r e s in or d e r to do w h a t it w a s cr e a t e d to do. M o s t pr o g r a m s sp e n d the va s t m a j o r i t y of their ti m e by far doi n g not h i n g – quit e liter all y. Thi s ti m e sp e n t in bet w e e n us e f u l op e r a t i o n s do e s not co u n t to w a r d s the tot al a m o u n t of C P U ti m e us e d by a pr o c e s s . Th e TI M E val u e onl y go e s up w h e n the pr o c e s s is bot h rec e i v i n g att e n t i o n fro m the C P U , an d is act u a l l y doi n g so m e t h i n g us e f u l wit h it. CMD Thi s fiel d is fairl y str ai g h t f o r w a r d . It sh o w s the na m e of the pr o g r a m that w a s run to cr e a t e the pr o c e s s in qu e s t i o n . In our ps listi n g, w e ca n se e tw o pr o c e s s e s , on e for bash, an d on e for ps itself. N o w ps is fairly selfex pl a n a t o r y – w e w o u l d cert a i n l y ex p e c t it to ap p e a r , be c a u s e ps ha d to cr e a t e a pr o c e s s for itself in or d e r to run, an d sh o w us the list of pr o c e s s e s .

P a g e 73

B ut w h a t is bash ? Thi s will al w a y s ap p e a r , reg a r d l e s s of w h a t yo u ar e doi n g or w h a t Lin u x sy st e m yo u ar e on. Th e re a s o n for this is that ba s h is yo u r shell .

P a g e 74

A sh e ll is the na m e giv e n to a sp e c i a l typ e of pr o g r a m w hi c h is run w h e n e v e r yo u log in. Y o u r sh e ll is w h a t giv e s yo u a co m m a n d pr o m p t , an d all o w s yo u to ent e r co m m a n d s that Lin u x ca n the n ru n. B a s h is the def a u l t sh el l in Li n u x , an d will al w a y s be run n i n g (bec a u s e if it w a s n’ t, yo u w o u l d n ’ t ha v e a co m m a n d pr o m p t). S o, that’s the ba si c s of pr o c e s s vie w i n g . H o w e v e r , the ab o v e onl y sh o w e d us the pr o c e s s e s that w e our s e l v e s w e r e res p o n s i b l e for cr e a t i n g . W h a t if w e w a n t to se e m o r e inf o r m a t i o n ab o u t the s e pr o c e s s e s be y o n d this ba s i c det a il ? A s yo u mi g h t ex p e c t , ps ha s a gr e a t m a n y fla g s w hi c h ca n be us e d to m o d i f y or ext e n d its op e r a t i o n in a wi d e vari e t y of w a y s . W e ca n se e m o r e inf o r m a t i o n ab o u t the ru n n i n g pr o c e s s e s wit h the -u fla g, as foll o w s :
USER PID %CPU %MEM drysdalk 22868 0.0 0.2 drysdalk 23038 0.0 0.1 VSZ RSS TTY 4272 1376 pts/3 2728 680 pts/3 STAT START S 10:32 R 10:37 TIME COMMAND 0:00 -bash 0:00 ps -u

N o w her e w e ha v e so m e extr a col u m n s , wit h the follo w i n g inf or m a t i o n : US E R Thi s sh o w s the us e r n a m e of the per s o n w h o is res p o n s i b l e for the initial run n i n g of thi s pr o c e s s . In this ca s e, sin c e w e ar e onl y se e i n g our o w n pr o c e s s e s , the us e r n a m e dis p l a y e d is that of drysdalk, the cur r e n t l ylog g e d- in us e r. %CPU Thi s indi c a t e s the cur r e n t per c e n t a g e of the C P U ' s tim e that the pr o c e s s e s ar e usi n g . As yo u ca n se e fro m this listin g, the us a g e is ne g l i g i b l e , w hi c h is w h a t w e w o u l d ex p e c t – neit h e r our sh ell nor our ps co m m a n d sh o u l d be usi n g an y t h i n g m o r e tha n the bar e mi ni m u m of C P U res o u r c e s , un d e r nor m a l cir c u m s t a n c e s . %MEM Si m i l a r to % C P U , thi s sh o w s the per c e n t a g e of the sy st e m ' s m e m o r y that the s e pr o c e s s e s ar e usi n g . A g a i n , the nu m b e r s ar e tiny for our tw o pr o c e s e s s her e, an d thi s sh o u l d al w a y s be the ca s e.

P a g e 75

taki n g in to ac c o u n t bot h the ph y s i c a l m e m o r y us a g e of the pr o c e s s an d the a m o u n t of sw a p sp a c e it is usi n g as w ell. an d ca u s e the m to re m a i n in thi s st at e ind e f i n i t e l y until the pr o b l e m is res o l v e d . STA T Thi s is the cur r e n t stat u s of the pr o c e s s . Thi s fig u r e is the a m o u n t of act u a l ph y s i c a l m e m o r y cur r e n t l y bei n g us e d by the pr o c e s s e s .VS Z Thi s sh o w s the a m o u n t of virt u a l m e m o r y that the pr o c e s s e s ar e usi n g . D onl y be se e n ver y bri efl y as the y ar e onl y in this stat e for as lon g as it tak e s the m to exit. Virt u a l m e m o r y is the tot al a m o u n t of m e m o r y allo c a t e d by a pr o c e s s . S o yo u will onl y us u a l l y se e as m a n y pr o c e s s e s in the R st at e as the r e ar e pr o c e s s o r s or C P U cor e s in the sy s t e m . RS S Thi s is the resi d e n t m e m o r y us a g e of the pr o c e s s e s . N o t e that a sin g l e C P U or C P U P a g e 76 . Thi s ap p e a r s w h e n a pr o c e s s is in the mi d s t of exiti n g an d del e t i n g itself fro m m e m o r y . Th e r e ar e a vari e t y of val u e s for thi s. but the m o s t co m m o n on e s that yo u will en c o u n t e r ar e: R cor e ca n onl y ex e c u t e on e pr o g r a m at a tim e – sy st e m s cr e a t e the illusi o n of m o r e tha n on e pr o g r a m run n i n g at on c e by ra pi d l y s wit c h i n g bet w e e n all the pr o c e s s e s that re q u i r e the C P U ' s att e n t i o n . S run n i n g pr o g r a m s that will be ex e c u t e d w h e n it is their tur n. in kil o b y t e s . but so m e t i m e s pr o b l e m s ca n oc c u r on a sy s t e m that sto p pr o c e s s e s fro m exiti n g cle a n l y . S o an y diff e r e n c e bet w e e n the virt u a l siz e an d the resi d e n t siz e is the a m o u n t of s w a p sp a c e bei n g us e d by the pr o c e s s . but w hi c h ar e still vali d R u n n i n g – thi s indi c a t e s that this pr o c e s s is the on e cur r e n t l y bei n g ex p e c t e d by the C P U . U s u a l l y the s e pr o c e s s e s will Sl e e p i n g – Sl e e p i n g pr o c e s s e s ar e on e s that the C P U is not cur r e n t l y givi n g its att e n t i o n to.

but w hi c h ha s not act u a l l y res p o n d e d an d is still in m e m o r y aft e r its su p p o s e d de a t h .Z sig n a l Zo m b i e . m u c h like the real (so to sp e a k) thi n g. it's us u a l l y a sig n of so m e ver y seri o u s tro u b l e . Th e s e do not ap p e a r oft e n an d. the na m e . H e n c e . P a g e 77 . A zo m b i e is a pr o c e s s w hi c h ha s be e n se n t a kill telli n g it to quit. w h e n yo u se e on e.

0 1524 496 ? S root 2 0.1 4480 1000 ? S daemon 1233 0. like so: [drysdalk@stimpy drysdalk]$ ps -aux USER PID %CPU %MEM VSZ RSS TTY STAT root 1 0.0 0.0 0.0 1512 424 tty4 S START Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 Mar13 TIME 0:04 0:00 0:00 0:00 0:00 0:04 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:01 0:00 0:00 0:00 COMMAND init [3] [keventd] [kapmd] [ksoftirqd/0] [bdflush] [kswapd] [kscand] [kupdated] [mdrecoveryd] [kjournald] [kjournald] [kjournald] [kjournald] [kjournald] [kjournald] syslogd -m 0 klogd -x mdadm --monitor 0:00 /usr/sbin/apmd -p 10 0:06 /usr/bin/perl -w? 0:00 /usr/sbin/sshd 0:00 xinetd -stayalive 0:00 ntpd -U ntp -p /var/ 0:00 sendmail: accepting 0:00 sendmail: Queue 0:00 0:00 0:00 0:00 0:00 0:00 crond /usr/sbin/atd /sbin/mingetty /sbin/mingetty /sbin/mingetty /sbin/mingetty tty1 tty2 tty3 tty4 P a g e 78 . an d ha v e alr e a d y be e n ex p l a i n e d .0 0.0 0.0 0.0 0.0 0 0 ? SW root 403 0.0 0.4 6096 2492 ? S connections smmsp 1176 0.pid -g root 1165 0.0 0 0 ? SW root 4 0. S o.4 5980 2244 ? S runner@01:00:00 for /var/spool/clientmqueue root 1212 0. if the pr o c e s s ha s be e n ru n n i n g for m o r e tha n 24 ho u r s) that the pr o c e s s in qu e s t i o n w a s st art e d .7 12748 9072 ? S /usr/local/bin/blocksshd --start root 975 0.0 1520 424 tty1 S root 1252 0.0 0.0 0 0 ? SW root 752 0.0 0 0 ? SWN root 7 0.1 2132 800 ? S -pidfile /var/run/xinetd.0 0. B ut on an y giv e n sy st e m ther e ar e al w a y s m o r e pr o c e s s e s run n i n g tha n tho s e that w e our s e l v e s ha v e st ar t e d up sin c e log g i n g in.0 0 0 ? SW root 6 0. B e a r in mi n d that ev e r y sin gl e pr o g r a m run n i n g on a sy s t e m will re q u i r e at lea s t on e pr o c e s s .0 0 0 ? SW root 404 0.0 1520 424 tty3 S root 1254 0.0 1520 504 ? S -w 5 -W -P /etc/sysconfig/apm-scripts/apmscript root 890 0.0 0 0 ? SW root 406 0.0 0.0 0.0 0.0 1528 456 ? S root 794 0.0 0.0 0 0 ? SW root 402 0.0 1. no w w e ha v e se e n ho w to get m o r e inf o r m a t i o n on our o w n pr o c e s s e s . W e ca n se e the pr o c e s s e s bel o n g i n g to all us e r s on the sy s t e m by co m b i n i n g the -u fla g wit h the -a an d -x fla g s.0 0 0 ? SW root 405 0.0 0 0 ? SW root 9 0.0 0.0 0.0 0 0 ? SW root 5 0.1 1588 564 ? S root 1251 0.STA R T Thi s sh o w s the ti m e of da y (or dat e.0 0.0 0.0 1580 404 ? S --scan -f root 850 0.0 1516 424 tty2 S root 1253 0.0 0.0 0.2 3652 1516 ? S root 994 0.0 0.0 0 0 ? SW root 3 0.5 2584 2576 ? SL run/ntpd.0 0.0 0.1 1592 580 ? S root 756 0.0 0.pid ntp 1036 0.0 0. an d so ot h e r soft w a r e on the sy st e m will ap p e a r in a pr o c e s s listi n g too.0 0 0 ? SW root 8 0.0 0.0 0.0 0.0 0.0 0.0 0 0 ? SW root 13 0.0 0. Th e ot h e r col u m n s ar e ide n t i c a l to tho s e se e n in a si m p l e ps listin g.

1.4 6856 paulj 22821 0.3 3520 root 22819 0.0 0.1.0 0.66 sshd: paulj [priv] sshd: paulj@pts/2 -bash sshd: drysdalk 2424 ? 1376 pts/3 716 pts/3 0:00 sshd: drysdalk@pts/3 0:00 -bash 0:00 ps -aux N o w .0 0.0 0. B y defi ni ti o n .0 1524 root 22718 0. not e that in this far lon g e r ps listi n g w e still onl y se e on e pr o c e s s in the R stat e.2 4272 drysdalk 23079 0.0 0.4 6996 tomd 22721 0. Inci d e n t a l l y .66 sshd: tomd [priv] sshd: tomd@pts/1 -bash ssh 10.0 1520 root 1259 0. P a g e 79 . an d that w a s our o w n ps co m m a n d .1.0 0.0 0.1. but the s e ar e the m o s t co m m o n on e s yo u will ne e d to us e.0 0. H a v e a loo k at the m a n pa g e an d feel fre e to pla y ar o u n d – yo u ca n ne v e r do an y kin d of da m a g e to a sy s t e m by usi n g ps. an d ple n t y m o r e be s i d e s . ot h e r ' s pe o p l e ' s bash sh el l se s s i o n s an d S S H co n n e c t i o n s .0 0.4 6852 tomd 22720 0.0 0. this giv e s us the sa m e col u m n s w e sa w bef o r e wit h the -u fla g.2 4256 tomd 22763 0.0 0.4 7000 paulj 22822 0.0 0.4 6868 drysdalk 22868 0. Th e r e ar e ple n t y of ot h e r ar g u m e n t s to ps. ss h d (the ser v e r pr o c e s s res p o n s i b l e for allo w i n g S S H co n n e c t i o n s to a sy st e m).0 0.4 6856 [priv] drysdalk 22867 0.2 4272 tomd 22816 0.0 0. an d so it w a s the onl y on e cur r e n t l y bei n g acti v e l y giv e n att e n t i o n by the C P U .1 2740 [drysdalk@stimpy drysdalk]$ 424 420 2064 2284 1364 1632 2060 2260 1368 1636 2064 2268 1372 2232 tty5 tty6 ? ? pts/0 pts/0 ? ? pts/1 pts/1 ? ? pts/2 ? S S S S S S S S S S S S S S S S R Mar13 Mar13 09:14 09:15 09:15 09:15 10:00 10:01 10:01 10:01 10:25 10:25 10:25 10:32 10:32 10:32 10:53 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 /sbin/mingetty tty5 /sbin/mingetty tty6 sshd: tomd [priv] sshd: tomd@pts/0 -bash ssh 10.root 1255 0. W e ca n no w se e su c h thi n g s as se n d m a i l (a m a il ser v e r).0 0.4 6852 tomd 22773 0. sin c e it onl y dis p l a y s inf or m a t i o n rat h e r tha n ch a n g i n g an y t h i n g . but als o sh o w s us ev e r y sin gl e pr o c e s s run n i n g on the sy st e m .0 0.3 3520 root 22766 0.0 0.2 4272 root 22865 0.4 6868 tomd 22774 0. thi s ha d to be the pr o c e s s run n i n g on the sy s t e m at the tim e the out p u t of ps w a s pr o d u c e d .

w e ha v e to us e the -9 fla g to kill to for c e a pr o c e s s to ter m i n a t e : [drysdalk@localhost drysdalk 27833 3.0 4764 676 pts/0 S 12:17 drysdalk]$ kill 27833 drysdalk]$ ps aux | grep firefox 5. Sin c e ps is onl y ca p a b l e of taki n g fla g s an d do e s not ac c e p t an y ar g u m e n t s or w o r k wit h file n a m e s at all. w h e n the -9 opti o n w a s us e d . yo u r Fir e f o x W e b br o w s e r ha s st o p p e d res p o n d i n g .0 4764 676 pts/0 S 12:15 0:00 grep firefox S o m e t i m e s ho w e v e r pr o c e s s e s w o n ' t exit. eit h e r be c a u s e the y ar e un a b l e or un w i lli n g res p o n d to a re q u e s t to quit.2 Proce s s mana g e m ent N o w w e' v e se e n ho w to vie w pr o c e s s e s that ar e cur r e n t l y run n i n g . Fo r ex a m p l e – let's sa y that on yo u r o w n loc a l m a c h i n e .0 4764 676 pts/0 S 12:17 0:09 firefox-bin 0:00 grep firefox 0:09 firefox-bin 0:00 grep firefox 0:00 grep firefox A n d as w e ca n se e.0 4764 676 pts/0 S 12:15 0:09 firefox-bin 0:00 grep firefox N o w w e kn o w that it ha s a PI D of 278 3 3. M u c h of pr o c e s s m a n a g e m e n t is do n e wit h the kill co m m a n d .5 58568 28544 pts/0 R 12:16 0.0 [drysdalk@localhost [drysdalk@localhost drysdalk 27833 3.0 [drysdalk@localhost [drysdalk@localhost drysdalk 24536 0. In the s e ca s e s . Fir st. as follo w s : [drysdalk@localhost drysdalk]$ kill 27833 [drysdalk@localhost drysdalk]$ ps aux | grep firefox drysdalk 24533 0.5 58568 28544 pts/0 R 11:12 drysdalk 24530 0.0 4764 676 pts/0 S 12:17 drysdalk]$ kill -9 27833 drysdalk]$ ps aux | grep firefox 0. Al s o not e that in the ps us a g e in this ex a m p l e w e did not ha v e to put a – sy m b o l in fro n t of the fla g s.3 drysdalk 24530 0.0 0. the ne x t qu e s t i o n se e m s to be ho w to act u a l l y m a n a g e the s e pr o c e s s e s an d co n t r o l the m .0 drysdalk]$ ps aux | grep firefox 5. Fir e f o x did ind e e d exit. w e ne e d to loc a t e its PI D : [drysdalk@localhost drysdalk]$ ps aux | grep firefox drysdalk 27833 3. the r e is no ne e d to put a – in fro n t of its fla g s. P a g e 80 .0 0.3 5.6. yo u m a y fin d on m o r e rec e n t Li n u x distri b u t i o n s that yo u rec e i v e a w a r n i n g m e s s a g e if yo u try to us e ps this w a y.3 drysdalk 24533 0.5 58568 28544 pts/0 R 12:16 0. Ind e e d . N o w w e ca n us e the kill co m m a n d to att e m p t to m a k e it quit.

1 2740 680 pts/3 [drysdalk@stimpy drysdalk]$ STAT S T R START 10:32 12:30 12:30 TIME 0:00 0:00 0:00 COMMAND -bash vi ps u W e ca n se e that the vi pr o c e s s is still run n i n g .Z.C ke y co m b i n a t i o n .2 0. Or: [drysdalk@stimpy drysdalk]$ vi (Note: Ctrl-Z was pressed at this point) [1]+ Stopped vi [drysdalk@stimpy drysdalk]$ fg vi H e r e w e do not get our co m m a n d pr o m p t ba c k until vi is finis h e d . but wit h a st at u s of T. P a g e 81 .2 4144 1080 pts/3 drysdalk 23104 0. Th e r e is als o a w a y to st o p a pr o c e s s . Fo r ex a m p l e : [drysdalk@stimpy drysdalk]$ vi (Note: Ctrl-Z was pressed at this point) [1]+ Stopped vi [drysdalk@stimpy drysdalk]$ bg [1]+ vi & [drysdalk@stimpy drysdalk]$ A n d vi co n t i n u e s run n i n g . an d exit s. on e that is dir e c t l y att a c h e d to our ter m i n a l an d re a d y for inp u t on c e ag a i n. so that it is pa u s e d an d ca n be res u m e d at a lat er sta g e . W e ca n res u m e it in on e of tw o w a y s .0 0. W e ca n typ e bg to re-st ar t this pr o c e s s in to the ba c k g r o u n d an d ret u r n us to our co m m a n d pr o m p t . an d if an d w h e n it is res u m e d it will pic k up ex a c t l y w h e r e it left off. Thi s is do n e wit h Ctrl. or w e ca n typ e fg to ru n it as a for e g r o u n d pr o g r a m – that is to sa y. but w e get our co m m a n d pr o m p t ba c k .W e ha v e alr e a d y se e n in a pr e v i o u s se c t i o n that it is po s s i b l e to st o p an y pr o c e s s cur r e n t l y ru n n i n g in yo u r ter m i n a l wit h the Ctrl.Z as follo w s : [drysdalk@stimpy drysdalk]$ vi (Note: Ctrl-Z was pressed at this point) [1]+ Stopped vi [drysdalk@stimpy drysdalk]$ ps u USER PID %CPU %MEM VSZ RSS TTY drysdalk 22868 0. Thi s m e a n s that it is sto p p e d – it ha s be e n fro z e n doi n g ex a c t l y w h a t it w a s doi n g w h e n w e pr e s s e d Ctrl.0 0.2 4272 1380 pts/3 drysdalk 23103 0.

like so: [drysdalk@stimpy drysdalk]$ df Filesystem 1K-blocks /dev/hda3 5036316 /dev/hda1 101089 /dev/hda7 1004024 none 255452 /dev/hda6 1004024 /dev/hda2 6048352 /dev/hda8 24264504 [drysdalk@stimpy drysdalk]$ Used Available Use% Mounted on 199284 4581200 5% / 38421 57449 41% /boot 299480 653540 32% /home 0 255452 0% /dev/shm 16432 936588 2% /tmp 624436 5116676 11% /usr 10742920 12289000 47% /var P a g e 82 . La s t l y. Disc spa c e Di s c sp a c e ca n be ea s il y ch e c k e d wit h the df co m m a n d . A go o d ca n d i d a t e for se e i n g ho w this w o r k s is the xeyes co m m a n d . Fo r ex a m p l e : [drysdalk@stimpy drysdalk]$ xeyes & [1] 23118 [drysdalk@stimpy drysdalk]$ Thi s star t s xeyes in the ba c k g r o u n d im m e d i a t e l y . Y o u r sh ell the n ret u r n s yo u to yo u r co m m a n d pr o m p t so yo u ca n co n t i n u e w o r k i n g as xeyes run s. an d res u m i n g it wit h bg an d fg – yo u sh o u l d fairly qui c k l y se e pr e c i s e l y w h a t sto p p i n g an d star ti n g a pr o g r a m m e a n s . an d w h a t the diff e r e n c e bet w e e n run n i n g in the ba c k g r o u n d an d run n i n g in the for e g r o u n d is. Tr y ru n n i n g xeyes an d sto p p i n g it wit h Ctrl. as w ell as dis c sp a c e . pri m a r i l y C P U an d m e m o r y utili s a t i o n . 6.3 Resource monitoring Ju s t as im p o r t a n t as ke e p i n g tra c k of the pr o c e s s e s on a sy st e m is ke e p i n g tra c k of ot h e r res o u r c e s in us e. ther e is on e ot h e r w a y to ru n a pr o g r a m in the ba c k g r o u n d fro m the ver y be g i n n i n g . an d thi s is to put an a m p e r s a n d at the en d of the co m m a n d w h e n yo u ar e typi n g it.Thi s is quit e har d to de m o n s t r a t e m e a n i n g f u l l y on pa p e r . but try it yo u r s e l f. an d als o tells yo u the PI D that w a s all o c a t e d to it. Fo r t u n a t e l y Lin u x pr o v i d e s a vari e t y of fairl y str ai g h t f o r w a r d w a y s to ch e c k the s e thin g s .Z.

m o u n t e d file s y s t e m s .8G 610M 4. W e ca n get a m o r e hu m a nrea d a b l e for m a t for the s e nu m b e r s wit h the -h fla g: [drysdalk@stimpy drysdalk]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/hda3 4. thi s is do n e wit h the du co m m a n d : [drysdalk@stimpy 68 /bin/ls [drysdalk@stimpy 68K /bin/ls [drysdalk@stimpy 4.9G 195M 4. an d the a m o u n t of sp a c e bot h us e d an d fre e on ea c h of the m .8M /bin [drysdalk@stimpy drysdalk]$ du /bin/ls drysdalk]$ du -h /bin/ls drysdalk]$ du -h /bin drysdalk]$ Memory W e ca n ch e c k the cur r e n t m e m o r y us a g e on a Lin u x sy st e m wit h the free co m m a n d : [drysdalk@stimpy drysdalk]$ free total used free Mem: 510908 464720 46188 -/+ buffers/cache: 29024 481884 Swap: 1020088 0 1020088 [drysdalk@stimpy drysdalk]$ shared 0 buffers 35716 cached 399980 P a g e 83 .4G 5% / /dev/hda1 99M 38M 57M 41% /boot /dev/hda7 981M 293M 639M 32% /home none 250M 0 250M 0% /dev/shm /dev/hda6 981M 17M 915M 2% /tmp /dev/hda2 5.Thi s sh o w s us all cur r e n t l y.9G 11% /usr /dev/hda8 24G 11G 12G 47% /var [drysdalk@stimpy drysdalk]$ La s t l y if w e w a n t to kn o w ho w m u c h dis c sp a c e a parti c u l a r dir e c t o r y or file is usi n g .

H o w e v e r . as pr e v i o u s l y not e d . res p e c t i v e l y . the dis c ca c h e as us e d m e m o r y R o w 2: Th e a m o u n t of ph y s i c a l m e m o r y cur r e n t l y fre e. but the im p o r t a n t part s of it br e a k do w n as foll o w s : total sp a c e sy s t e m ha s 51 2 M B of m e m o r y . an d ar o u n d 1 G B of s w a p sp a c e co n f i g u r e d . yo u onl y ha v e to ch e c k the V S Z an d R S S val u e s for it in the out p u t of ps. the siz e of this ca c h e is dy n a m i c a l l y adj u s t e d by the op e r a t i n g sy st e m ac c o r d i n g to ho w m u c h m e m o r y pr o g r a m s the m s e l v e s ne e d to run – the s e ar e us u a l l y giv e n prio rit y. Proce s s or usa ge R o w 1: Th e a m o u n t of ph y s i c a l m e m o r y us e d by Thi s col u m n list s the tot al a m o u n t of m e m o r y an d sw a p inst a l l e d on the sy st e m .Th e a m o u n t s her e ar e all giv e n in kilo b y t e s . so as to sp e e d up ac c e s s to the m . not co u n t i n g the dis c ca c h e R o w 3: Th e a m o u n t of s w a p sp a c e cur r e n t l y fre e A re a s o n a b l e qu e s t i o n her e w o u l d be – w h a t is the dis c ca c h e ? Lin u x is ca p a b l e of allo c a t i n g a por ti o n of the sy s t e m ' s m e m o r y to hol di n g a co p y of fre q u e n t l y. an d onl y R o w 3: Th e a m o u n t of s w a p sp a c e in us e free reg a r d i n g R o w 1: Th e a m o u n t of ph y s i c a l m e m o r y cur r e n t l y fre e. Th e out p u t of free ca n ap p e a r quit e co m p l e x at first. used pr o g r a m s .ac c e s s e d file s in m e m o r y . S o un d e r nor m a l circ u m s t a n c e s it is the fig u r e s in the mi d d l e ro w that indi c a t e the ab s o l u t e a m o u n t of m e m o r y that is av a il a b l e to an y pr o g r a m s that mi g h t req u i r e it. S o our ex a m p l e for dis c ca c h i n g R o w 2: Th e a m o u n t of ph y s i c a l m e m o r y us e d by pr o g r a m s P a g e 84 . N o t e that to se e ho w m u c h m e m o r y an y giv e n pr o g r a m is usi n g .

B ut w h a t if w e w a n t an ov e r a l l pict u r e – to get an ide a of ho w bu s y the sy st e m ' s C P U ge n e r a l l y is at the m o m e n t . or ha s be e n ov e r a l l rec e n t l y ? Th e r e ar e. as yo u w o u l d ex p e c t . P a g e 85 . a fe w w a y s to get inf o r m a t i o n of this sort.W e ' v e alr e a d y se e n that w e ca n ch e c k the a m o u n t of C P U tim e an d the per c e n t a g e of the C P U ' s res o u r c e s that an indi vi d u a l pr o g r a m is co n s u m i n g by ch e c k i n g its listin g in ps (the % C P U an d TI M E col u m n s . res p e c t i v e l y).

1 user. load average: 0.75. 1 user. 3:57.00s w [root@vhost5-1 root]# A s yo u ca n se e.iomart.80 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 stimpy. load average: 0. 0.80. but the ea si e s t w a y is wit h the w co m m a n d : [root@vhost5-1 root]# w 13:18:21 up 149 days.80 Th e val u e s her e ha v e the foll o w i n g m e a n i n g s : 13:18:21 Th e cur r e n t loc a l sy st e m ti m e. Th e s e thr e e nu m b e r s ar e the sy s t e m loa d av e r a g e ov e r the pa s t 1 mi n u t e . 5 mi n u t e s an d 1 5 mi n u t e s res p e c t i v e l y .Th e ea si e s t w a y to get an ide a of ho w bu s y a sy st e m is at an y giv e n m o m e n t is to ch e c k its load average .00s 0.80 H e r e w e ha v e the act u a l loa d av e r a g e fig u r e s the m s e l v e s . the loa d av e r a g e of a sy s t e m is a nu m b e r that ex p r e s s e s ho w m a n y pr o c e s s e s ar e cur r e n t l y vyi n g for the att e n t i o n of the C P U . 3:57 Th e upti m e of the sy st e m – the a m o u n t of tim e sin c e it w a s last reb o o t e d . 0. 0.75. 1 user Th e nu m b e r of us e r s cur r e n t l y log g e d in.02s 0. 0. Wit h o u t getti n g ov e r l y tec h n i c a l . 3 ho u r s an d 57 mi n u t e s . 3:57. an d w h e r e the y log g e d in fro m . Th e r e ar e vari o u s w a y s to ch e c k the cur r e n t loa d av e r a g e . 1 4 9 da y s. the w co m m a n d do e s so m e t h i n g els e as w ell – it giv e s us a sh o r t su m m a r y of ev e r y o n e cur r e n t l y log g e d in to the sy s t e m . 0. P a g e 86 .80.co 1:18pm 0. 0. load average: 0. up 149 days.75.80. S o in our ca s e. B ut w e ar e int er e s t e d her e in that first lin e of out p u t that w a s ret u r n e d : 13:18:21 up 149 days.

0 0:00 keventd 0 0 0 SW 0. a loa d av e r a g e of gr e a t e r tha n 1.0 0. su c h as onl y ov e r the on e. ar e nor m a l l y not so w o r r y i n g .0 0. sin c e the loa d av e r a g e indi c a t e s ho w m a n y pr o c e s s e s ar e cur r e n t l y acti v e l y req u i r i n g C P U att e n t i o n .2% user.cgi 2400 2276 1460 S 1.0% system. Th e sy s t e m w o u l d pr o b a b l y still be us a b l e .9 14.1 2:37 httpd 492 464 440 S 0. but its perf o r m a n c e w o u l d be noti c e a b l y de g r a d e d .0 0:18 kswapd 0 0 0 SW 0.mi n u t e val u e s . Lo a d av e r a g e spi k e s ov e r a sh o r t e r peri o d . ho w do yo u go ab o u t det e r m i n i n g the ca u s e of a hig h sy s t e m loa d ? W e l l.0 0.5% idle Mem: 1030840K av.0 123:19 kscand/HighMem 0 0 0 SW 0.0 0:00 bdflush 0 0 0 SW 0. Fi n a l l y. 2048008K free 603900K cached PID 19059 18236 10755 1 2 3 4 5 6 7 8 9 10 11 15 USER apache smmsp root root root root root root root root root root root root root PRI NI 17 0 10 0 9 0 8 0 9 0 9 0 19 19 9 0 9 0 9 0 9 0 9 0 9 0 -1 -20 9 0 SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 5204 5204 1908 S 37.0 0.0 0:04 kupdated 0 0 0 SW< 0. 0 stopped CPU states: 0. the n it is too bu s y an d will not be per f o r m i n g at its be s t.0 0. 0. 0. 12504K free. load average: 0.or five.0 0:01 kscand/DMA 0 0 0 SW 0.18.tas k i n g is cr e a t e d by the C P U ra pi d l y sw it c h i n g fro m on e pr o g r a m to an o t h e r . S o for a sin g l e.9 0.0 0:03 ksoftirqd_CPU0 0 0 0 SW 0.0 0.17 60 processes: 58 sleeping. 0. yo u will the n se e a scr e e n su c h as this: 1:47pm up 72 days.0 0:05 init 0 0 0 SW 0. 0K shrd. 111628K buff Swap: 2096472K av.00 ov e r fifte e n mi n u t e s w o u l d indi c a t e that it w a s too bu s y – in ot h e r w o r d s .0 0. 48464K used. 0. If yo u typ e top at the co m m a n d pr o m p t .0 0.0 6:29 kjournald P a g e 87 .22.0 0:00 mdrecoveryd 0 0 0 SW 0.2 0. 6:13.re a d a b l e sn a p s h o t ov e r v i e w of sy s t e m pr o c e s s o r us a g e .S o w h a t co n s t i t u t e s a hig h sy s t e m loa d ? Stri ctl y sp e a k i n g .0 548:59 kscand/Normal 0 0 0 SW 0.0 0:00 kapmd 0 0 0 SWN 0.pr o c e s s o r sin g l e.0 0. 1 user. the r e w o u l d be too m a n y thin g s ha p p e n i n g on the sy s t e m for the m all to be res p o n d i n g in a tim e l y fas h i o n .0 0. R e m e m b e r that a C P U ca n onl y do on e thi n g at a ti m e – the illusi o n of m u l ti.2 0:12 sendmail 185M 142M 3616 S 0. S u d d e n sur g e s in pr o c e s s o r acti vit y ar e a fairl y co m m o n oc c u r r e n c e at pe a k tim e s .cor e sy st e m .5 0:00 store_stats. 2 running.0 0.0 0. 1018336K used. but if a sy s t e m co n s i s t e n t l y ha s a loa d av e r a g e hig h e r tha n the nu m b e r of C P U s or C P U cor e s it ha s inst a ll e d . yo u ca n ch e c k the out p u t of a ps -aux an d se e w hi c h pr o c e s s e s ar e co n s i s t e n t l y usi n g hig h per c e n t a g e s of the C P U ' s res o u r c e s or w hi c h ha v e tak e n up the hig h e s t val u e s of its tim e. 0. 0 zombie.0% nice. the n if the loa d av e r a g e ex c e e d s the nu m b e r of C P U cor e s on a sy s t e m the n it is too hig h. but the r e is a co m m a n d that will giv e yo u a hu m a n.

0 0.70 140 471 475 492 511 568 569 586 654 701 716 730 753 763 770 771 772 773 774 775 7854 7863 18993 19013 19060 root root root root rpc rpcuser root root root root root root ntp root root root root root root root root root smmsp root root root 9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 9 9 9 9 9 9 9 9 8 9 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 556 424 564 688 0 0 744 528 892 812 2068 276 452 44 44 44 44 44 44 1428 1192 2488 1524 1092 0 0 520 376 536 608 0 0 708 472 768 728 2068 244 424 4 4 4 4 4 4 956 816 2344 1524 1092 0 0 476 372 492 604 0 0 620 452 668 652 1868 204 404 0 0 0 0 0 0 800 724 1680 1148 872 SW SW S S S S SW SW S S S S S S S S S S S S S S S S S R 0. a P e rl scri p t ru n n i n g in a cu s t o m e r ' s W e b sp a c e .0 0. w hi c h is part of the W e b ser v e r soft w a r e an d is m o s t likel y in the pr o c e s s of ser v i n g up a W e b pa g e .0 0.0 0. so it is a ha n d y on e.0 0.0 0.0 0.0 0.0 0.statd rpciod lockd ypbind automount sshd xinetd ntpd crond rhnsd mingetty mingetty mingetty mingetty mingetty mingetty sendmail sendmail sendmail bash top S o w e ca n se e that on thi s sy s t e m (one of the sh a r e d W e b ho s t i n g ser v e r s) the he a v i e s t us e r of C P U res o u r c e s is store_stats.0 0. N e x t hig h e s t is an inst a n c e of sendmail that is pr o b a b l y bu s y se n d i n g out an e-m a il. fro m he a v i e s t to lig ht e s t us a g e .0 0.0 0.0 0.0 0. to m a k e fin di n g out w h a t mi g h t be usi n g m o s t of yo u r sy s t e m ' s C P U ti m e ev e n ea si e r .1 0:00 0:00 2:21 0:00 0:01 0:00 4:24 0:00 0:05 0:00 8:21 1:20 0:07 0:28 1:17 0:00 0:00 0:00 0:00 0:00 0:00 0:05 0:00 0:00 0:00 0:00 khubd kjournald syslogd klogd portmap rpc.0 0.1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.2 0.0 0.0 0.0 0. N o t e that by def a u l t top sort s this list by pr o c e s s o r us a g e .0 0.0 0.0 0.0 0.0 0.0 0. P a g e 88 .0 0.0 0.0 0.0 0.2 0. an d the n w e ha v e an httpd pr o c e s s .0 0.sto p.0 0.0 0.0 0.0 0.0 0.0 0. It als o dis p l a y s st ati s t i c s ab o u t m e m o r y us a g e as w ell.0 0.sh o p for sy st e m res o u r c e us a g e inf o r m a t i o n (with the ex c e p t i o n of dis c sp a c e).cgi.0 0.

Apache at a glance Th e foll o w i n g inf o r m a t i o n ap p l i e s to the def a u l t out.bo x inst a ll of A p a c h e on a R e d H at styl e sy s t e m (i. a cle a n inst al l of A p a c h e will be h a v e ex a c t l y as outli n e d ab o v e .e. w e will loo k at co m m o n pie c e s of ser v e r soft w a r e .4 Common server software In this se ct i o n . an d ex a m i n e the tas k s yo u w o u l d m o s t typi c a l l y ha v e to car r y out w h e n w o r k i n g wit h the m . 6.of-the.4. H o w e v e r .6. as will on e that ha s not be e n cu st o m i s e d in an y sig n ifi c a n t w a y. R e d H at E nt e r p r i s e).1 Web server – Apache A p a c h e is m o r e or les s the de fact o st a n d a r d W e b ser v e r on m o s t Lin u x sy s t e m s . Fe d o r a . A p a c h e nor m a l l y ap p e a r s as /usr/sbi n/htt p d A p a c h e list e n s on P or t 80 on all co n f i g u r e d IP ad d r e s s e s for H T T P req u e s t s N o t e that an y on e of the s e val u e s or as s u m p t i o n s ca n be ch a n g e d by editi n g A p a c h e ' s co n f i g u r a t i o n ap p r o p r i a t e l y . • • • • • • • • • Th e A p a c h e bi n a r y ex e c u t a b l e is inst a ll e d as /usr/sbi n/htt p d A p a c h e ' s m a i n co n f i g u r a t i o n file is /etc/htt p d/c o n f/htt p d . C e n t O S . P a g e 89 . c o n f Th e us e r that A p a c h e is co n f i g u r e d to ru n as is 'ap a c h e ' Th e gr o u p the A p a c h e us e r bel o n g s to is 'ap a c h e ' Th e W e b traffi c log file for A p a c h e is /var/log/htt p d/a c c e s s _ l o g Th e A p a c h e err o r log is /var/log/htt p d/er r o r _ l o g Th e def a u l t W e b sit e' s co n t e n t is loc a t e d be n e a t h /var/w w w/ht m l In a ps listi n g. so do not as s u m e that the ab o v e will be tru e on ev e r y sin g l e sy st e m that yo u co m e acr o s s . W h i t e B o x. Th e r e ar e ot h e r s av a il a b l e – an d w e do in fact m a k e us e of so m e of the m our s e l v e s in cert a i n pla c e s – but A p a c h e is the on e yo u ar e m o s t likel y by far to en c o u n t e r tha n an y ot h e r.

Task 1: Chec kin g to see if Apache is running To ch e c k to se e if A p a c h e is ru n n i n g .0 0.0 0.0 0.1.4 28676 18436 ? S 12:33 apache 6152 0.4 29084 18708 ? S 11:39 apache 2210 0.4 27344 17352 ? S 11:46 apache 2793 0.4 29480 19328 ? S 11:22 apache 1689 0.0 0.0 0.4 27556 17424 ? S 12:33 apache 3592 0. the ea s i e s t thin g to do is to se e if it ap p e a r s in a ps listi n g: [drysdalk@vhost6-1 vhost6-1]$ ps aux | grep httpd root 19037 0.4 28772 18576 ? S 10:10 apache 312 0.0 3696 660 pts/0 S 14:31 [drysdalk@vhost6-1 vhost6-1]$ 0:48 0:07 0:08 0:06 0:07 0:07 0:05 0:05 0:07 0:04 0:07 0:06 0:05 0:07 0:07 0:04 0:04 0:05 0:03 0:05 0:00 0:00 0:00 0:00 /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd grep httpd A s yo u ca n se e.0 0.2 20476 9400 ? S 14:28 apache 6649 0.4 27940 17608 ? S 12:33 apache 3589 0.0 0.0 0. W h i c h is just as w ell.4 29448 19100 ? S 11:39 apache 2208 0.3 25776 15048 ? S 14:29 drysdalk 6754 0.0 0.4 30016 19872 ? S 12:33 apache 3590 0.0 0.4 28068 17932 ? S 11:45 apache 2406 0.0 0.4 27052 16940 ? S 11:42 apache 2284 0.0 0.4 26964 16748 ? S 11:36 apache 2207 0.4 28860 18816 ? S 11:42 apache 2385 0. P a g e 90 . thi s par ti c u l a r ser v e r (vho st 6.4 27576 17336 ? S 11:22 apache 2108 0.0 0.0 0.0 0.4 27156 16696 ? S 14:11 apache 6635 0.0 0.0 0.4 27200 16820 ? S 11:39 apache 2267 0.4 29512 19476 ? S 10:32 apache 1546 0.4 28956 18816 ? S 11:17 apache 1688 0.3 0.4 26984 16812 ? S 12:33 apache 3593 0.0 0.0 0.0 0.2 20340 9108 ? S Jan17 apache 32188 0.4 28824 18724 ? S 12:02 apache 3588 0.0 0. on e of the sh a r e d W e b ho s t i n g ser v e r s . an d the on e w e will us e thr o u g h o u t this se c ti o n) is ind e e d run n i n g A p a c h e .0 0.0 0.

0 0.0 7604 1768 apache 31938 0.Task 2: Starting Apache if it is not running If yo u ar e rec e i v i n g aler t s fro m a W e b ser v e r indi c a t i n g that A p a c h e is not ru n n i n g . as yo u mi g h t ex p e c t .0 7604 1768 apache 31937 0. yo u ca n st ar t A p a c h e fro m col d wit h the follo w i n g co m m a n d : service httpd start Fo r ex a m p l e : [root@ren ~]# ps aux | grep http root 31917 0.0 0.0 7604 1768 root 31941 0.0 0. Task 3: Stopping Apache in the proper fashion Y o u ha v e be e n as k e d to st o p A p a c h e on on e of the W e b ser v e r s .0 0.0 0.0 5216 568 pts/2 [root@ren ~]# [ S+ 14:25 OK ] 0:00 grep http Task 4: What to do if there are problem s re-starting Apache P a g e 91 .0 0. so yo u w o u l d be be s t to eit h e r do thi s wit h sudo or to per f o r m a sudo su – pri or to att e m p t i n g this.0 7604 1768 apache 31936 0.0 7604 1768 apache 31935 0.0 4536 568 [root@ren ~]# service httpd start Starting httpd: [root@ren ~]# ps aux | grep http root 31929 0.1 7604 2400 apache 31931 0.0 0.0 3976 568 [root@ren ~]# pts/2 S+ 14:23 0:00 grep http [ ? ? ? ? ? ? ? ? ? pts/2 Ss S S S S S S S S S+ 14:23 14:23 14:23 14:23 14:23 14:23 14:23 14:23 14:23 14:23 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 OK ] /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd grep http N o t e that yo u ha v e to be ro ot to st o p an d/or star t A p a c h e .0 7604 1768 apache 31939 0. Thi s is do n e .0 0. wit h: service httpd stop Fo r ex a m p l e : [root@ren ~]# service httpd stop Stopping httpd: [root@ren ~]# ps aux | grep http root 32089 0.0 7604 1768 apache 31933 0.0 0.0 0.0 0.0 7604 1768 apache 31934 0.0 0. an d yo u ha v e verifi e d yo u r s e l f usi n g the ab o v e m e t h o d that thi s is ind e e d the ca s e.

0 5720 568 [root@ren ~]# service httpd start Starting httpd: [root@ren ~]# ps aux | grep http apache 32109 0.0 9248 1772 apache 32421 0.0 0.0 0.0 9248 1772 apache 32419 0. ev e n if at first gl a n c e it do e s n ' t ap p e a r to be run n i n g .0 0. A n o t h e r ca u s e ca n be if P er l scri p t s or si m il a r thi n g s ha v e be e n left-ov e r fro m the pr e v i o u s inst a n c e of A p a c h e that fail e d.0 0. an d A p a c h e w o n 't st art.0 9248 1772 apache 32416 0.0 4424 568 [root@ren ~]# ? pts/2 S S+ 14:25 14:31 0:00 /usr/sbin/httpd 0:00 grep http [ ? pts/2 pts/2 S S+ S+ 14:25 14:31 14:31 FAILED ] 0:00 /usr/sbin/httpd 0:00 grep http 0:00 grep http [ OK ] ? ? ? ? ? ? ? ? ? pts/2 Ss S S S S S S S S S+ 14:31 14:31 14:31 14:31 14:31 14:31 14:31 14:31 14:31 14:31 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd /usr/sbin/httpd grep http Thi s is by far the m o s t co m m o n re a s o n w h y A p a c h e w o n ' t star t. tryi n g to star t A p a c h e m a y not w o r k. For ex a m p l e : [root@ren ~]# ps aux | grep http apache 32109 0.0 9248 1772 apache 32418 0.0 0. Thi s ca n ha p p e n if A p a c h e ha s die d off for so m e rea s o n .0 0. ev e n tho u g h yo u ar e rec e i v i n g aler t s indi c a t i n g that the W e b ser v e r ha s faile d.S o m e t i m e s .0 0. but on e of its pr o c e s s e s is still aliv e w h e n it sh o u l d not be. sin c e the ol d pr o c e s s will be blo c k i n g a ne w inst a n c e of A p a c h e fro m st ar ti n g .0 0.0 0. In ca s e s su c h as this. so if yo u se e an y P e rl scri p t s o w n e d by the us e r 'ap a c h e ' on a ps listi n g. yo u first ha v e to kill off the A p a c h e pr o c e s s that ha s be e n left be h i n d .0 0. Th e s e too will blo c k a ne w inst a n c e fro m st ar ti n g .0 9248 1772 apache 32417 0.0 5552 568 [root@ren ~]# kill -9 32109 [root@ren ~]# ps aux | grep http root 32399 0. In this sit u a t i o n .0 0.0 0. yo u'll log on to a ser v e r an d se e that the r e se e m s still to be an A p a c h e pr o c e s s ru n n i n g .1 8976 2284 root 32397 0.0 9248 1772 apache 32415 0.0 9248 1772 apache 32420 0. the n killin g the s e off will pr o b a b l y fix the pr o b l e m .0 0. P a g e 92 .0 0.1 9248 2404 apache 32413 0.0 9248 1772 root 32423 0.1 8976 2284 root 32385 0.0 0.0 4336 568 [root@ren ~]# service httpd start Starting httpd: [root@ren ~]# ps aux | grep http root 32411 0.

/var/log/htt p d/er r o r _ l o g .172] Premature end of script headers: amazon_products_feed. w e se e: [root@vhost5-1 root]# tail -2 /var/log/httpd/error_log [Wed Mar 21 15:04:05 2007] [error] [client 64.172. c g i is failin g be c a u s e of a 'Per m i s s i o n de n i e d ' err o r w h e n A p a c h e trie s to ex e c u t e it. It's al m o s t cert a i n that thi s cu s t o m e r si m p l y for g o t to set ex e c u t e per m i s s i o n on the file w h e n the y upl o a d e d it to their cgi. if w e tak e a loo k at the tail-en d of this file on on e of the bu si e r sh a r e d W e b ser v e r s . an d that doi n g so w o u l d fix the pr o b l e m .208.209. it will writ e that out p u t to its err o r log.227] (13)Permission denied: exec of '/vhost/vhost5/d/e/s/designer-info.Task 5: Diagno sin g problem s with CGI scripts A n o t h e r co m m o n tas k is ha vi n g to tra c k do w n w h y a par ti c u l a r scri p t on a W e b sit e is givi n g an 'Int e r n a l S er v e r Err o r '.bin/ dir e c t o r y . Thi s is a cat c h.cgi [Wed Mar 21 15:04:06 2007] [error] [client 65. as not e d pr e v i o u s l y . If A p a c h e rec e i v e s an y m e a n i n g f u l out p u t fro m the scri p t ot h e r tha n w h a t it w a s ex p e c t i n g .all W e b ser v e r ter m for a fail ur e of the call e d scri p t to act u a l l y ret u r n su c c e s s f u l l y .cgi' failed S o her e w e ca n se e that the scri p t a m a z o n _ p r o d u c t s _ f e e d . S o. P a g e 93 .com/cgibin/apf4/amazon_products_feed. Th e def a u l t err o r log file in a R e d H a t inst a ll of A p a c h e is.55.

vsftpd at a glance A s bef o r e .styl e sy st e m : • • • Th e vsft p d bin a r y is inst a ll e d as /usr/sbi n/vsft p d Th e co n f i g u r a t i o n file for vsft p d is /etc/vsft p d/v s f t p d .0 0. alt h o u g h this is rar e r no w tha n it us e d to be. the foll o w i n g ap p l i e s onl y to the out.6. f t p u s e r s Task 1: Starting vsftpd A s yo u mi g h t w ell ex p e c t by no w . c o n f Th e list of us e r s w h o ar e not allo w e d to log in via F T P is /etc/vsft p d .to-tim e en c o u n t e r an o t h e r FT P ser v e r call e d Pr o F T P D .of-the.4.0 4768 676 pts/0 [root@vhost5-1 root]# S 17:01 0:00 grep vsftpd [ S S S 2006 10:22 17:01 OK ] 3:01 /usr/sbin/vsftpd 0:00 /usr/sbin/vsftpd 0:00 grep vsftpd P a g e 94 .0 1924 968 ? /etc/vsftpd/vsftpd.conf root 16592 0.2 FTP server – vsftpd Th e F T P ser v e r that is us e d by def a u l t on m o s t of our sh a r e d W e b ho s t i n g platf o r m is vsft p d .conf ftp 15236 0. tho u g h yo u m a y fro m tim e. Thi s is the st a n d a r d R e d H a t F T P ser v e r the s e da y s. this is si m p l y do n e wit h service vsftpd start Fo r ex a m p l e : [root@vhost5-1 root]# ps -aux | grep vsftpd root 16587 0.0 0.0 0.0 1788 484 ? /etc/vsftpd/vsftpd.0 0.0 4768 676 pts/0 [root@vhost5-1 root]# service vsftpd start Starting vsftpd: [root@vhost5-1 root]# ps -aux | grep vsftpd root 8124 0.bo x def a u l t inst a l l a t i o n of vsft p d on a R e d H at.

an d w h e n yo u log in to ch e c k yo u se e a gr e a t m a n y vsft p d pr o c e s s e s all o w n e d by the sa m e us e r.3 Databa s e server – My S Q L P a g e 95 .conf ftp 15236 0. Thi s will cle a r all cur r e n t l y.0 4768 676 pts/0 [root@vhost5-1 root]# S S S 2006 10:22 17:01 3:01 /usr/sbin/vsftpd 0:00 /usr/sbin/vsftpd 0:00 grep vsftpd [ S 17:01 OK ] 0:00 grep vsftpd Task 3: Diagno sin g problem s with vsftpd Th e m o s t co m m o n pr o b l e m wit h vsft p d oc c u r s w h e n the ser v e r ha s rea c h e d its m a x i m u m nu m b e r of allo w e d si m u l t a n e o u s co n n e c t i o n s . Thi s ca n ha p p e n eit h e r as a res u l t of the ser v e r ge n u i n e l y bei n g bu s y . 6. an d star t it ba c k up ag a i n. In this ca s e.conf root 16592 0. yo u si m p l y st o p vsft p d . the pr o b l e m will qui c k l y re-ap p e a r an d req u i r e es c a l a t i o n to our net w o r k tea m in or d e r to bl o c k the IP ad d r e s s of the off e n d i n g us e r an d to arr a n g e to ha v e the m co n t a c t e d . or m o r e oft e n w h e n on e par ti c u l a r us e r de c i d e s to est a b l i s h do z e n s of co n n e c t i o n s un d e r their o w n logi n to sp e e d up their F T P tra n s f e r s .0 1788 484 ? /etc/vsftpd/vsftpd.0 0. ho w e v e r . If it is a ca s e of ge n u i n e ab u s e rat h e r tha n ac ci d e n t a l fooli s h n e s s .est a b l i s h e d co n n e c t i o n s an d allo w ne w us e r s in on c e ag a i n.Task 2: Stopping vsftpd Thi s is do n e si m p l y wit h: service vsftpd stop Fo r ex a m p l e : [root@vhost5-1 root]# ps -aux | grep vsftpd root 8124 0.0 1924 968 ? /etc/vsftpd/vsftpd. Th e sy m p t o m s of thi s w o u l d be the m o n i t o r i n g sy s t e m re p o r t i n g that F T P w a s eit h e r ti mi n g out or ref u s i n g co n n e c t i o n s on on e of the W e b ser v e r s .0 0.4.0 0.0 4768 676 pts/0 [root@vhost5-1 root]# service vsftpd stop Stopping vsftpd: [root@vhost5-1 root]# ps -aux | grep vsftpd root 16587 0. w ait a fe w se c o n d s an d ch e c k to se e that it ha s sto p p e d su c c e s s f u l l y.0 0.

the qu e r y log for M y S Q L rec o r d s ea c h indi vi d u a l S Q L dat a b a s e qu e r y run. c o m .In the Li n u x w o r l d the tw o m a i n dat a b a s e ser v e r s yo u ar e likel y to en c o u n t e r ar e M y S Q L . O n our sh a r e d ho s t i n g platf o r m w e us e M y S Q L . S o a dat a b a s e call e d 'm y d b ' w o u l d be stor e d in the dir e c t o r y : /var/lib/m y s q l/ m y d b Th e co n f i g u r a t i o n file for M y S Q L is /etc/m y. Th e re a s o n that it is not en a b l e d by de a f u l t is that su c h a log qui c k l y be c o m e s ver y lar g e. so as not to co n s u m e un n e c e s s a r y dis c sp a c e or slo w the M y S Q L ser v e r do w n . c o m .i o m a r t . m u c h in the m a n n e r that A p a c h e ' s ac c e s s _ l o g rec o r d s ev e r y sin g l e H T T P req u e s t m a d e . the err o r log w o u l d be: /var/lib/m y s q l/ m y s q l . e r r S o for a dat a b a s e ser v e r m y s q l. but yo u w o u l d nor m a l l y onl y w a n t to do so if yo u ha d to car r y out de b u g g i n g that ab s o l u t e l y req u i r e d yo u ha v i n g qu e r y log inf o r m a t i o n . an d so this is the on e that w e will foc u s on her e in this gui d e . c n f Th e def a u l t err o r log file will ha v e a na m e of the for m : /var/lib/m y s q l/<h o s t n a m e > .bo x setti n g s . alt h o u g h the s e will be the def a u l t out. P a g e 96 . e r r B y def a u l t ther e is no qu e r y log – onl y err o r s an d st art u p/s h u t d o w n m e s s a g e s ar e log g e d A s wit h A p a c h e an y an d all of the ab o v e ca n be ch a n g e d . an d ca n slo w do w n the M y S Q L ser v e r co n s i d e r a b l y . an d P o s t g r e S Q L (quite oft e n just ref e r r e d to as P o s t g r e s). My S Q L at a glance Th e def a u l t co n f i g u r a t i o n for M y S Q L on a R e d H at sy st e m is as follo w s : • • • • • Th e M y S Q L bi n a r y is inst a ll e d as /usr/sbi n/m y s q l d D a t a b a s e s ar e stor e d in /var/lib/m y s q l. W h e n en a b l e d . ea c h in its o w n dir e c t o r y . Y o u ca n en a b l e qu e r y log g i n g . Y o u ' d als o us u a l l y w a n t to tur n it off ag a i n as so o n as yo u no lon g e r ne e d e d it.of-the.i o m a r t .

sock root 1636 0.0 0.0 4768 676 pts/0 S 17:01 0:00 grep mysql [root@claudius root]# P a g e 97 .0 4248 420 ? S Mar16 0:00 /bin/sh /usr/bin/mysqld_safe -datadir=/var/lib/mysql --pid-file=/var/lib/mysql/claudius.pid root 27767 0.iomart. Fo r ex a m p l e : [root@claudius root]# ps -aux | grep mysql root 27767 0.g.0 0.0 3692 680 pts/0 S 11:49 0:00 grep mysql [root@claudius root]# service mysql start Stopping mysql: [ OK ] [root@claudius root]# ps -aux | grep mysql mysql 1671 23.0 0.pid --skip-locking --socket=/var/lib/mysql/mysql.iomart. htt p d.pid root 27768 0.sock root 1636 0.com.com.0 0.com.0 4768 676 pts/0 S 17:01 0:00 grep mysql [root@claudius root]# Task 2: Stopping My S Q L A s for ot h e r s : service mysql stop Fo r ex a m p l e : [root@claudius root]# ps -aux | grep mysql mysql 1671 23.0 4248 420 ? S Mar16 0:00 /bin/sh /usr/bin/mysqld_safe -datadir=/var/lib/mysql --pid-file=/var/lib/mysql/claudius.0 0.0 3692 680 pts/0 S 11:49 0:00 grep mysql [root@claudius root]# service mysql stop Stopping mysql: [ OK ] [root@claudius root]# ps -aux | grep mysql root 27768 0.pid --skip-locking --socket=/var/lib/mysql/mysql.1 185864 69296 ? S Mar16 3893:43 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/claudius.iomart.com.Task 1: Starting My S Q L A s yo u' v e pr o b a b l y co m e to ex p e c t : service mysql start N o t e that it's ' service mysql' an d not ' service mysqld' – the ot h e r ser v i c e co m m a n d s w e' v e se e n so far us e the sa m e ser vi c e na m e as the na m e of the bi n a r y its elf (e. vsft p d). but M y S Q L do e s not.0 7.iomart.0 7.1 185864 69296 ? S Mar16 3893:43 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/claudius.0 0.

U s u a l l y./s1homes/property_images' 070326 17:12:42 [ERROR] Got error 134 when reading table '.err -rw-rw---1 mysql root 625534 Mar 26 17:19 s1dbmysql2.err 070326 16:08:05 [ERROR] /usr/sbin/mysqld: Can't open file: 'sms_status.MYI' (errno: 145) 070326 16:08:05 [Warning] Checking table: './s1homes/sms_status' 070326 17:11:52 [ERROR] Got error 134 when reading table '.iomart.MYI' (errno: 145) 070326 17:14:20 [Warning] Checking table: './s1homes/sms_messages_sent' 070326 17:19:52 [Note] Found 1206874 of 1206876 rows when repairing '.err H e r e .MYI' (errno: 145) 070326 17:14:20 [Warning] Checking table: '.iomart. the err o r log by def a u l t is loc a t e d in a file wit h a na m e of the for m a t : /var/lib/mysql/<hostname>. but so m e t i m e s w e ne e d to m a n u a l l y ru n furt h e r ch e c k s on an y tabl e s that ar e ha vi n g tro u b l e . P a g e 98 .iomart. ar e the last fe w lin e s fro m a M y S Q L ser v e r call e d s1d b m y s q l 2: [root@s1dbmysql2 root]# cd /var/lib/mysql [root@s1dbmysql2 mysql]# ls -l s1dbmysql2./s1homes/messageIDgenerator' 070326 17:14:20 [ERROR] /usr/sbin/mysqld: Can't open file: 'sms_messages_sent.Task 3: Chec kin g the error log If ev e r y M y S Q L is ex p e r i e n c i n g pr o b l e m s of so m e kin d. it will log this inf o r m a t i o n to its err o r log./s1homes/property_images' 070326 17:12:14 [ERROR] Got error 134 when reading table '. M y S Q L ca n tak e car e of the s e iss u e s itself the s e da y s.com.com. for ex a m p l e . be it wit h run n i n g out of m e m o r y or dis c sp a c e or if a par ti c u l a r dat a b a s e on the sy s t e m ha s be c o m e cor r u p t .err [root@s1dbmysql2 mysql]# tail -10 s1dbmysql2./s1homes/property_images' 070326 17:14:20 [ERROR] /usr/sbin/mysqld: Can't open file: 'messageIDgenerator./s1homes/property_images' [root@s1dbmysql2 mysql]# Thi s err o r log sh o w s us a vari e t y of pr o b l e m s wit h the tabl e s in the 's1 h o m e s ' dat a b a s e .com. To rec a p .

MYD -rw-rw---1 mysql mysql 15803392 Mar 28 11:40 property_images. an d so w e ne e d to ch e c k the tabl e pr o p e r t y _ i m a g e s in the dir e c t o r y /var/lib/m y s q l/s 1 h o m e s . e an d -T fla g s. let's sa y w e w a n t e d to furt h e r inv e s t i g a t e this par ti c u l a r tabl e that w a s m e n t i o n e d in the M y S Q L err o r log in the pr e v i o u s se ct i o n : 070326 17:11:52 [ERROR] Got error 134 when reading table './s1homes/property_images' R e m e m b e r that all dat a b a s e s ar e stor e d in a dir e c t o r y call e d /var/lib/m y s q l/<d a t a b a s e na m e >. At this poi n t yo u w o u l d es c a l a t e thi s m a t t e r to an o t h e r m e m b e r of the sy s t e m s ad m i n i s t r a t i o n tea m to car r y out the re p a i r of the tabl e.check data record references index: 1 myisamchk: error: Found 1206094 keys of 1206073 . as ap p r o p r i a t e . Fo r ex a m p l e : [root@s1dbmysql2 root]# cd /var/lib/mysql/s1homes [root@s1dbmysql2 s1homes]# ls -l property_images* -rw-rw---1 mysql mysql 8698 May 2 2006 property_images. ther e is a co m m a n d . In this ex a m p l e the dat a b a s e is 's1 h o m e s ' . an d it ne e d s to be re p a i r e d .check records and index references myisamchk: error: Record at: 102568272 Can't find key for index: 1 MyISAM-table 'property_images' is corrupted Fix it using switch "-r" or "-o" [root@s1dbmysql2 s1homes]# A n d w e ca n se e that w e do ind e e d ha v e an err o r in this tabl e – its str u c t u r e is cor r u p t . P a g e 99 . or to notif y the cu s t o m e r w h o s e M y S Q L ser v e r it w a s. Fo r ex a m p l e .check file-size .frm -rw-rw---1 mysql mysql 105488948 Mar 28 11:40 property_images.check record delete-chain . Th e co m m a n d for per f o r m i n g tabl e ch e c k s is myisamchk.check index reference .Task 4: Chec kin g tables for errors If ev e r M y S Q L is re p o r t i n g err o r s wit h a tabl e in a par ti c u l a r dat a b a s e that it's not be e n abl e to fix itself. It ca n per f o r m saf e ch e c k s on an y tabl e in an y st a n d a r d M y S Q L dat a b a s e wit h the -c.lin e utilit y wit h w hi c h w e ca n car r y out furt h e r tabl e ch e c k i n g our s e l v e s to verif y that the r e is a pr o b l e m .MYI [root@s1dbmysql2 s1homes]# myisamchk -c -e -T property_images Checking MyISAM file: property_images Data records: 1206073 Deleted blocks: 20092 myisamchk: warning: 1 client is using or hasn't closed the table properly .check key delete-chain .

sendmail at a glance A s bef o r e . or it ca n be for w a r d i n g on em a il se n t by tho s e cu s t o m e r s to the out s i d e w o r l d. the s e ar e the def a u l t as s u m p t i o n s on a R e d H a t.4. • Th e se n d m a i l bi n a r y is us u a l l y ref e r r e d to as /usr/sbi n/s e n d m a i l • M a il b o x e s for loc al us e r s ar e ke p t in /var/sp o o l/ m a il • Th e co n t e n t s of the cur r e n t m a il qu e u e ar e stor e d in /var/sp o o l/ m q u e u e • Th e def a u l t log file for se n d m a i l is /var/log/m a ill o g • M o s t co n f i g u r a t i o n file s ar e stor e d in the dir e c t o r y /etc/m ail • Th e list of IP ad d r e s s e s that ar e allo w e d to se n d m a il thr o u g h the ser v e r is ke p t in the file /etc/m ail/ac c e s s • Th e list of do m a i n s that the ser v e r ca n rec e i v e e-m a il for is ke p t in /etc/m ail/lo c a l.deri v e d sy s t e m . c f Task 1: Starting and stopping sendmail P a g e 10 0 .4 E-mail server – sendmail O n m o s t R e d H at.deri v e d Li n u x sy st e m s .ho s t. se n d m a i l is the def a u l t m a il tra n s f e r ag e n t (or M T A). Ty p i c a l l y an S M T P ser v e r perf o r m s on e of the follo w i n g role s: • • • • R e c e i v e s e-m a il via S M T P fro m the out si d e w o r l d.6. an d sa v e s it in loc al P O P 3 or IM A P 4 m a i l b o x e s R e c e i v e s e-m a il via S M T P fro m the out si d e w o r l d an d pa s s e s it on to an o t h e r loc a l m a i l ser v e r w hi c h hol d s the act u a l P O P 3 or IM A P 4 m a il b o x e s R e c e i v e s e-m a il via S M T P fro m cu s t o m e r s se n d i n g m a il fro m their em a il clie n t s to be pa s s e d on to ot h e r de s t i n a t i o n s els e w h e r e A n y co m b i n a t i o n of the ab o v e S o an M T A ca n eit h e r be rec e i v i n g e-m a il fro m the out s i d e w o r l d that ha s be e n se n t to the cu s t o m e r s it ser v e s .na m e s • Th e list of co n f i g u r e d e-m a i l ad d r e s s e s is ke p t in /etc/m ail/virt u s e r t a b l e • Th e m a s t e r co n f i g u r a t i o n file is /etc/m ail/se n d m a i l . M T A s ar e pie c e s of ser v e r soft w a r e that ar e res p o n s i b l e for tra n s f e r r i n g e-m a il via S M T P fro m on e ser v e r to an o t h e r .

. If it's no n e an d it's a ser v e r that sh o u l d be bu s y.net@jefferylee.) <sidelinefats@bitsmart. Requested mail action ) <bgm2@btconnect.. U s u a l l y the r e will be – ne a r l y al w a y s .com> l2S4Xato027998 16851 Wed Mar 28 05:33 <magnadrylafayette. l2S2biiq024719 8801 Wed Mar 28 03:37 <istchoices@graphicworksatlanta. Task 2: Chec kin g the mail queue O n e of the m o s t co m m o n tas k s yo u w a n t to per f o r m wit h se n d m a i l is to ch e c k ho w m a n y e-m a il s ar e cur r e n t l y sittin g in its m a il qu e u e . that' s pr o b a b l y a pr o b l e m too.com..com> (Deferred: Connection timed out with aerospaceuk. Th e m a il qu e u e is ch e c k e d wit h the 'm ail q' co m m a n d as follo w s : [root@mta4 root]# mailq /var/spool/mqueue/q1 (31 requests) -----Q-ID----.) <catchall@aerospaceuk. If it's se v e r a l ten d s of tho u s a n d s . be c a u s e e-m a il that is in the mi d s t of bei n g tra n s f e r r e d w h e n yo u as k se n d m a i l to sto p will fini s h pr o c e s s i n g bef o r e it act u a l l y exit s.--Size-.-----Q-Time----.com.com> l2SAijV80005551501 Wed Mar 28 11:44 <leota18@speedy.co.com> l2SAnl4S010249 9424 Wed Mar 28 11:49 <hwffppclotz@versanet.com>.com> . S o al w a y s m a k e sur e that all ol d se n d m a i l pr o c e s s e s ar e de a d an d go n e bef o r e star ti n g se n d m a i l ba c k up. that' s a pr o b l e m . sin c e the ser v e r mi g h t be too full to ev e r get thr o u g h its qu e u e an d req u i r e att e n t i o n to fix w h a t e v e r ha s go n e wr o n g . in fact.de> (Deferred: 451 <bgm2@btconnect. it's al w a y s a go o d ide a to ch e c k that no ol d se n d m a i l pr o c e s s e s ar e still ha n g i n g ar o u n d .ar> (Deferred) <marcus@startrecruitment.bitsmart.com> (Deferred: 451 <magnadrylafayette. or els e yo u'll just get an err o r.net@jefferylee.------------Sender/Recipient----------l2SAtUoH022193 4915 Wed Mar 28 11:55 <> 8BITMIME (Deferred: Connection timed out with mail3.com. To star t: service sendmail start A n d to sto p: service sendmail stop If yo u' v e st o p p e d se n d m a i l an d ar e w a n t i n g to re-star t it.W e w o n ' t d w e l l too m u c h on the st arti n g an d st o p p i n g at this poi n t – yo u get the ide a by no w (hop e f u l l y !).uk> Total requests: 995 P a g e 10 1 .com> unable ) <cliveyandrews@tiscali.

148]. delay=04:27:42. size=17488.net@jefferylee. relay=mx5. dsn=4. relay=[12. msgid=<000001c770f2$1a5c4680$0100007f@localhost>.uk.0.0.100.uk>. proto=SMTP. N o r m a l l y yo u w o n 't ne e d to w o r r y too m u c h ab o u t this dat a.co.localdomain [127. msgid=<000001c770f2$1a5c4680$0100007f@localhost>. [212.0.com>.151].[root@mta4 root]# In this ab b r e v i a t e d list (you w o u l d re all y ha v e se e n a full list of all 995 em a il s). relay=mx5.net@jefferylee. Let's sa y w e w a n t e d full e r inf or m a t i o n on that last e-m a il in the m a il qu e u e .150]. the siz e of the e-m a il in byt e s.com>. c o m .0.100.74. that' s pr o b a b l y a sp a m ru n or so m e o n e ' s getti n g m a i l.co.0. delay=00:00:13.net@jefferylee.0. daemon=MTA-RX.uk>. n e t @ j e f f e r y l e e . xdelay=00:00:09. mailer=esmtp.0.com> unable to verify address P a g e 10 2 . delay=02:28:03. ex c e p t to ch e c k that the qu e u e is of an ac c e p t a b l e siz e. Task 3: Finding out more about a particular mes s a g e in the queue S o m e t i m e s .76] Mar 28 05:33:37 mta4 sendmail[27998]: l2S4Xato027998: from=<magnadrylafayette.com> unable to verify address Mar 28 10:01:18 mta4 sendmail[7887]: l2S4Xato027998: to=<cliveyandrews@tiscali. xdelay=00:00:11.147]. [212. nrcpts=1. class=0. an d that the r e ar e no m a s s i v e e-m a i l s st u c k in the qu e u e that mi g h t be ca u s i n g pr o b l e m s . stat=Deferred: 451 <magnadrylafayette.tiscali.uk>. w h e n it w a s su b m i t t e d to the ser v e r . stat=Deferred: 451 <magnadrylafayette.com. xdelay=00:00:11.194. so w e ca n se a r c h for thi s in the se n d m a i l log file: [root@mta4 root]# grep l2S4Xato027998 /var/log/maillog Mar 28 05:33:36 mta4 sendmail-rx[27946]: l2S4XZ61027946: from=<magnadrylafayette. yo u w a n t m o r e det a il e d inf o r m a t i o n on on e parti c u l a r m e s s a g e in the qu e u e .uk. pri=137488. daemon=MTA. class=0. the on e fro m m a g n a d r y l a f a y e t t e . pri=227488.tiscali. the def a u l t se n d m a i l logfil e.74.net@jefferylee.74.74. mailer=esmtp. relay=mx3. [212.bo m b e d . relay=localhost.co. mailer=esmtp. delay=01:18:17.tiscali.com> unable to verify address Mar 28 08:01:39 mta4 sendmail[27734]: l2S4Xato027998: to=<cliveyandrews@tiscali.uk. Al s o.com> unable to verify address Mar 28 06:51:53 mta4 sendmail[1918]: l2S4Xato027998: to=<cliveyandrews@tiscali.0. [212.107.0. proto=ESMTP. pri=47488. an d the e-m a i l ad d r e s s e s it is co m i n g fro m an d goi n g to.uk>.tiscali.100.com.net@jefferylee. dsn=4.com.1] Mar 28 05:33:49 mta4 sendmail[28002]: l2S4Xato027998: to=<cliveyandrews@tiscali. dsn=4. relay=mx1.com. nrcpts=1. size=17311. W e ca n se e it ha s a uni q u e qu e u e ID of 1 2 S 4 X a t o 0 2 7 9 9 8 . xdelay=00:00:12.co.net@jefferylee.0. stat=Deferred: 451 <magnadrylafayette.100.uk. yo u ca n se e the qu e u e ID for ea c h e-m a il (ever y m a il cur r e n t l y in the qu e u e ha s a uni q u e ide n t i fi e r – a bit like PI D s for pr o c e s s e s in ter m s of w h a t it do e s). mailer=esmtp. if ev e r yo u se e tho u s a n d s of e-m a il s all co m i n g fro m the sa m e ad d r e s s or goi n g to the sa m e reci p i e n t . stat=Deferred: 451 <magnadrylafayette. dsn=4. pri=317488. Y o u ca n do this by usi n g gr e p to se a r c h for its uni q u e qu e u e ID in /var/log/m a ill o g .

P a g e 10 3 . delay=06:28:00.uk.uk>. mailer=esmtp.74. stat=Deferred: 451 <magnadrylafayette. it's al m o s t cert a i n l y a sp a m e-m a il or so m e ot h e r si mil a r jun k. pri=407488.com.inf e c t e d P C s or sp a m m e r s . In ot h e r w o r d s .Mar 28 12:01:36 mta4 sendmail[1192]: l2S4Xato027998: to=<cliveyandrews@tiscali.tiscali.u k. ther e' s a lot of dat a her e to be sur e. but w e ca n se e that the m e s s a g e is bei n g rej e c t e d by its fin al de s t i n a t i o n (mx5.net@jefferylee. xdelay=00:00:12. S o yo u'r e likel y to se e far m o r e e-m a il s that ar e jun k tha n not in yo u r tra v e l s .com> unable to verify address N o w . dsn=4.150]. It's a sa d fact that pr a c t i c a l l y all e-m a il that pa s s e s thr o u g h m o s t m a il ser v e r s on the Int e r n e t the s e da y s is eit h e r sp a w n e d by vir u s.100.co.0. relay=mx5.ti s c a l i. [212.0. c o m) be c a u s e the ad d r e s s of the se n d e r ca n n o t be verifi e d .

7. Conclu sion W e l l. Si m i l a r l y. W e' v e go n e in this do c u m e n t fro m the ver y ba si c s of co n n e c t i n g to a Lin u x sy st e m an d na v i g a t i n g its file s y s t e m . It's a lot to tak e in. G o o d luc k ! P a g e 10 4 . or if yo u feel yo u ne e d to re a d ba c k ov e r pr e v i o u s se c ti o n s of the G ui d e . an d yo u sh o u l d n ' t w o r r y if at this poi n t ther e ar e par t s that yo u ar e still un cl e a r on. B y all m e a n s do so – that' s w h a t it's the r e for. feel fre e to as k – ot h e r m e m b e r s of the tea m will be m o r e tha n ha p p y to hel p yo u. up to m o r e ad v a n c e d sy s t e m s ad m i n i s t r a t i o n co n c e p t s de a l i n g wit h indi vi d u a l ser v e r soft w a r e pr o d u c t s su c h as A p a c h e an d M y S Q L . if yo u ha v e an y qu e s t i o n s at all. w e' v e no w co m e to the en d of our Lin u x G u i d e .

Sign up to vote on this title
UsefulNot useful