t utorial l esson linux & tools

55
TUTORIAL LESSON Linux & Tools Institute of Parallel and Distributed System (iPads) Shanghai Jiao Tong University Rong Chen rongchen @ sjtu.edu.cn

Upload: dugan

Post on 23-Feb-2016

62 views

Category:

Documents


0 download

DESCRIPTION

Institute of Parallel and Distributed System (iPads) Shanghai Jiao Tong University Rong Chen rongchen @ sjtu.edu.cn. T UTORIAL L ESSON Linux & Tools. BIRTH of TUTORIAL LESSON. ICS introduces the Computer Systems, then W HO introduces ICS ? A new environment: Linux - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: T UTORIAL L ESSON Linux  &  Tools

TUTORIAL LESSONLinux & Tools

Institute of Parallel and Distributed System (iPads)Shanghai Jiao Tong University

Rong [email protected]

Page 2: T UTORIAL L ESSON Linux  &  Tools

BIRTH of TUTORIAL LESSON

ICS introduces the Computer Systems, then WHO introduces ICS ? A new environment: Linux Many new tools: svn, …

Institute of Parallel and Distributed System (iPads), SJTU 2

ICS Book does not contain them

Page 3: T UTORIAL L ESSON Linux  &  Tools

OUTLINE

3

Pre-requisiteLinuxTools

Page 4: T UTORIAL L ESSON Linux  &  Tools

Pre-requisiteLinux Tools

4

Page 5: T UTORIAL L ESSON Linux  &  Tools

TASKS

Labs (35%) 1: Bits 2: Bomb * 3: Y86 Assembler 4: Buffer

Overflow * 5: Y86 Compiler

* Online Test

5

Exams (60%) Middle Final

Homework (5%)

Institute of Parallel and Distributed System (iPads), SJTU

Page 6: T UTORIAL L ESSON Linux  &  Tools

HARD RULES

Deadline: No Extension Multiple submissions

Plagiarism: No Tolerance Forbid C&P and Typo

from Network from Classmates

Punishment 0 point for ALL

6Institute of Parallel and Distributed System (iPads), SJTU

Page 7: T UTORIAL L ESSON Linux  &  Tools

7

Cheating will not be tolerated …All homework, labs and exams are to be done individually.…It is your responsibility to ensure that your passwords are well-guarded, directories protected, and printouts do not fall into other hands.

Institute of Parallel and Distributed System (iPads), SJTU

Page 8: T UTORIAL L ESSON Linux  &  Tools

Pre-requisite

LinuxTools

Introduction Installation Shell

8

Page 9: T UTORIAL L ESSON Linux  &  Tools

BACKGROUND

The History of Linux Linus Torvalds, 1991 Unix-like Operating Systems

“ Unix is not so much an operating system as an oral history ”

Heirs: Linux, BSD, Solaris, MacOS X, …

Principle: KISS

9

Keep It Simple, Stupid !

Institute of Parallel and Distributed System (iPads), SJTU

Page 10: T UTORIAL L ESSON Linux  &  Tools

COMPARISON

Differences between Windows and Linux One Kernel and Multiple Distribution

2.6.x kernel (newest: 3.2.x) RedHat / Fedora, Debian Suse, Gentoo, Arch, Ubuntu, …

Powerful Command Line Interface Directories Organization …

10Institute of Parallel and Distributed System (iPads), SJTU

Page 11: T UTORIAL L ESSON Linux  &  Tools
Page 12: T UTORIAL L ESSON Linux  &  Tools

Pre-requisite

LinuxTools

Introduction

Installation Shell

12

Page 13: T UTORIAL L ESSON Linux  &  Tools

INSTALL

Step 0: How to find it ? SJTU Depository

ftp://ftp.sjtu.edu.cn/ e.g. Debian-6.03

/debian-cd/6.0.3/i386/iso-cd/

Online: get the official web-site by google

