introduction to unix

50
UNIX OS Lecture I Simonas Kareiva Vilnius University Faculty of Mathematics and Informatics Preparation of the material was supported by the project „Increasing Internationality in Study Programs of the Department of Computer Science II“, project number VP1–2.2–ŠMM- 07-K-02-070, funded by The European Social Fund Agency and the Government of Lithuania.

Upload: simonas-kareiva

Post on 14-Aug-2015

73 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Introduction to UNIX

UNIX OS Lecture I

Simonas Kareiva

Vilnius University

Faculty of Mathematics and Informatics

Preparation of the material was supported by the project „Increasing Internationality in Study Programs of the Department of Computer Science II“, project number VP1–2.2–ŠMM-07-K-02-070, funded by The European Social Fund Agency and the Government of Lithuania.

Page 2: Introduction to UNIX

2

Page 3: Introduction to UNIX

3

Page 4: Introduction to UNIX

4

Page 5: Introduction to UNIX

5

Page 6: Introduction to UNIX

6

Page 7: Introduction to UNIX

7

Page 8: Introduction to UNIX

8

Page 9: Introduction to UNIX

9

Page 10: Introduction to UNIX

10

Page 11: Introduction to UNIX

11

Page 12: Introduction to UNIX

12

Page 13: Introduction to UNIX
Page 14: Introduction to UNIX

Sponsors

14

Page 15: Introduction to UNIX

Part 2History

Page 16: Introduction to UNIX

:)

16

Page 17: Introduction to UNIX

17

Page 18: Introduction to UNIX

Part 3Differences

Page 19: Introduction to UNIX

Differences

AIX FreeBSD HP-UX Linux Solaris Tru64

Hard Disk Device

/dev/hd4 /dev/ad0s1a /dev/vg00/lvol1 /dev/sda1 /dev/vx/dsk/rootvol /dev/rz0a

Home folder

/home /usr/home /home /home /export/home/dev/vx/dsk/home

?

Password files

/etc/passwd/etc/security/passwd

/etc/passwd/etc/master.passwd

/etc/passwd /tcb/files/auth/r/root

/etc/passwd /etc/shadow

/etc/passwd /etc/shadow

/etc/passwd

Maximum user ID

4294967295 65535 2147483647 65535 2147483647 65535

User creation

mkuser adduser Useradd useradd useradd useradd

Process supervision

monitor top glance top prstat top

Printing lines

/etc/qconfig /var/spool/print /etc/lp/interface/

/var/spool/lpd/lp/

/etc/lp/interfaces/ /usr/spool/lpd

Network configuration

lsattr -E -l inet0

/etc/rc.conf /etc/rc.config.d/netconf

/etc/sysconfig/network/

