Slide 1

Slide 1 text

speakerdeck.com/ uranusjr

Slide 2

Slide 2 text

Agenda • Introduction • The shell • Git • Linux topics • Writing code • Python basics • Python in shell • Extensions

Slide 3

Slide 3 text

Introduction to Linux

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Me • Call me TP • https://uranusjr.com • Python, C++, OS X, iOS, Web • Tutorials and courses • Speaker • Django Girls Taipei


Slide 6

Slide 6 text

Quick Polls • Something “not Windows” • Command line interface • Plain text editors • Programming

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Prompt

Slide 10

Slide 10 text

pi@raspberrypi:~$

Slide 11

Slide 11 text

pi@raspberrypi:~$ ⢪欽罏

Slide 12

Slide 12 text

pi@raspberrypi:~$ ⚺堣せ珕

Slide 13

Slide 13 text

pi@raspberrypi:~$ 騟䖜

Slide 14

Slide 14 text

Shell • Core — Shell — User • Command line interface • Bash (Bourne-Again Shell)

Slide 15

Slide 15 text

$  pwd   /home/pi

Slide 16

Slide 16 text

$  mkdir  bedroom  

Slide 17

Slide 17 text

$  ls   bedroom    Desktop

Slide 18

Slide 18 text

$  touch  table  

Slide 19

Slide 19 text

$  ls   bedroom    Desktop    table

Slide 20

Slide 20 text

$  cd  bedroom   $  pwd   剙곎爙➊랁

Slide 21

Slide 21 text

$  mkdir  closet  

Slide 22

Slide 22 text

銲䙥랁鹌Ⰵ  closet

Slide 23

Slide 23 text

$  cd  closet  

Slide 24

Slide 24 text

$  cd  ../..   植㖈➂㖈ㆬ酬♶銲⡲䒦

Slide 25

Slide 25 text

穩㼨騟䖜   /home/pi/bedroom/closet   湱㼨騟䖜   bedroom/closet

Slide 26

Slide 26 text

..  =  㢩꬗

Slide 27

Slide 27 text

現在位置(.)   /home/pi/bedroom/closet   外面兩層(../..)   /home/pi

Slide 28

Slide 28 text

$  cd  ~   $  cp  -­‐r  bedroom  guest-­‐room   $  ls   剙⳿植➊랁

Slide 29

Slide 29 text

$  cd  guest-­‐room   酬꬗僽やㄤ  bedroom  ♧垺剣♧ ⦐  closet銲䙥랁墝叆

Slide 30

Slide 30 text

拷貝一樣東西   cp  something   拷貝一樣東西,以及裡面的所有東西   cp  -r  something

Slide 31

Slide 31 text

拷貝一樣東西   cp  something   拷貝一樣東西,以及裡面的所有東西   cp  -r  something չ⿭侶պ䧴չ䒷侶պ

Slide 32

Slide 32 text

$  man  cp   ...   -­‐R,  -­‐r,  -­‐-­‐recursive          copy  directories  recursively

Slide 33

Slide 33 text

$  cd  ..   鸍垺剙ⵋㆬ酬

Slide 34

Slide 34 text

$  mv  guest-­‐room  living-­‐room   $  ls   剙⳿植➊랁

Slide 35

Slide 35 text

$  mv  living-­‐room/closet  bedroom/closet2   鸍⦐䭷⟀⨞✪➊랁✲䞔

Slide 36

Slide 36 text

$  rm  ~/table   $  rm  -­‐r  ~/bedroom   $  rm  -­‐r  ~/living-­‐room   敮嫅։

Slide 37

Slide 37 text

The File System • The root directory • Other partitions are “mounted” • Things have their places • Names are case-sensitive

Slide 38

Slide 38 text

/ ├── bin ├── dev ├── etc ├── home │ └── pi ├── lib ├── media ├── opt ├── root ├── tmp ├── usr └── var

Slide 39

Slide 39 text

Permissions • Essential for Un*x systems • Owner, group, others • Read, write, execute

Slide 40

Slide 40 text

$  groups   pi  adm  dialout  cdrom  sudo  audio   video  plugdev  games  users  netdev   gpio  i2c  spi  input

Slide 41

Slide 41 text

$  groups  pi   pi  :  pi  adm  dialout  cdrom  sudo   audio  video  plugdev  games  users   netdev  input  spi  i2c  gpio

Slide 42

Slide 42 text

$  cd  /var   $  ls  -­‐l   total  102436   drwxr-­‐xr-­‐x  8  root  root    Aug  16  05:17  log   drwxrwsr-­‐x  2  root  mail    May    6  22:12  mail   -­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐  1  root  root    May    6  23:29  swap   drwxrwxrwt  2  root  root    Jan  11    2015  tmp

Slide 43

Slide 43 text

奚ꣳ垦硹 䠑纏 r 隡《 w 㻨Ⰵ x 㛂遤鹎Ⰵ湡ꏗ s ⟃暶㹁魨⟨㛂遤 t ⫦乩剤罏〳ⵅꤑ荈䊹涸墂呪

Slide 44

Slide 44 text

奚ꣳ垦硹 䠑纏 r 隡《 w 㻨Ⰵ x 㛂遤鹎Ⰵ湡ꏗ s ⟃暶㹁魨⟨㛂遤 t ⫦乩剤罏〳ⵅꤑ荈䊹涸墂呪