e.g. Debian (/'dɛbiːjən/, Debra + Ian) http://www.debian.org/distrib/

13

Tips: about version Fedora Sulphur(9), Cambridge(10) Debian (Toy Story) Lenny(5.0), Squeeze(6.0)

Institute of Parallel and Distributed System (iPads), SJTU

Page 14: T UTORIAL L ESSON Linux  &  Tools

INSTALL

Step 1: Where to install it ? Cygwin

Sorry, no technical support

on RAW machine Cool !

on VIRTUAL machine Safety!

14

Dangerous !

Recommendation !

Tips: virtual machine Definition provides a complete system platform which supports the execution of a complete operating system

Java Runtime Environment

Institute of Parallel and Distributed System (iPads), SJTU

Page 15: T UTORIAL L ESSON Linux  &  Tools

INSTALL

Step 2: Create VM Select a Guest Operating System

Debian 6 / Other Linux 2.6.x kernel Set name and location Network connection

Bridge (separate IP) or NAT (internal IP) Disk capacity

20G (engross on demand)

15

Tips: VMware Workstation Benefit hosted, popular, graphic easy, stable, checkpointed

Done !Institute of Parallel and Distributed System (iPads), SJTU

Page 16: T UTORIAL L ESSON Linux  &  Tools

INSTALL

Step 3: Configure VM Insert ISO image

“VM -> Settings -> CD-ROM : Use ISO Image”

ISO Image: “debian-6.0.3-i386-CD-1.iso” Configure Hardware

Memory Size #CPU / #Core Ethnet Mode

Power On

16

Let’s go !Institute of Parallel and Distributed System (iPads), SJTU

Page 17: T UTORIAL L ESSON Linux  &  Tools

17

Page 18: T UTORIAL L ESSON Linux  &  Tools

INSTALL

Step 4: Install Debian Select a language and your location Select a keyboard layout

U.S. English Configure the network

Hostname and Domain name Set root password and Create a User Configure the clock

Time Zone

18

Tips: VMware Workstation Switch Ctrl + Alt

Institute of Parallel and Distributed System (iPads), SJTU

Page 19: T UTORIAL L ESSON Linux  &  Tools

INSTALL

Step 4: Install Debian Partition disks

Manual Partitioning

1. _ swap 512M (equal to memory size) - sda2

2. / ext3 fill to maximum allowable size - sda1

19

Tips: hard Disk in Linux Naming: sd[x][y] sda 1 - the 1st section of 1st HD sdb3 - the 2nd section of 3rd HD

* sd: SCSI disk / hd: IDE disk

Page 20: T UTORIAL L ESSON Linux  &  Tools

INSTALL

Step 4: Install Debian Configure package manager

Use a Network mirror Hostname: ftp://ftp.sjtu.edu.cn Mirror directory: /debian/

Software selection Graphical desktop environment Standard System Utilities …

20

Tips: Desktop Environment GNOME /gə'noʊm/ from GNU Project KDE /'keidiː‘iː/ from Qt Software

as you like

Institute of Parallel and Distributed System (iPads), SJTU

Page 21: T UTORIAL L ESSON Linux  &  Tools

INSTALL

Step 4: Install Debian Install GRUB boot loader Waiting … Reboot … OK

21

Welcome to Debian 6 !

Institute of Parallel and Distributed System (iPads), SJTU

Page 22: T UTORIAL L ESSON Linux  &  Tools

22

Page 23: T UTORIAL L ESSON Linux  &  Tools

23

Page 24: T UTORIAL L ESSON Linux  &  Tools

APPENDIX: System Virtualization

Architecture

24

VM

Virtual Machine Monitor

Hardware(CPU, Memory, Disk, Ethernet)

Operating System

UnmodifiedUser Software

VM

Operating System

UnmodifiedUser Software

VM

Virtual Machine Monitor

Hardware(CPU, Memory, Disk, Ethernet)

Operating System

UnmodifiedUser Software

VM

Operating System

UnmodifiedUser Software

Host Operating System

Non-hosted Hosted Institute of Parallel and Distributed System (iPads), SJTU

Page 25: T UTORIAL L ESSON Linux  &  Tools

APPENDIX: System Virtualization

Virtual Machine Monitor VMware (EMC)

Player, Workstation, … Fusion, VMware Server, ESX Server, …

Other s Hyper-V (Virtual PC) xVM (VirtualBox) KVM, Xen …

25Institute of Parallel and Distributed System (iPads), SJTU

Page 26: T UTORIAL L ESSON Linux  &  Tools

APPENDIX: VMware Workstation

Snapshot (unsupported in VMware Player) Backup the whole computer

Don’t worry about system crash Trade of between storage and

computers

Files in VMware Workstation Configuration (.vmx) BIOS (.nvram)

Paging file (.vmem) Disk (.vmdk) Snapshot (.vmsn ) …

26Institute of Parallel and Distributed System (iPads), SJTU

Page 27: T UTORIAL L ESSON Linux  &  Tools

APPENDIX: VMware Workstation

Configuration Network

>setup select ‘network configuration’

>ping ftp.sjtu.edu.cn

Install VMware Tools click menu “VM -> Install VMware Tools” >cd /media/cdrom >tar zxf VMwareTools-8.1.3-203739.tar.gz ...

27Institute of Parallel and Distributed System (iPads), SJTU

Page 28: T UTORIAL L ESSON Linux  &  Tools

Pre-requisite

LinuxTools

IntroductionInstallation

Shell

28Institute of Parallel and Distributed System (iPads), SJTU

Page 29: T UTORIAL L ESSON Linux  &  Tools

SHELL

Operating System Shell Provide access to the services of a

kernel Command-Line Interface (CLI)

Unix Shell e.g. Bounce-Again Shell, bash

Non-Unix Shell e.g. DOS

Graphical User Interface (GUI) Windows, X Window (KDE, GNOME, Xfce),

Mac OS29

Institute of Parallel and Distributed System (iPads), SJTU

Page 30: T UTORIAL L ESSON Linux  &  Tools

30

Page 31: T UTORIAL L ESSON Linux  &  Tools

Commands

MOST IMPORTANT Search Path: /bin, /usr/bin, ... Command is case sensitive man – display the on-line manual pagese.g. >man man

whatis – search the whatis database for complete wordse.g. >whatis passwd

31Institute of Parallel and Distributed System (iPads), SJTU

Page 32: T UTORIAL L ESSON Linux  &  Tools

Commands

File and Directory ls - list files/dirs e.g. >ls -l mkdir – create a dir e.g. >mkdir test cd - change dir e.g. >cd test rm - remove files/dirs e.g. >rm -f a.txt cp - copy files/dirs e.g. >cp a.txt b.txt mv – move files/dir s e.g. >mv a.txt c.txt

pwd – show current path e.g. >pwd du – estimate files/dirs space usagee.g. >du -c -h test

df – report free disk spacee.g. >df

32Institute of Parallel and Distributed System (iPads), SJTU

Page 33: T UTORIAL L ESSON Linux  &  Tools

Commands

File and Directory chmod – change mode of file/dire.g. >chmod 777 test

chown – change owner of file/dire.g. >chown rong edit

chgrp – change group of file/dire.g. >chgrp guest draft -R

33

$ ls -l drwxr--r-- 1 peter admin 4096 Mar 1 2007 drafts -rw-r--r-- 1 peter admin 30405 Mar 1 2007 edition-32 -r-xr-xr-x 1 terry admin 8460 Mar 1 2007 edit duuugggooo C owner group size date name C:(hard link count)Institute of Parallel and Distributed System (iPads),

SJTU

Page 34: T UTORIAL L ESSON Linux  &  Tools

Commands

Search whereis - locate special files for a command (binary, src and manual file)e.g. >whereis cp

find – search for files/dirs in a dir hierarchye.g. >find . –name “c.txt”

locate – locate files/dirs by name in system based on a databasee.g. >locate test

grep – text search utilitye.g. >grep “abc” . -R

34Institute of Parallel and Distributed System (iPads), SJTU

Page 35: T UTORIAL L ESSON Linux  &  Tools

Commands

User Account useradd – create a new user e.g. >useradd rong

userdel – delete a user accounte.g. >userdel rong

passwd – set password for a user account based on a databasee.g. >passwd rong

users – print name of user currently loggede.g. >users

35Institute of Parallel and Distributed System (iPads), SJTU

Page 36: T UTORIAL L ESSON Linux  &  Tools

Commands

Text cat – concatenate and print files e.g. >cat b.txt

head – output the first part of filese.g. >head –n 4 b.txt

tail – output the last part of filese.g. >tail –c 50 b.txt

wc – print the number of newlines, words, and bytes in filese.g. >wc b.txt

cut – remove sections from each line of filese.g. >cut –c 4-10 b.txt

36Institute of Parallel and Distributed System (iPads), SJTU

Page 37: T UTORIAL L ESSON Linux  &  Tools

Commands

Misc echo – display a line of texte.g. >echo $PATH

mount – mount a file system e.g. >mount /dev/sda3 /mnt

umount – unmount a file systeme.g. >umount /mnt

ping – send ICMP ECHO_REQUEST to network hostse.g. >ping 10.132.143.100

date – print or set the system date and timee.g. >date "+%m/%d/%y“

time – time a simple commande.g. >time locate mapreduce

37Institute of Parallel and Distributed System (iPads), SJTU

Page 38: T UTORIAL L ESSON Linux  &  Tools

Commands

Misc ; – join two command in one linee.g. >echo $PATH; whereis echo

< > >> – redirect input and output e.g. >cat b.txt >> c.txt

| – pipe the former output as the later inpute.g. >cat b.txt | grep “abc”

& – do command in new processe.g. >cat b.txt &

38Institute of Parallel and Distributed System (iPads), SJTU

Page 39: T UTORIAL L ESSON Linux  &  Tools

Pre-requisiteLinuxTools

Software Installer Compressing and

Archiving Remote Login Text Editor

39

Page 40: T UTORIAL L ESSON Linux  &  Tools

VERSION CONTROL

APT (Advanced Package Tools) A management system for software

packages Package resource list for APT:

/etc/apt/sources.list

40

$ cat /etc/apt/source.list ... deb http://ftp.sjtu.edu.cn/debian/ squeeze main dbe-src http://ftp.sjtu.edu.cn/debian/ squeeze main type URI of source dist comp URI type: http, ftp, cdrom, file, ssh ...Institute of Parallel and Distributed System (iPads),

SJTU

Page 41: T UTORIAL L ESSON Linux  &  Tools

VERSION CONTROL

APT (Advanced Package Tools) apt-get: command-line tool

update e.g. >apt-get update install e.g. >apt-get install htop remove e.g. >apt-get remove htop upgrade e.g. >apt-get upgrade htop

apt-cache: cache manipulator search e.g. >apt-cache search htop showpkg e.g. >apt-cache showpkg htop

41Institute of Parallel and Distributed System (iPads), SJTU

Page 42: T UTORIAL L ESSON Linux  &  Tools

VERSION CONTROL

APT (Advanced Package Tools) example: install vim

>su root user >apt-get update update apt list >apt-cache search vim search in cache

>apt-get install vim install vim >man vim manual of vim

42

$ apt-cache search vim ... vim – Vi IMproved – enhanced vi editor vim-doc - Vi IMproved – HTML documentation ...Institute of Parallel and Distributed System (iPads),

SJTU

Page 43: T UTORIAL L ESSON Linux  &  Tools

Pre-requisiteLinuxToolsC LanguageLab

Software Installer Compressing and

Archiving Remote Login Text Editor

43

Page 44: T UTORIAL L ESSON Linux  &  Tools

COMPRESSING

GZIP (Gnu ZIP) gzip file format Compress just single file Replace the original file with .gz filee.g. >gzip test.txt >gunzio test.txt.gz

44Institute of Parallel and Distributed System (iPads), SJTU

Page 45: T UTORIAL L ESSON Linux  &  Tools

ARCHIVING

TAR (Tape ARchive) tar file format Suffix:

.tar e.g. >tar -cf src.tar src/ .tgz/.tar.gz e.g. >tar -zxf src.tar.gz .tbz/.tar.bz2 e.g. >tar -jcf src.tbz src/

45Institute of Parallel and Distributed System (iPads), SJTU

Page 46: T UTORIAL L ESSON Linux  &  Tools

ARCHIVING

CPIO (CoPy files In and Out archives) cpio file format Suffix:

.cpioe.g. >cpio -id < test.cpio

.cpgz / .cpio.gze.g. >find . –depth –print | cpio -o > x.cpio >gzip -9 x.cpio

* TAR vs CPIO: http://rightsock.com/~kjw/Ramblings/tar_v_cpio.html

46Institute of Parallel and Distributed System (iPads), SJTU

Page 47: T UTORIAL L ESSON Linux  &  Tools

Pre-requisiteLinuxToolsC LanguageLab

Software InstallerCompressing and Archiving

Remote Login Text Editor

47Institute of Parallel and Distributed System (iPads), SJTU

Page 48: T UTORIAL L ESSON Linux  &  Tools

REMOTE LOGIN

Telnet (Teletype network) A network protocol over TCP for remote

access Birth in 1969, and supported by various

OSes Including Windows

e.g. >telnet bbs.fudan.edu.cn >telnet 10.132.143.112

48Institute of Parallel and Distributed System (iPads), SJTU

Page 49: T UTORIAL L ESSON Linux  &  Tools

REMOTE LOGIN

SSH (Secure SHell) A Replacement for Telnet

Communication through a secure channel Tatu Ylönen, 1995 OpenSSH (OpenBSD Secure Shell), 1999

e.g. >ssh -l root 10.132.143.112

SCP, A Replacement for FTP e.g. >scp b.txt [email protected]:~/test/ >scp [email protected]:~/test/b.txt ./

49Institute of Parallel and Distributed System (iPads), SJTU

Page 50: T UTORIAL L ESSON Linux  &  Tools

REMOTE LOGIN

Remote Login from Windows Command-Line Interface

PuTTY act as a client for SSH and Telnet Developed by Microsoft

Graphical User Interface VNC (Virtual Network Client)

Platform Independent Client-Sever Model

50Institute of Parallel and Distributed System (iPads), SJTU

Page 51: T UTORIAL L ESSON Linux  &  Tools

Pre-requisiteLinuxToolsC LanguageLab

Software InstallerCompressing and ArchivingRemote Login

Text Editor

51

Page 52: T UTORIAL L ESSON Linux  &  Tools

TEXT EDITOR

vi (Visual Editor) /'viː'ai/, not /'siks/ Extension: vim, vile, xvi, … Simple and Convenient BOOK: “learning the vi editor”

http://www.china-pub.com/computers/common/info.asp?id=9208

Cheat Sheet (Chinese version) http://jserv.sayya.org/misc/vi-vim-cheat-sheet.png

“>vimtutor” to get a simple tutorial52

Institute of Parallel and Distributed System (iPads), SJTU

Page 53: T UTORIAL L ESSON Linux  &  Tools

TEXT EDITOR

Emacs (Editing MACroS) /'imæks/ More powerful than IDE !

Emacs List BOOK: “Learning GNU Emacs”

http://www.china-pub.com/computers/common/info.asp?id=13395

53Institute of Parallel and Distributed System (iPads), SJTU

Page 54: T UTORIAL L ESSON Linux  &  Tools

54

Thanks

Page 55: T UTORIAL L ESSON Linux  &  Tools

Tutorial-1 (Spring 2012)

Rooms 5103: 5100309118 ~ 5110379048 TA: LYC & HJ

5120: 5110379049 ~ 5110379104 TA: CL & MSD

Tasks Install Linux Shell http://

ipads.se.sjtu.edu.cn/courses/ics/tutorials/shell.html

55Institute of Parallel and Distributed System (iPads), SJTU