pyladies talk: learn to love the command line!

Post on 07-Aug-2015

150 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

LEARN TO LOVE THECOMMAND LINE

Thursday, 19 February, 2015

Google MontrealShopify Montreal

IN LOVE WITH...THE COMMAND LINE

/ /

http://cli-talk.bitballoon.com

Blanca Mancilla bluciam @Blanckus

LinuxCommand.org

You have Linux installed and running. TheGUI is working fine, but you are gettingtired of changing your desktop themes.You keep seeing this "terminal" thing.

WHAT IS THE COMMANDLINE?

Anybody with little or no experience?What do you know about it?

What are you expecting to learn tonight?

WHAT IS THE COMMANDLINE?

Specifically, the computer program is the operatingsystem (UNIX or nowadays Linux) and the interface is

what we called the .

THE COMMAND LINEAND THE SHELL

A command-line interface (CLI) is a means of interacting with a computer program where the user issues commands to the program in the form of successive lines of text (command lines).

https://en.wikipedia.org/wiki/Command-line_interface

shell

TYPES OF SHELLS IN LINUXshbashcsh and tcshkshread more...

HOW DO I KNOW WHICHSHELL?

~ $ w h i c h b a s h/ b i n / b a s h~ $ w h i c h s h/ b i n / s h~ $ w h i c h c s h~ $ e c h o $ S H E L L/ b i n / b a s h~ $ s h$ e c h o $ S H E L L/ b i n / b a s h$ p s - p $ $ P I D T T Y T I M E C M D1 7 7 9 3 p t s / 2 8 0 0 : 0 0 : 0 0 s h$ ^ D~ $ p s - p $ $ P I D T T Y T I M E C M D1 5 6 1 5 p t s / 2 8 0 0 : 0 0 : 0 1 b a s h

THE INSPIRATION

by Jeroen JanssensData Science at the Command Line

—Chris H. WigginsAssociate Professor in the Department of Applied Physics

and Applied Mathematics at Columbia Universityand Chief Data Scientist at The New York Times

The Unix philosophy of simple tools, eachdoing one job well, then cleverly pipedtogether, is embodied by the commandline. Jeroen expertly discusses how to

bring that philosophy into your work indata science, illustrating how the

command line is not only the world of fileinput/ output, but also the world of data

manipulation, exploration, and evenmodeling.

APPENDIX: COMMANDSalias awk aws bash bc bigmler body cat cd chmod colscowsay cp csvcut csvgrep csvjoin csvlook csvsort csvsql

csvstack csvstat curl curlicue cut display drake dseq echoenv export feedgnuplot fieldsplit find for git grep headheader in2csv jq json2csv less ls man mkdir mv parallel

paste pbc pip pwd python R Rio Rio-scatter rm

SOME DETAILSNOW!

Yes! Of course.

FOR LOOPS?

f o r i i n * p d f ; d o e v i n c e $ i ; d o n e

FOR LOOPS: l y c e u m $ l s * p d fH o w T o B e A P r o g r a m m e r . p d f S E N G 3 0 2 0 - 0 . 1 . p d f t e a c h i n g - p r g m . p d fS E N G 3 0 1 0 - B A R T - R e q - v 1 - 1 - 3 d . p d f S E N G 3 0 2 0 _ 0 7 s 2 . p d f: l y c e u m $ e v i n c e * p d f: l y c e u m $ f o r i i n * p d f ; d o e v i n c e $ i ; d o n e

or even

FOR LOOPSIn a script

f o r i i n * p d fd o e v i n c e $ id o n e

f o r i i n ` l s * p d f `d o e v i n c e $ id o n e

More info

CHECK IF A FILE EXISTS ANDIF NOT ...

c l i - t a l k : $ [ - f i n d e x . h t m l ] & & e c h o " Y e s , w e h a v e a p r e s e n t a t i o n ! " \| | e c h o " P A N I C "

CHECK IF A FILE EXISTS ANDIF NOT ...

Let's try a demo

CHECK IF A FILE EXISTS ANDIF NOT ...

c l i - t a l k : $ l o c a t e * 9 7 6 8 . J P G

GLOB PATTERNS:REAL MAGIC!

Strictly speaking, there are neither regular expressionsnor patterns used in pattern recognition.

They are .glob patterns

GLOB PATTERNS:REAL MAGIC!

l s a p p / * . { e r b , s c s s , r b , y m l }

v i p u b l i c _ h t m l / [ i I ] * . h t m *

My favorite: Move all image files for the years 2010 to 2012 into .

GLOB PATTERNS:REAL MAGIC!

my_dir

m v { I M G , i m g } * 2 0 1 [ 0 1 2 ] * . { j p g , J P G , p n g , g i f } m y _ d i r

FIND A RESOURCEANYWHERE IN YOUR HARD

DRIVE

versus

FIND A RESOURCE ...locate find

