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

Post on 04-Jan-2016

212 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

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.

• 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.

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.

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.

Formatting a floppy

• Physical formatting:– writing tracks – writing sectors

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

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

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.

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

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.

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.

Listing files

• ls lists files

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

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

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…

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.

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

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.

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

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

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

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

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

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

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

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 .

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

http://openlib.org/home/krichel

Thank you for your attention!

top related