Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to...

21
Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 1 / 21

Transcript of Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to...

Page 1: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Introduction to Unix-like System

Macaca Li

National Taiwan University

2013/02/26

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 1 / 21

Page 2: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Who am I

All graduate students should be indoormen

B97902018/R01922001

Experience:Machine Learning TA (100-1)DSA TA (100-2)NASA TA (101-1)

Good at: Linear Algebra, Probability and Machine Learning

Poor at: Systems and Architectures

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 2 / 21

Page 3: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

What is 217 Workstation Lab

http://wslab.csie.ntu.edu.tw/

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 3 / 21

Page 4: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

How many OS you know

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 4 / 21

Page 5: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

What is UNIX

Compliant with and certified according to the Single UNIXSpecification

First developed in 1969, including

Ken ThompsonDennis RitchieBrian KernighanDouglas McIlroyMichael LeskJoe Ossanna

Multitasking and multi-user OS

Unix-like System

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 5 / 21

Page 6: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Dennis Ritchie

All computer science students should know him

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 6 / 21

Page 7: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Unix-like

BSDs

Linux

Mac OS

Solaris

Minix

SunOS

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 7 / 21

Page 8: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Linux-Kernel

Accessing hardwares

Provides the functions you would learn from OS-related courses

Can shed the parts you don’t need - Android

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 8 / 21

Page 9: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Distributions

Built on the kernel with many applications

Ubuntu, Debian, Fedora, CentOS, Redhat, SUSE, ... etc

(a) Ubuntu (b) Debian

(c) Fedora (d) SUSE

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 9 / 21

Page 10: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Why use UNIX

Stability

Performance

Security

Price

”Given enough eyeballs, all bugs are shallow.” - Linus

Question

Is UNIX a panacea ?

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 10 / 21

Page 11: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Logging to 217 workstation

All in http://wslab.csie.ntu.edu.tw/ssh/

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 11 / 21

Page 12: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Path

.

..

∼Absolute path

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 12 / 21

Page 13: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Basic Commands

File

cd

ls

mkdir

rm

mv

cp

find

pwd

Man

Manualratherthan guys

ex: man ls

man man(-k)

Textcat

more

less

tail

head

grep

diff

sort

wc

cut -d -f

vim

Others

whoami

who

ps aux

top

kill

alias

tar

awk

sed

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 13 / 21

Page 14: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Vim

Insert: i

Command: Esc

Save: :w

Exit: :q

vimtutor

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 14 / 21

Page 15: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Redirect the input and output

<

>

>>

Demos

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 15 / 21

Page 16: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Combos - Pipe

Combine multiple commands with I/O redirection

Example - list /bin

ls -al /bin | more

Exercise

How to find the arguments for recursive copying?

How many processes are running

How many users are logging

Ans: who | cut -d ’ ’ -f1 | uniq | wc -l

Who are logging in ascending order

Ans: who | cut -d ’ ’ -f1 | sort | uniq

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 16 / 21

Page 17: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

File Permissions

What is this

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 17 / 21

Page 18: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

File Permissions

r: read

w: write

x: execute

rwx rwx rwx (User Group Others)

chmod (be careful)

su, sudo

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 18 / 21

Page 19: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Shell Script

Combine more commands with more flexibilities

Scenerio1

You need to do a sequence of commands such as

mkdir test1

touch ./test1/doc1

touch ./test1/doc2

mkdir test2

touch ./test1/doc3

for 10 times ...

Scenerio2

You are a TA, you need to judge the students’ homeworks by

diff ID ans

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 19 / 21

Page 20: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Basic Structure

Learning by Examples

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 20 / 21

Page 21: Introduction to Unix-like System - 國立臺灣大學hsinmu/courses/_media/... · Introduction to Unix-like System Macaca Li National Taiwan University 2013/02/26 Macaca (National

Practice

df would list the usage of disks.

Please count the total used space.Note: Do not use df –total

Macaca (National Taiwan University) Intro. to UNIX 2013/02/26 21 / 21