39
Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 6 Files Systems: Hands-On

Session 6 Files Systems: Hands-On

  • Upload
    jaxon

  • View
    28

  • Download
    0

Embed Size (px)

DESCRIPTION

Session 6 Files Systems: Hands-On. File Systems (1). Essential requirements for long-term information storage: It must be possible to store a very large amount of information . The information must survive the termination of the process using it. - PowerPoint PPT Presentation

Citation preview

Page 1: Session 6 Files Systems: Hands-On

Fall 2011Nassau Community College ITE153 – Operating Systems 1

Session 6Files Systems: Hands-On

Page 2: Session 6 Files Systems: Hands-On

• Essential requirements for long-term information storage: It must be possible to store a very large

amount of information. The information must survive the

termination of the process using it. Multiple processes must be able to access

the information concurrently.

File Systems (1)

Nassau Community College ITE153 – Operating SystemsFall 2011 2

Page 3: Session 6 Files Systems: Hands-On

• Think of a disk as a linear sequence of fixed-size blocks and supporting reading and writing of blocks. Questions that quickly arise: How do you find information? How do you keep one user from reading

another’s data? How do you know which blocks are free?

File Systems (2)

Nassau Community College ITE153 – Operating SystemsFall 2011 3

Page 4: Session 6 Files Systems: Hands-On

Some typical file extensions.

File Naming

Fall 2011 4Nassau Community College ITE153 – Operating Systems

Page 5: Session 6 Files Systems: Hands-On

Some possible file attributes.

File Attributes

Nassau Community College ITE153 – Operating SystemsFall 2011 5

Page 6: Session 6 Files Systems: Hands-On

The most common system calls relating to files:

File Operations

• Append• Seek• Get Attributes• Set Attributes• Rename

• Create• Delete• Open • Close• Read• Write

Nassau Community College ITE153 – Operating SystemsFall 2011 6

Page 7: Session 6 Files Systems: Hands-On

Fall 2011Nassau Community College ITE153 – Operating Systems 7

Session 6Files Systems:

Hands-On Commands

Page 8: Session 6 Files Systems: Hands-On

File & Directory Permissions

Unit Objectives:

By the end of this unit, you will be able to:

• Use the ls command to determine existing permissions on files and directories

• Describe the significance of permission settings

• Change permissions using the chmod command

• Determine default permissions for new files and directories

• Change the default permissions for new files and directories

Fall 2011 8Nassau Community College ITE153 – Operating Systems

Page 9: Session 6 Files Systems: Hands-On

Overview of Security Permissions

• View existing permissions using ls -l $ ls -l

drwxr-xr-x 2 cajs office 32 nov 27 2002 06:33 DOCS

- rw-r--r-- 1 cajs office 96 nov 27 2002 14:12 abc

d rwx r-x r-x

- rw- r-- r--

Directory orfile

User/owner

User’sGroup

Others

Fall 2011 9Nassau Community College ITE153 – Operating Systems

Page 10: Session 6 Files Systems: Hands-On

Permission Symbols

Readr

Writew

Executex

Directory List Add/deletefiles

ChangeDirectory

File DisplayContents

Edit Use ascommand

Fall 2011 10Nassau Community College ITE153 – Operating Systems

Page 11: Session 6 Files Systems: Hands-On

Changing Permisssions with chmod

chmod SETTING NAME(s)• SETTING

Symbolic or Octal notationUse symbols or octal numbers

$ chmod g+w my.file $ chmod 664 my.file

• NAME(s) Name of file(s) or directory(s)

Fall 2011 11Nassau Community College ITE153 – Operating Systems

Page 12: Session 6 Files Systems: Hands-On

Symbolic Notation

u userg groupo other+ add- subtract= set

exactlyr readw writex execute

Symbolic setting examplesu+rugo+xg=rgo+wugo=rwg-wug+w,o-r

$ chmod setting filename(s)

Fall 2011 12Nassau Community College ITE153 – Operating Systems

Page 13: Session 6 Files Systems: Hands-On

Practice Using Symbols

Before Command Line After

drwxrw---- chmod o+r dirName ?

-rw-rw-rw- ? -rwxrwxrwx

-r--r--r-- chmod ug+w,o-r fileName

?

drwx------ ? drwxrwx---

Fall 2011 13Nassau Community College ITE153 – Operating Systems

Page 14: Session 6 Files Systems: Hands-On

Octal Notation

Common Octal Settings

Directories

777 drwxrwxrwx755 drwxr-xr-x700 drwx------Files

777 -rwxrwxrwx644 -rw-r--r--

ShortcutSetting Value

r 4

w 2

x 1

- 0

rwxrw-rw- is 766

rwx 4+2+1=7

rw 4+2+0=6

rw 4+2+0=6

Fall 2011 14Nassau Community College ITE153 – Operating Systems

Page 15: Session 6 Files Systems: Hands-On

Practice With Octal

Before Command Line After

drwxrw---- chmod 766 DirName ?

-rw-rw-rw- ? -rwxrwxrwx

-r--r--r-- chmod 660 fileName ?

drwx------ ? drwxrwx---

Before Command Line After

drwxrw---- chmod 766 DirName ?

-rw-rw-rw- ? -rwxrwxrwx

-r--r--r-- chmod 660 fileName ?

drwx------ ? drwxrwx---

Fall 2011 15Nassau Community College ITE153 – Operating Systems

Page 16: Session 6 Files Systems: Hands-On

Default File & Directory Permissions

• The chmod command changes EXISTING file or directory permissions.

• DEFAULT permissions Used when new files or directories are

created• For files: 666• For directories: 777

Default can be modified using the umask command

Fall 2011 16Nassau Community College ITE153 – Operating Systems

Page 17: Session 6 Files Systems: Hands-On

umask Settings

• umask uses Octal notation• To determine existing umask setting:$ umask

• To change umask setting:$ umask 022

• File default becomes: -rw-r--r--• Directory default becomes: drwxr-xr-

x

Fall 2011 17Nassau Community College ITE153 – Operating Systems

Page 18: Session 6 Files Systems: Hands-On

Common umask Settings

umask Setting

Directory File

022 drwxr-xr-x -rw-r--r--

037 drwxr--r-- -rw-r-----

002 drwxrwxr-x -rw-rw-r--

umask Setting

Directory File

022 drwxr-xr-x -rw-r--r--

037 drwxr--r-- -rw-r-----

002 drwxrwxr-x -rw-rw-r--

Fall 2011 18Nassau Community College ITE153 – Operating Systems

Page 19: Session 6 Files Systems: Hands-On

Hands-onExercises

Fall 2011Nassau Community College ITE153 – Operating Systems 19

Page 20: Session 6 Files Systems: Hands-On

Fall 2011Nassau Community College ITE153 – Operating Systems 20

Session 6vi Editor:

Hands-On Commands

Page 21: Session 6 Files Systems: Hands-On

Basics of the vi Editor

By the end of this unit, you will be able to:

• Describe the features of a text editor

• List the modes of the vi editor

• Use commands to move around a text file

• Use input commands to enter text

• Perform a global substitution

• Escape to the shell

• Create an abbreviation

• Save your file

• Exit the vi editor

Fall 2011 21Nassau Community College ITE153 – Operating Systems

Page 22: Session 6 Files Systems: Hands-On

vi Overview

• vi is a text editor• No automatic

formatting• Not a word

processor

With vi, you can: Create text Edit text Delete text Search for text Much more…

Fall 2011 22Nassau Community College ITE153 – Operating Systems

Page 23: Session 6 Files Systems: Hands-On

Inventor of vi Editor

• wrote the vi editor in a weekend, 1976

• largely responsible for managing the authorship of BSD UNIX

• co-founded Sun Microsystems in 1982

• lives in Aspen

Fall 2011Nassau Community College ITE153 – Operating Systems 23

Page 24: Session 6 Files Systems: Hands-On

vi Modes

$ vi filename

$

<esc>

a, i, o...

Input

Command

ex

<enter>

:Fall 2011 24

Nassau Community College ITE153 – Operating Systems

Page 25: Session 6 Files Systems: Hands-On

Moving the Cursor: Little Moves

In Command Mode

• Moving by line:<enter>

• Moving by words:w W

• Moving by character:<space><backspace>

Fall 2011 25Nassau Community College ITE153 – Operating Systems

Page 26: Session 6 Files Systems: Hands-On

Moving the Cursor: Big Moves

In Command Mode• Scroll up and

down:<ctrl-u><ctrl-d>

• Move within the screen:H homeM middleL last

• Move to a specified line:6G Move to line sixG Move to the last line

• Where am I?<ctrl-g>

Fall 2011 26Nassau Community College ITE153 – Operating Systems

Page 27: Session 6 Files Systems: Hands-On

Entering Text

In Command Mode• Type an Input

command (i,a,o,O)

• Type the text you want to enter

• Press <esc> to return to Command Mode

Input commands are relative to the cursor:

O

i a

o

Fall 2011 27Nassau Community College ITE153 – Operating Systems

Page 28: Session 6 Files Systems: Hands-On

Changing Text

• Change word: cw• Change 3 words: 3cw• Change current line: ccThe change command:

Displays a $ at the end of the word(s) or line to be changed

Puts you into input mode Use <esc> to return to command mode A number before the command multiplies

the action

Fall 2011 28Nassau Community College ITE153 – Operating Systems

Page 29: Session 6 Files Systems: Hands-On

Deleting Text

• Delete word dw• Delete 5 words 5dw• Delete current line dd• Delete current characterx• A number before the command

multiplies the action.

Fall 2011 29Nassau Community College ITE153 – Operating Systems

Page 30: Session 6 Files Systems: Hands-On

The Undo Command

• u Undo the last change• U Restores the current line

(Even after several changes.)

Fall 2011 30Nassau Community College ITE153 – Operating Systems

Page 31: Session 6 Files Systems: Hands-On

Searching for Text

• In command mode type: /patternFor example: /edit

• Searches forward in the file for the pattern ‘edit’.

• Puts cursor on the ‘e’ in the first instance found

• Type n (for next) to go to the next instance

Fall 2011 31Nassau Community College ITE153 – Operating Systems

Page 32: Session 6 Files Systems: Hands-On

Copying & Moving Text

• To copy text use vi’s yank command:• ywyanks (copies) one word• yyyanks (copies) one line• To move text use any of vi’s delete

commands like dd, dw, x• To paste:p puts copied or deleted text back at the cursor

Fall 2011 32Nassau Community College ITE153 – Operating Systems

Page 33: Session 6 Files Systems: Hands-On

ex Mode

• From command mode a : (colon) puts you in ex mode

• Some tasks in ex mode:• save(write) and quit (example: :wq!)

• make global changes• create abbreviations• customize vi• many more….

Fall 2011 33Nassau Community College ITE153 – Operating Systems

Page 34: Session 6 Files Systems: Hands-On

Save & Quit

• Write and quit vi :wq• Write without quitting :w• Quit without saving :q!• Write to a new filename :w filename

Fall 2011 34Nassau Community College ITE153 – Operating Systems

Page 35: Session 6 Files Systems: Hands-On

Global Substitutions

• In ex mode - :[address]s/pattern/replacement/[g]

• Examples::1, $s/Monday/Friday/g:.,10s/his/hers/g:18s/lunch/dinner:1,.s/rabbits/bunnies/g

Fall 2011 35Nassau Community College ITE153 – Operating Systems

Page 36: Session 6 Files Systems: Hands-On

Abbreviations

• :abbr UOS UNIX Operating System

• When you type ‘UOS’ in input mode, vi will replace it with ‘UNIX Operating System’

Page 37: Session 6 Files Systems: Hands-On

Hands-onExercises

Fall 2011Nassau Community College ITE153 – Operating Systems 37

Page 38: Session 6 Files Systems: Hands-On

Important URLs

How Linux file permissions work - a little more info about file permissions

What is Umask and How To Setup Default umask Under Linux? – good explanation of umask command

Access Rights and File Security – good write-up on file security

The vi Editor (Wikipedia) – very good history of vi Learning the vi Editor, Sixth Edition - this is the online

(free) version

Fall 2011Nassau Community College ITE153 – Operating Systems 38

Page 39: Session 6 Files Systems: Hands-On

Homework

Review the Slides Keep Practicing Commands Compare to what you have learned

on Linux to Windows

Fall 2011Nassau Community College ITE153 – Operating Systems 39