/etc/hostname.* /etc/inet/* /etc/defaultrouter

/etc/rc.config

Type of file system

jfs ufs vxfs ext2 vxfs advfs

Kernel /usr/lib/boot/unix_up

/boot/kernel/kernel

/stand/vmunix /boot/vmlinuz

/kernel/genunix /vmunix

Program installation

installp –a pkg_add swinstall rpm –I package

pkgadd setld -i

Printing file list

ls ls ls ls ls ls

19

Page 20: Introduction to UNIX

Directory layout - Windows

C:\C:\Users

C:\Users\Simonas C:\Users\Derpina

C:\Windows C:\Windows\System32

C:\Temp

D:\D:\MusicD:\Movies

20

Page 21: Introduction to UNIX

Directory structure - UNIX /

/bin/ /boot/ /dev/ /etc/ /home/ /lib/ /media/ /mnt/ /opt/ /proc/ /root/ /sbin/ /srv/ /tmp/ /usr/ /var/

21

Page 22: Introduction to UNIX

Directory structure - UNIX

/ /bin/ /boot/ /dev/ /etc/ /home/

/home/simonas/ /home/derpina/

/lib/ /media/ /mnt/ /opt/ /proc/ /root/ /sbin/ /srv/ …

22

Page 23: Introduction to UNIX

Directory structure - UNIX /

/bin/ /boot/ /dev/ /etc/ /home/ /lib/ /media/ /mnt/ /opt/ /proc/ /root/ /sbin/ /srv/ /tmp/ /usr/ /var/

23

Page 24: Introduction to UNIX

Directory structure - UNIX

/ … /mnt/ /opt/ /proc/ /root/ /sbin/ /srv/ /tmp/ /usr/

/usr/bin/ /usr/include/ /usr/lib/ /usr/sbin/ /usr/share/ /usr/src/

/var/

24

Page 25: Introduction to UNIX

Directory structure - UNIX /

/bin/ /boot/ /dev/ /etc/ /home/ /lib/ /media/ /mnt/ /opt/ /proc/ /root/ /sbin/ /srv/ /tmp/ /usr/ /var/

25

Page 26: Introduction to UNIX

Directory structure - UNIX

/ /bin/ /boot/ /dev/ /etc/ /home/ /lib/ /media/ /mnt/

/mnt/usb/ /mnt/win/

/mnt/win/Windows/ /opt/ /proc/ /root/ /sbin/ …

26

Page 27: Introduction to UNIX

Directory structure - UNIX

File Hierarchy Standard – FHS –describes the usual Linux and BSD OS directory layout

Not every UNIX OS follows this standard (for example, OS X has /Users, /Library, etc.)

On the other hand, different OS wouldn’t be different if they had the same hierarchy

For a moment, think of the software developers...

27

Page 28: Introduction to UNIX

Directory structure – live example #1# ls -l

total 22480

drwx------ 2 root root 512 May 3 2008 Mail

lrwxrwxrwx 1 root root 9 Feb 2 2008 bin -> ./usr/bin

-rw-r--r-- 1 root root 356221 Sep 28 2010 catalog

drwxr-xr-x 3 root root 512 May 23 2008 cdrom

drwxr-xr-x 2 root root 512 Nov 24 2010 cert

-rw------- 1 root root 10667463 Apr 4 12:15 core

drwxr-xr-x 16 root sys 4096 Sep 9 14:08 dev

drwxr-xr-x 2 root sys 512 Sep 9 14:05 devices

drwxr-xr-x 80 root sys 5120 Sep 10 20:23 etc

drwxr-xr-x 3 root sys 512 Feb 3 2011 export

dr-xr-xr-x 1 root root 1 Sep 9 14:07 home

drwxr-xr-x 14 root sys 512 Feb 2 2009 kernel

-rw------- 1 root root 636 Mar 22 2011 key

drwxr-xr-x 7 root bin 5120 Jul 24 18:07 lib

drwx------ 2 root root 8192 Feb 2 2009 lost+found

drwxr-xr-x 2 root sys 512 Feb 2 2009 mnt

dr-xr-xr-x 1 root root 1 Sep 9 14:07 net

drwxr-xr-x 13 root sys 512 Apr 20 2010 opt

-rw-r--r-- 1 root root 779 Aug 12 2007 partition.old

-rw-r--r-- 1 root root 66560 Aug 5 2011 pkg_get.pkg

drwxr-xr-x 39 root sys 1536 Mar 31 2011 platform

dr-xr-xr-x 100 root root 258752 Sep 10 20:45 proc

drwxr-xr-x 2 root sys 1024 Jul 24 15:21 sbin

-rw-r--r-- 1 root root 1325 Mar 31 2011 siginfo.h

drwxr-xr-x 4 root root 512 Feb 2 2006 system

-rw-r--r-- 1 root root 570 Mar 30 2006 test.c

drwxrwxrwx 6 root root 2048 May 20 16:05 tftpboot

drwxrwxrwt 6 root sys 733 Sep 10 20:45 tmp

drwxr-xr-x 41 root sys 1024 Jul 27 23:43 usr

drwxr-xr-x 47 root sys 1024 Jul 27 08:45 var

dr-xr-xr-x 6 root root 512 Sep 9 14:08 vol

28

Page 29: Introduction to UNIX

# ls -l

total 944

-rw-r--r-- 2 root wheel 786 Vas 24 2012 .cshrc

-rw-r--r-- 2 root wheel 253 Vas 24 2012 .profile

drwxrwxr-x 2 root operator 512 Kov 19 2012 .snap

-rw------- 1 root wheel 872448 Rgs 10 18:27 3dm2.core

-r--r--r-- 1 root wheel 6188 Vas 24 2012 COPYRIGHT

-rw-r--r-- 1 root wheel 78 Lap 6 2012 O

drwxr-xr-x 2 root wheel 1024 Kov 19 2012 bin

drwxr-xr-x 9 root wheel 512 Kov 26 2012 boot

drwxr-xr-x 2 root wheel 512 Kov 19 2012 cdrom

lrwxr-xr-x 1 root wheel 10 Kov 19 2012 compat -> usr/compat

dr-xr-xr-x 5 root wheel 512 Rgs 9 13:46 dev

drwxr-xr-x 2 root wheel 512 Kov 19 2012 dist

-rw------- 1 root wheel 4096 Bir 26 15:46 entropy

drwxr-xr-x 21 root wheel 2560 Rgs 9 10:46 etc

lrwxr-xr-x 1 root wheel 8 Kov 19 2012 home -> usr/home

drwxr-xr-x 3 root wheel 1536 Vas 24 2012 lib

drwxr-xr-x 2 root wheel 512 Kov 19 2012 libexec

drwxr-xr-x 2 root wheel 512 Vas 24 2012 media

drwxr-xr-x 4 root wheel 512 Rgs 9 11:19 mnt

dr-xr-xr-x 2 root wheel 512 Vas 24 2012 proc

drwxrwxrwx 15 root wheel 512 Lie 24 17:32 raid

drwxr-xr-x 2 root wheel 512 Bir 22 18:18 raid2

drwxr-xr-x 2 root wheel 2560 Kov 19 2012 rescue

drwxr-xr-x 8 root wheel 512 Rgp 4 16:55 root

drwxr-xr-x 2 root wheel 2560 Kov 19 2012 sbin

drwxr-xr-x 3 squid squid 11 Rgs 10 08:33 squid

lrwxrwxrwx 1 root wheel 11 Kov 19 2012 sys -> usr/src/sys

drwxrwxrwt 13 root wheel 1024 Rgs 10 13:18 tmp

drwxr-xr-x 21 root wheel 512 Rgs 10 13:15 usr

drwxr-xr-x 26 root wheel 512 Rgs 9 13:46 var

Directory structure – live example #1

29

Page 30: Introduction to UNIX

Part 4Userland

Page 31: Introduction to UNIX

???

linux login: _

31

Page 32: Introduction to UNIX

???

linux login: simonask_

32

Page 33: Introduction to UNIX

???

linux login: simonaskPassword: _

33

Page 34: Introduction to UNIX

???

linux login: simonaskPassword: Last login: Thu Sep 10 21:08:34 2012 from p1$ _

34

Page 35: Introduction to UNIX

???

linux login: simonaskPassword: Last login: Thu Sep 10 21:08:34 2012 from p1$ ls _

35

Page 36: Introduction to UNIX

???

linux login: simonaskPassword: Last login: Thu Sep 10 21:08:34 2012 from p1$ ls Maildir.tgz ports-supfileMaildir1.tgz public_htmldump.sh stable-supfile$ _

36

Page 37: Introduction to UNIX

???

linux login: simonaskPassword: Last login: Thu Sep 10 21:08:34 2012 from p1$ ls Maildir.tgz ports-supfileMaildir1.tgz public_htmldump.sh stable-supfile$ cd public_html _

37

Page 38: Introduction to UNIX

???

linux login: simonaskPassword: Last login: Thu Sep 10 21:08:34 2012 from p1$ ls Maildir.tgz ports-supfileMaildir1.tgz public_htmldump.sh stable-supfile$ cd public_html$ _

38

Page 39: Introduction to UNIX

???

linux login: simonaskPassword: Last login: Thu Sep 10 21:08:34 2012 from p1$ ls Maildir.tgz ports-supfileMaildir1.tgz public_htmldump.sh stable-supfile$ cd public_html$ ls –l _

39

Page 40: Introduction to UNIX

???

linux login: simonaskPassword: Last login: Thu Sep 10 21:08:34 2012 from p1$ ls Maildir.tgz ports-supfileMaildir1.tgz public_htmldump.sh stable-supfile$ cd public_html$ ls -l-rw-r--r-- 1 simonask adm 40 Lap 17 2006 index.html

$ _

40

Page 41: Introduction to UNIX

Simple example

$ cat > fileonetwo^D$ cat > script#!/bin/shwc –l $1^D$ chmod +x script $ ./script file 2 file$

41

Page 42: Introduction to UNIX

Some commands

ls – list folder contents ls –l – contents printed in wide format ls –a – hidden files/folders also displayed

cd – change directorypwd – print working directorydf –h – disk free space (human readable output)rm a.txt – remove a.txtmv a.txt b.txt – rename or move a.txt to b.txtcat a.txt – concatenate file contents to stdouttail a.txt – output last 10 lines of a.txt to stdouthead a.txt – output first 10 lines of a.txt to stdoutless a.txt – interactive file content viewer

(w/scrolling)vi a.txt – powerful text editor (edit file a.txt)

42

Page 43: Introduction to UNIX

Philosophy for non-philosophers

Small is beautiful.

Make each program do one thing well.

Build a prototype as soon as possible.

Choose portability over efficiency.

Store data in flat text files.

Use software leverage to your advantage.

Use shell scripts to increase leverage and portability.

Avoid captive user interfaces.

Make every program a filter.

43

Page 44: Introduction to UNIX

Some more philosophy

UNIX file system is an universal space

44

Page 45: Introduction to UNIX

Everything is file?

UNIX byte streams (files): Files and documents Folders, links Storage devices (discs, CD-ROMs, …) Interprocess communication (“pipes”,”sockets”,…) Network connections and terminals Other devices (printers, etc.)

You can handle them:Reading (read) Writing (write) Seeking (lseek) Closing (close)

45

Page 46: Introduction to UNIX

Everything is file?

Reading from file

Think, if there’s any difference, when you read a file which is stored in local filesystem…

… or on a network disk

… or streamed from a service through a pipe

… or being written on other user’s terminal

… or created in memory by other program, … ?

It doesn’t matter. You just read the file. Using same syscalls.

46

Page 47: Introduction to UNIX

Universal space

/usr/local/etc/

/home/simonask/unix.pdf

/mnt/cdrom/

/dev/ad0s1a

/tmp/mysql.sock

/dev/cuad0

/dev/ums0

47

Page 48: Introduction to UNIX

Universal space in Windows?

C:\Documents and Settings\Simonas K\

E:\autorun.inf

C:\autoexec.bat

CON ?

NUL

?!

???

:-(

48

Page 49: Introduction to UNIX

Pseudo-file systems

procfs – for process management and review

devfs – special files to access devices, …

tmpfs – temporary file system, SWAP

portalfs – a fs created by BSD, for example /p/tcp/mail.vu.lt/smtp

nullfs – allows to mount subdirectories of current FS in some other directories

sysfs – ???, http://en.wikipedia.org/wiki/Sysfs

49

Page 50: Introduction to UNIX

Competition

Life is hard

Thank you.

50