Slide 45

Slide 45 text

$  cd  /var   $  ls  -­‐l   total  102436   drwxr-­‐xr-­‐x  8  root  root    Aug  16  05:17  log   drwxrwsr-­‐x  2  root  mail    May    6  22:12  mail   -­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐  1  root  root    May    6  23:29  swap   drwxrwxrwt  2  root  root    Jan  11    2015  tmp

Slide 46

Slide 46 text

The Superuser • “root” • Can do anything • Log-in disabled by default

Slide 47

Slide 47 text

/ ├── bin ├── dev ├── etc ├── home │ └── pi ├── lib ├── media ├── opt ├── root ├── tmp ├── usr └── var Superuser’s home directory!

Slide 48

Slide 48 text

sudo • “superuser do” • Run a command as superuser • Requires the sudo group

Slide 49

Slide 49 text

$  groups  pi   pi  :  pi  adm  dialout  cdrom  sudo   audio  video  plugdev  games  users   netdev  input  spi  i2c  gpio

Slide 50

Slide 50 text

$  whoami   pi   $  sudo  whoami   root

Slide 51

Slide 51 text

Package Manager • APT = Advance package Tool • apt-get • apt-cache

Slide 52

Slide 52 text

$  sudo  apt-­‐get  update   $  sudo  apt-­‐get  install  git

Slide 53

Slide 53 text

Git Basics

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

$  cd  ~   $  git  clone  https://github.com/raspberrypi-­‐ tw/workshop.git   $  cd  workshop/gpio-­‐tutorial-­‐03/02_2-­‐ led_blink/led_blink.py   $  ls   led.py

Slide 57

Slide 57 text

$  python  led.py

Slide 58

Slide 58 text

HJUDMPOF 䭡頺♧⦐(JU墂呪䏨 HJUBEE墂呪 䪾墂呪⸈Ⰵ墂呪䏨 HJUBEE〳⟃♧妄⸈Ⰵ鿈墂呪 HJUDPNNJUN鏽鎹 ⸈Ⰵ♧⦐晝劥 HJUTUBUVT 叆溏湡⵹涸墂呪䏨朜䢀 HJUEJ 叆溏湡⵹墂呪䏨ㄤ♳⦐晝劥⛓꟦涸䊴殯 HJUMPH 叆溏晝劥鎹ꏗ HJUQVTI 㼟劥㖒墂呪䏨♳⫄荛黇畮 HJUQVMM 刿倞劥㖒Ⰹ㺂

Slide 59

Slide 59 text

How a Linux OS Boots

Slide 60

Slide 60 text

Boot Sequence • Load the kernel (details omitted) • Prepare the system • Start services • Run custom startup hooks • User log in

Slide 61

Slide 61 text

Boot Sequence • Load the kernel (details omitted) • Prepare the system • Start services • Run custom startup hooks • User log in

Slide 62

Slide 62 text

Run Levels ꡠ堥 ㋲➃笞隌垸䒭 搂/'4㢵➃垸䒭 㸤侮㢵➃垸䒭 ⥃殆 㕮䕎➝꬗ ꅾꟚ堥

Slide 63

Slide 63 text

$  ls  -­‐d  /etc/rc*   /etc/rc0.d    /etc/rc1.d    /etc/rc2.d   /etc/rc3.d    /etc/rc4.d    /etc/rc5.d   /etc/rc6.d    /etc/rc.local    /etc/rcS.d

Slide 64

Slide 64 text

$  ls  -­‐d  /etc/rc*   /etc/rc0.d    /etc/rc1.d    /etc/rc2.d   /etc/rc3.d    /etc/rc4.d    /etc/rc5.d   /etc/rc6.d    /etc/rc.local    /etc/rcS.d

Slide 65

Slide 65 text

raspberrypi  login:

Slide 66

Slide 66 text

$  ls  -­‐A  ~   .bashrc      .bash_logout      .bash_profile   .profile   $  ls  -­‐d  /etc/profile*     /etc/profile    /etc/profile.d

Slide 67

Slide 67 text

Summary • Startup • Run levels • Single-user and multi-user mode • Login shells and non-login shells

Slide 68

Slide 68 text

$  nano

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

^R ➿邌 Control

Slide 71

Slide 71 text

倰ぢ꒳ 獵⹛康垦 1H6Q 1H%O )PNF &OE 獵⹛康垦 ^O 㶸墂 ^R Ꟛ㉬墂呪 ^X 鷎ⴀ剚鑉㉏僽や⮭㶸墂呪 ^W 䵃㼦 ^K 䭡頺♧遤俒㶶 ^U 顦♳⛓⵹䭡頺涸俒㶶

Slide 72

Slide 72 text

Demo

Slide 73

Slide 73 text

Error  writing  /etc/hosts:  Permission  denied

Slide 74

Slide 74 text

Demo

Slide 75

Slide 75 text

Try it!

Slide 76

Slide 76 text

$  cd  ~   $  git  clone  https://github.com/serialhex/ nano-­‐highlight.git  .nano   $  nano  .nanorc

Slide 77

Slide 77 text

include  "~/.nano/python.nanorc"   set  tabsize  4   set  tabstospaces