tonight we dine in shell tonight we dine in shell
play

Tonight we dine in shell Tonight we dine in shell Hands-On Unix - PowerPoint PPT Presentation

Lecture 3 Lecture 3 Tonight we dine in shell Tonight we dine in shell Hands-On Unix System Administration DeCal 2012-09-17 Review $ 1 , $ 2 , . . . ; $ @ , $ * , $ # , $ 0 , $ ? e n v i r o n m e n t v


  1. Lecture 3 Lecture 3 Tonight we dine in shell Tonight we dine in shell Hands-On Unix System Administration DeCal 2012-09-17

  2. Review ● $ 1 , $ 2 , . . . ; $ @ , $ * , $ # , $ 0 , $ ? ● e n v i r o n m e n t v a r i a b l e s ● e n v , e x p o r t ● $ H O M E , $ P A T H ● $ P S 1 = n \ [ \ e [ 0 ; 3 1 m \ ] \ u \ [ \ e [ m \ ] @ \ [ \ e [ 1 ; 3 4 m \ ] \ w \ [ \ e [ 2 ; 9 0 m \ ] \ @ \ n \ [ \ e [ m \ ] \ [ \ e [ 0 ; 3 5 m \ ] \ h \ [ \ e [ m \ ] \ [ \ e [ 0 ; 3 1 m \ ] \ $ \ [ \ e [ m \ ] \ [ \ e [ 0 ; 3 2 m \ ] ● q u o t e s , ' a n d " ● a l i a s e s ● g l o b b i n g ● b a c k t i c k s ( ` ) ● p i p e s ( | )

  3. t e e ● e s s e n t i a l l y a p i p e ● m o s t l y u s e d t o d o $ s u d o < c o m m a n d > | s u d o t e e < f i l e >

  4. f i n d ● g o o g l e s e a r c h o n s t e r o i d s f o r f i l e s y s t e m ● r e g e x e s , d e p t h s , m t i m e s , t y p e s , g r o u p s , u s e r s , e t c . $ f i n d - L / u s r / p o r t s / p a c k a g e s - t y p e l - e x e c r m - - { } + $ f i n d / - n e w e r t t t - u s e r w n j - p r i n t $ f i n d a b - t y p e f ! - n a m e ' c r a z y ' - p r i n t f ' % f \ n '

  5. x a r g s ● m o s t u s e d a f t e r a f i n d : $ f i n d . - n a m e ' r a n d o m c r a p f i l e ' | x a r g s r m $ f i n d . - n a m e ' f i l e t o b e m o v e d ' | x a r g s - I { } m v { } s o m e f o l d e r -print0 u s e d w i t h f i n d t o p r i n t N U L c h a r a c t e r g e n e r a l l y f o r x a r g s -0 u s e d i n x a r g s i n c o n j u n c t i o n w i t h - p r i n t 0 f o r ` f i n d ' f o r f i l e s w i t h s p a c e s

  6. l o c a t e ● c a c h e d g o o g l e s e a r c h f o r f i l e s y s t e m ● p r e c o m p i l e d d a t a b a s e ● f find ' a s t e r t h a n ` , b u t n o t a s d e t a i l e d i n s e a r c h

  7. and w loops f o r h i l e ● b u i l t i n t o s h e l l S t r u c t u r e : f o r { s o m e t h i n g } d o s o m e c o m m a n d s o m e o t h e r c o m m a n d d o n e O n e - l i n e r , w i t h s e m i - c o l o n s : $ f o r { s o m e t h i n g } ; d o s o m e c o m m a n d ; s o m e o t h e r c o m m a n d ; d o n e

  8. loops and f o r w h i l e S t r u c t u r e w h i l e { s o m e t h i n g } d o s o m e c o m m a n d s o m e o t h e r c o m m a n d d o n e O n e - l i n e r , w i t h s e m i - c o l o n s : $ w h i l e { s o m e e x p r e s s i o n } ; d o s o m e c o m m a n d ; s o m e o t h e r c o m m a n d ; d o n e

  9. a w k ● f u l l p r o g r a m m i n g l a n g u a g e ● g e n e r a l l y u s e d t o d o ( s i m p l e ) r e g u l a r e x p r e s s i o n s o n f i l e s ● M o r e i n f o a t : h t t p s : / / e n . w i k i p e d i a . o r g / w i k i / A w k , h t t p : / / w w w . g r y m o i r e . c o m / U n i x / A w k . h t m l

  10. Moar shell-fu ● grep ● sed ● cut ● tr ● wc ● sort ● head ● tail

  11. t r t r [ O P T I O N ] . . . S E T 1 [ S E T 2 ] ● S E T 1 a n d S E T 2 d e f i n e o r d e r e d s e t s o f c h a r a c t e r s ( c h a r a c t e r s o f i n p u t t h a t ` t r ' o p e r a t e s o n ) ● F u n c t i o n i s t o r e p l a c e , s q u e e z e , r e m o v e c h a r a c t e r s f r o m i t s i n p u t – N o f i l e n a m e s t o p r o v i d e a s a r g u m e n t s ● R e a d s s t r e a m f r o m s t d i n , w r i t e s t o s t d o u t

  12. t r t r [ O P T I O N ] . . . S E T 1 [ S E T 2 ] ● E x a m p l e s $ e c h o “ t h e q u i c k b r o w n f o x ” | t r a b c d e f – R e p l a c e c h a r a c t e r s i n S E T 1 w i t h c o r r e s p o n d i n g c h a r a c t e r s i n S E T 2 c a n u s e r a n g e s ( e . g , a - z A - Z ) $ e c h o “ t h e q u i c k b r o w n f o x ” | t r a - z A - Z ● C o m m o n l y u s e d o p t i o n s - d , - - d e l e t e - s , - - s q u e e z e - r e p e a t s

  13. s o r t s o r t [ O P T I O N ] . . . [ F I L E ] . . . ● U s e f u l o p t i o n s : - d , - - d i c t i o n a r y - o r d e r ● C o n s i d e r b l a n k s a n d a l p h a n u m e r i c c h a r a c t e r s - n , - - n u m e r i c - s o r t S o r t b y n u m e r i c a l v a l u e - r , - - r e v e r s e R e v e r s e t h e r e s u l t o f c o m p a r i s o n s - f , - - i g n o r e - c a s e - k ( c o l u m n ) , - n k 2 m e a n s s o r t c o l u m n 2 n u m e r i c a l l y

  14. c u t c u t [ O P T I O N ] . . . [ F I L E ] . . . ● P r i n t s e l e c t e d p a r t s o f l i n e s f r o m e a c h F I L E ( o r s t d i n ) t o s t d o u t ● U s e f u l o p t i o n s : - d , - - d e l i m t e r = D E L I M - f , - - f i e l d s = L I S T

  15. h e a d / t a i l ● V i e w f i r s t / l a s t p a r t s o f f i l e ● U s e f u l f o r v i e w i n g l o g s ● D e f a u l t : v i e w f i r s t / l a s t 1 0 l i n e s ● C o m m o n o p t i o n s – - n , - - l i n e s = N ● O u t p u t f i r s t / l a s t N l i n e s , ● t a i l - f < f i l e > – “ f o l l o w ” t h e f i l e , o u t p u t a p p e n d e d d a t a a s < f i l e > g r o w s ● t a i l - n + N < f i l e > o r t a i l - - l i n e s = + N < f i l e > – S t a r t i n g f r o m N , o u t p u t N t o r e s t o f f i l e ● h e a d - - l i n e s = - N < f i l e > – V i e w e v e r y t h i n g b u t t h e l a s t N l i n e s i n < f i l e >

  16. w c ● W o r d c o u n t ● P r i n t n e w l i n e , w o r d , a n d b y t e c o u n t s ● w c - l , p r i n t n e w l i n e c o u n t ( c o u n t l i n e s ) ● w c - w , p r i n t w o r d c o u n t

  17. Regular Expressions (regex) ● S t r i n g m a t c h i n g ● S e t o f m e t a c h a r a c t e r s l e t y o u s e a r c h f o r t e x t t h a t f i t s c r i t e r i a ● T e x t e d i t o r s , u t i l i t i e s , p r o g r a m m i n g l a n g u a g e s  g r e p , s e d , a w k , v i ( m )  P e r l , R u b y , e t c . ● M a n y f l a v o r s , P O S I X B R E ≠ ● R e g e x g l o b s / w i l d c a r d s ● D i f f e r e n t s e t s o f m e t a c h a r a c t e r s u s e d f o r d i f f e r e n t p u r p o s e s ● F i l e n a m e e x p a n s i o n v s . s t r i n g m a t c h i n g ● T h e s h e l l i t s e l f d o e s n o t r e c o g n i z e R E ' s . I t i s t h e c o m m a n d s a n d u t i l i t i e s , t h a t d o .

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend