itr3 lecture 6: intoduction to unix

27
ITR3 lecture 6: intoduction to UNIX Thomas Krichel 2002-10-21

Upload: ryo

Post on 05-Jan-2016

25 views

Category:

Documents


0 download

DESCRIPTION

ITR3 lecture 6: intoduction to UNIX. Thomas Krichel 2002-10-21. Today we have fun with. Disks Unix basics Important unix utilities. Files, directories and links. Files are continuous chunks data on disks that are required for software applications. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: ITR3 lecture 6:  intoduction to UNIX

ITR3 lecture 6: intoduction to UNIX

Thomas Krichel

2002-10-21

Page 2: ITR3 lecture 6:  intoduction to UNIX

Today we have fun with

• Disks

• Unix basics

• Important unix utilities

Page 3: ITR3 lecture 6:  intoduction to UNIX

Files, directories and links

• Files are continuous chunks data on disks that are required for software applications.

• Directories are files that contain other files. Microsoft calls them folders.

• A link is a file that contain the address of another file. Microsoft call it a shortcut.

Page 4: ITR3 lecture 6:  intoduction to UNIX

Structure of a disk

• Disks are round devices divided into tracks and sectors.

• A hard disk may have several physical disks.

• Sector is 571 bytes long– 512 bytes are used by the user– The rest is reserved for disk operation

• The disk spins, a head reads and writes data.

Page 5: ITR3 lecture 6:  intoduction to UNIX

Data integrity

• The special data in each sector is kept there to try ensure that the user data is safe.

• It contains a summary of the user data.• When the summary and the user data no

longer match, the summary can be used to correct the user data.

• SMART disks are those that can monitor if they are a in good shape.

Page 6: ITR3 lecture 6:  intoduction to UNIX

Formatting a floppy

• Physical formatting:– writing tracks – writing sectors

• Logical formatting:– labeling each sector– create boot record– create file allocation table (FAT)

Page 7: ITR3 lecture 6:  intoduction to UNIX

Formatting a hard disk

• That is the same as formatting a floppy but• Between physical and logical formatting, the

hard disk may be partitioned.• This allows for several logical disks on the same

physical disk• Therefore the boot record is more complicated

than on the floppy and called a master boot record MBR.

• Example: dual boot Linux/Windows machine

Page 8: ITR3 lecture 6:  intoduction to UNIX

Unix file conventions

• In UNIX the root directory is “/”.

• “/” is the directory separator.

• A number of special files in “/dev” represent devices.

• Each device is “mounted” as a subdirectory of the root directory. Example

mount /dev/fd0 /floppy

• You need to be root to do this.

Page 9: ITR3 lecture 6:  intoduction to UNIX

Device names

• /dev/fd0 first floppy drive • /dev/fd1 second floppy• /dev/sda first SCSI disk • /dev/sdb second SCSI disk • /dev/scd0 first SCSI CD-ROM • /dev/hda master disk on IDE primary controller • /dev/hdb slave disk on IDE primary controller • /dev/hdc master disk on IDE secondary

controller • /dev/hdd slave disk on IDE secondary

controller

Page 10: ITR3 lecture 6:  intoduction to UNIX

Root user

• “root” is the user name of the superuser.

• The superuser has all priviledges.

• Most of the time, you should not work as the superuser, but use your own private account.

Page 11: ITR3 lecture 6:  intoduction to UNIX

Permission model

• Permission of files are give to the owner, the group, and the rest of the world.

• A group is a grouping of users. Unix allows to define any number of groups and make users a member of it.

• The rest of the world are all other users who have access to the system.

Page 12: ITR3 lecture 6:  intoduction to UNIX

Listing files

• ls lists files

• ls –l make a long listing. It contains– Date– Owner– Group– Size– permission

Page 13: ITR3 lecture 6:  intoduction to UNIX

First element in ls -l

• Type indicator– d means directory– l means link– - means ordinary file

• 3 letters for permission of owner• 3 letters for permission of group• 3 letters for permission of rest of the world• r means read, w means write, x means

execute

Page 14: ITR3 lecture 6:  intoduction to UNIX

Change permission: chmod

A permission is a number– 4 is read– 2 is write– 1 is excute

• Permissons are three numbers, for owner, group and rest of the world.

• Example: chmod 764 file• Directories need to be executable to get in

them…

Page 15: ITR3 lecture 6:  intoduction to UNIX

Change owner and group

• chown user file

• chgrp group file

• Usually you need to be root to do this.

• Add users with adduser, follow instructions.

• userdel rids you of an annoying user.

Page 16: ITR3 lecture 6:  intoduction to UNIX

shell

• The shell is a command line interpreter.• When you login, a shell is started for you.• Shells include

– Bourne shell sh -- Korn shell ksh– C shell csh -- extended C shell tcsh– Bourne again shell bash – z shell zsh

• The default shell will be bash, which is linked to the default place where the shell is found, /bin/sh

Page 17: ITR3 lecture 6:  intoduction to UNIX

General structure of commands

• commandname –flag --option

• Where commandname is a name of a command

• Flag can be a letter

• Several letters set several flags or form an option

• An option can also be expressed with - - and a word.

Page 18: ITR3 lecture 6:  intoduction to UNIX

Bash features

• cd is a command to change directory

• File names and command names can be completed with TAB

• The command history can be activated with the arrow keys of the keyboard

• Environment variables can be completed

• So login now

Page 19: ITR3 lecture 6:  intoduction to UNIX

Environment variables

• Are variable that the shell knows about.

• Env lists all of them– PATH, where the executable files are

searched– EDITOR, the default editor– PS1, the primary prompt– HOME, the home directory

Page 20: ITR3 lecture 6:  intoduction to UNIX

Setting and showing them

• LWORD=library– Set lword to be library

• export LWORD– Make it visible to the shell

• echo $LWORD– Show the value.

• Other examplePATH=$PATH:$HOME/bin

Page 21: ITR3 lecture 6:  intoduction to UNIX

Copying and removing

• cp file copyfile

• scp user@machine:file user@machine:file– User is a user– Machine is a machine– File is the path to a file – Of course you will need permissions here!

• rm file there is no recycling bin!!

-r flag copies and deletes recursively

Page 22: ITR3 lecture 6:  intoduction to UNIX

Directories and files

• mkdir file makes a directory• rmdir file removes it• touch file

– makes a new empty file– sets the time on an existing file

• more file– Pages contents of file, no way back

• less file – Pages contents of file, “u” to go back, “q” to quit

Page 23: ITR3 lecture 6:  intoduction to UNIX

Important programs

• echo, shows argument on the screen• cat file, shows file on the screen• who, shows who is logged in• top, shows processes• ln –s file1 file2 create a link form file2 to file1.

pretty confusing • man command shows manual for command• man –k term looks for commands with the

keyword term

Page 24: ITR3 lecture 6:  intoduction to UNIX

grep

• Looks up an expression in a file

• Syntax is one of simple regular expressions

• READ the man page for this command. This is an important reading and will be part of the quiz after the installation

Page 25: ITR3 lecture 6:  intoduction to UNIX

kill

• Sends signal to a process.

• You need to know the number of the process, you can do that with ps

• Signal ‘9’ will kill the process

• Signal HUP will hang up the process, it will read its configuration file again .

Page 26: ITR3 lecture 6:  intoduction to UNIX

find

• Finds files

• Has a –exec flag that allows you to execute programs on the files found.

• READ the man page for this command. This is an important reading and will be part of the quiz after the installation

Page 27: ITR3 lecture 6:  intoduction to UNIX

http://openlib.org/home/krichel

Thank you for your attention!