1 Linux Programming Environment Setup. Outline Introduce Linux Install Linux on Vmware 在...

62
1 Linux Programming Environment Setup

Transcript of 1 Linux Programming Environment Setup. Outline Introduce Linux Install Linux on Vmware 在...

Page 1: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

1

Linux Programming Environment Setup

Page 2: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Outline

Introduce Linux

Install Linux on Vmware

在 Windows 下常用的 Software

Practice

2

Page 3: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

INTRODUCE LINUX

3

Page 4: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

History Linus Torvalds make a Minix (Mini Unix) kernel

Just only 10000 row of C codes

Richard Stallman bring up GNU plan Open source Free Unix-like

GNU/Linux Linux Kernel + many modules

4

Page 5: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Use

Server MySql + PHP + Apache

Embedded system STB (Set Top Box)

Super Computer 75% (Top 500 on the world)

Game Sony PlayStation 3 Microsoft XBOX

5

Page 6: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Linux Kernel

Linux Kernel version format Linux-a.b.c

a kernel version b odd : test

even : stable c number of bug fix

Common, Linux-2.4.x and Linux-2.6.x

6

Page 7: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Linux distribution

Redhat 9 Linux-2.4.x Fedora 1 Linux-2.4.x Fedora 2~ Linux-2.6.x Debian more app. (15940) Trustix more safe and

stable Knoppix LiveCD

7

Page 8: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Other

There’s nothing impossible on Linux, because Source code can change

Find Linux distribution or modules 義守大學檔案伺服器 http://ftp.isu.edu.tw/

Good Web Site 鳥哥的 Linux 私房菜

http://linux.vbird.org/8

Page 9: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

INSTALL LINUX ON VMWARE

9

Page 10: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Vmware

Use software (VMware ESX Server) to“virtualize”the hardware resources

Including the CPU, RAM, hard disk and network controller

To create a virtual machine that can run its own operating system

and applications just like a “real” computer

10

Page 11: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Install Linux – Vmware 執行畫面

11

Page 12: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Install Linux – 新增一個新的 Virtual Host

12

Page 13: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

13

Install Linux – 選擇 Typical ( 典型 Virtual Host)

Page 14: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

14

Install Linux – 撰擇 Virtual Host 上欲安裝之系統

Page 15: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

15

Install Linux –設定 Virtual Host 名稱及位置

Page 16: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

16

Install Linux –設定 Virtual Host 網路狀態

Page 17: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

17

Install Linux – 決定 Virtual Host 可用之空間

Page 18: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

18

Install Linux – 分配 Virtual Host 硬碟空間中

Page 19: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

19

Install Linux – 完成一個 Virtual Host, 準備正式安裝 Linux

Page 20: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

20

Install Linux –選擇 image 檔來源 ,可由網路捉取或由課程網站 download

Page 21: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

21

Install Linux – 執行 Linux image 檔 ( 如同以光碟片開機 )

Page 22: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

22

Install Linux – Linux 開機後的畫面

Page 23: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Install Linux – 略過 image 檢查

23

Page 24: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Mainly, press the “Next” forever

We’ll point out options that need to setup below

24

Page 25: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

25

Install Linux –選擇所要的 Linux 環境

Page 26: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

26

Install Linux –網路設定

Page 27: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Install Linux –時區設定

27

Page 28: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Install Linux –登入之密碼設定

28

Page 29: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Install Linux –選擇所要的 Linux 模組

只選擇以下套件 Development Tools Editors

29

Page 30: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Install Linux –開始安裝到硬碟

30

Page 31: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Install Linux –換下一片 image 檔

31

Page 32: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Install Linux –決定是否建立開機磁片

32

Page 33: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Install Linux –成功安裝 Linux, 重開機後之畫面

33

Page 34: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

設定 Linux – 利用 setup 指令 , 關閉不需要之服務

34

Page 35: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

設定 Linux –只留下 network 與 sshd 兩個服務後 , 重開機

35

Page 36: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

設定 Linux –若需更改網路設定 , 亦可利用 setup 指令重新設定

36

Page 37: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

37