L o r i B i z : $ l o c a t e * . e r bL o r i B i z : $ f i n d . - n a m e * . e r b

find . -name *.erb -exec ls {} \;

find . -name *.erb -exec grep mytableauthor {} \;

find . -name *.erb -exec grep -H mytableauthor {} \;

find . -name *.scss -exec grep -H mytableauthor {} \;

find . -name *.scss -exec grep -n -H mytableauthor {} \;

FIND A RESOURCE...

FIND AND REPLACE TRAILINGSPACES IN SOURCE CODE

FIND ... TRAILING SPACES INSOURCE CODE

c l i - t a l k $ g r e p " \ s \ + $ " i n d e x . h t m l

... REPLACE TRAILING SPACESIN SOURCE CODE

L o r i B i z $ f i n d . - n a m e * . e r b - e x e c g r e p - H n " \ s \ + $ " { } \ ; L o r i B i z $ f i n d . - n a m e * . e r b - e x e c g r e p - H n " \ s \ + $ " { } \ ; - e x e c v i { } \ ;

# O n c e i n v i f i n d a n d r e p l a c e u s i n g t h e c o m m a n d: % s / \ s \ + $ / /

MAKING BACKUPS OFGIT REPOSITORIESsuperspreadsheet.wordpress.com

MAKING BACKUPS OF ...1. pull from the bare repository2. commit local changes3. push changes to the bare repository

Pull and Commit

MAKING BACKUPS OF ...

1 # ! / b i n / s h 2 # 3 # A u t o m a t i c p u l l a n d c o m m i t o n t h e d i r e c t o r i e s l i s t e d i n d i r s _ t o _ p u l l 4 5 C R O N L O G = " / c o m p l e t e / p a t h / t o / p u l l c o m m i t p u s h . l o g " 6 C O M M I T M S G = " / c o m p l e t e / p a t h / t o / m s g A u t o C o m m i t " 7 e c h o > > $ C R O N L O G 8 e c h o " N i g h t l y g i t a u t o - c o m m i t f o r t h e a b s e n t m i n d s : $ ( d a t e ) " > > $ C R O N L O G 9 f o r i i n ` c a t / c o m p l e t e / p a t h / t o / d i r s _ t o _ p u l l `1 0 d o ( c d $ i ;1 1 e c h o " P U L L $ i $ ( d a t e ) " > > $ C R O N L O G ;1 2 g i t p u l l > > $ C R O N L O G 2 > & 1 ;1 3 e c h o " C O M M I T $ i $ ( d a t e ) " > > $ C R O N L O G ;1 4 g i t c o m m i t - a - F $ C O M M I T M S G > > $ C R O N L O G 2 > & 11 5 e c h o > > $ C R O N L O G )1 6 d o n e 1 7 e c h o > > $ C R O N L O G ;

Push

MAKING BACKUPS OF ...

1 # ! / b i n / s h 2 # 3 # A u t o m a t i c p u s h o n t h e d i r e c t o r i e s l i s t e d i n d i r s _ t o _ p u s h 4 5 C R O N L O G = " / c o m p l e t e / p a t h / t o / p u l l c o m m i t p u s h . l o g " 6 e c h o > > $ C R O N L O G 7 e c h o " N i g h t l y g i t a u t o - p u s h f o r t h e a b s e n t m i n d s : $ ( d a t e ) " > > $ C R O N L O G 8 f o r i i n ` c a t / c o m p l e t e / p a t h / t o / d i r s _ t o _ p u s h ` 9 d o ( c d $ i ;1 0 e c h o " P U S H : $ i $ ( d a t e ) " > > $ C R O N L O G1 1 g i t p u s h > > $ C R O N L O G 2 > & 11 2 e c h o > > $ C R O N L O G1 3 ) ;1 4 d o n e1 5 e c h o > > $ C R O N L O G ;

: from the Greek word for time, χρόνος chronos.

MAKING BACKUPS USING ...cron

https://en.wikipedia.org/wiki/Cron

MAKING BACKUPS USING ...Cron is a time-based job scheduler thatSysadmins use to schedule jobs to run

periodically at fixed times, dates, orintervals (i.e. download email at regular

intervals).

MAKING BACKUPS USING ...c r o n t a b - e

minute hour dayOfMonth month dayOfWeek command

3 2 * * * / c o m p l e t e / p a t h / t o / p u l l _ c o m m i t 2 > / c o m p l e t e / p a t h / t o / p u l l _ c o m m i t . e r r5 2 * * * / c o m p l e t e / p a t h / t o / p u s h 2 > / c o m p l e t e / p a t h / t o / p u s h . e r r

Blog post in development!

CREATING A COPY OF A GITREPOSITORY WHICH IS NOT

QUITE A COPY

THE ENDAre you in love yet?

JavaScript source code for the slides taken from.

I encourage you to try it!

THE ENDreveal.js

top related