Page 38: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

在 Windows 下常用的 Software – 用來與 Linux 溝通

38

Page 39: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Pietty – 類似 Telnet 軟體 Use SSH ( Secure Shell ) protocol

Allows data to be exchanged over a secure channel between two computers

Why use it? Convenient for In/Out Vmware console Good copy way

http://ntu.csie.org/~piaip/pietty/39

Page 40: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

40

Page 41: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

41

Page 42: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Winscp – ftp 軟體 Support

SFTP (SSH File Transfer Protocol) SCP (Secure Copy Protocol) FTP (File Transfer Protocol)

Good way to transmission data between Windows and Linux

http://winscp.net/eng/docs/lang:cht

42

Page 43: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

43

Page 44: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

44

Page 45: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

LINUX COMMON COMMANDS

45

Page 46: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Linux Command Format

Command [–options] [param1] [param2] …

Short option use “-” Long option use “--”

Ex. dmesg gcc –v gcc ––help cp file1 file2

46

Page 47: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

File management

ls list ls –al

chmod change authority

-rw-r--r-- 1 root root 20 Sep 25 12:12 123.log

47

d : directoryl : soft-link- : filec : char deviceb : block device

owner

group

other

r w x222120

Ex. Chmod 755 file

-rwxr-xr-x

Page 48: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

rmdir remove directory mkdir make directory cp copy

cp from to mv move or rename

Move from to cd change directory

cd <absolute or relative path> cd – cd ..

48

Page 49: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

find -name find file find <where> –name <filename>

grep find string dmesg | grep CPU

cat print to stdout file print file info. touch change file’s timestamp make a file

49

Page 50: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

rm remove rm –rf <file or directory>

man command manual tar uncompress or compress

tar zxvf file.tar.gz tar zcvf backup.tar.gz /root tar jxvf file.tar.bz2

ln soft-link ln –s <file> <link_name>

50

Page 51: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Network

route setup or print route rule ping

ping -c 4 www.google.com.tw

ifconfig setup or print network ifconfig eth0 xxx.xxx.xxx.xxx

netstat show the network status netstat -l

51

Page 52: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

System

reboot shutdown –r

shutdown shutdown -h now

ps print process ps aux

kill terminate process kill <PID> killall <service_name>

52

Page 53: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

uname show system info. uname –r uname –a

free memory allocate state sync store memory buf. to disk

53

Page 54: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Vi Editor

vi filename

54

Page 55: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Visual Mode

yy copy a row

p paste a row

dd delete a row

55

Page 56: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Insert Mode

Input what you want

56

Page 57: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Command Mode

:wq save file and quit

:q! un-save and quit

:100 jump to 100th row

/<key> find [key] in this file press “n” to “Next”

57

Page 58: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Tips

Tab Command complement File complement

Up/Down Record command history

` <action> ` First to do Ex. ifconfig `cat net.conf`

net.conf eth0 x.x.x.x

58

Page 59: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

PRACTICE

59

Page 60: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

First program - Hello World ~!

touch test.c 新增一檔案

vi test.c 撰寫 code

gcc test.c –o test 編譯程式 gcc <source 檔名 > -o < 編譯後檔名 >

./test 執行程式

60

//test.c#include <stdio.h>

int main (int argc, char *argv[]) { printf("Hello world~!\n"); return 0;}

Page 61: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Homework

實現該 Linux 程式設計環境 , 並利用已有之程式碼編譯和執行出一簡單範例 程式碼請至課程網站 download

(helloworld_sock)

Report Format 作業描述 流程圖 執行結果 問題與討論 心得

61

Page 62: 1 Linux Programming Environment Setup. Outline  Introduce Linux  Install Linux on Vmware  在 Windows 下常用的 Software  Practice 2.

Submission 以一個學號命名之壓縮檔 ( 此報告 ) 於期限內

E-Mail 寄至助教信箱和繳交紙本給助教 鄭玴吉 : ES711: [email protected] 林宜鋒 : ES711: [email protected]

Deadline 2008/03/19 晚上 12 點前

若有疑問可至 ES711 詢問助教62