Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nassau Community College

Similar presentations


Presentation on theme: "Nassau Community College"— Presentation transcript:

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

2 Nassau Community College ITE153 – Operating Systems
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. Multiple processes must be able to access the information concurrently. Nassau Community College ITE153 – Operating Systems Fall 2011

3 Nassau Community College ITE153 – Operating Systems
File Systems (2) 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? Nassau Community College ITE153 – Operating Systems Fall 2011

4 File Naming Some typical file extensions.
Nassau Community College ITE153 – Operating Systems Fall 2011

5 File Attributes Some possible file attributes.
Nassau Community College ITE153 – Operating Systems Fall 2011

6 Nassau Community College ITE153 – Operating Systems
File Operations The most common system calls relating to files: Create Delete Open Close Read Write Append Seek Get Attributes Set Attributes Rename Nassau Community College ITE153 – Operating Systems Fall 2011

7 Nassau Community College
Fall 2011 Session 6 Files Systems: Hands-On Commands Nassau Community College ITE153 – Operating Systems Fall 2011 7 ITE153 - Operating Systems Management

8 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 Nassau Community College ITE153 – Operating Systems Fall 2011

9 Overview of Security Permissions
View existing permissions using ls -l $ ls -l drwxr-xr-x 2 cajs office 32 nov :33 DOCS - rw-r--r-- 1 cajs office 96 nov :12 abc Every file and directory has permission setting that control who can read, write or execute. This is an important feature in a mutli-user operating system. The ls command with the -l (long) option displays the existing permissions on a file or directory, along with other information associated with the file. From the example above: Nassau Community College ITE153 – Operating Systems Fall 2011

10 Nassau Community College ITE153 – Operating Systems
Permission Symbols Using ls output from the previous page, we can determine the significance of the permissions: drwxr-xr-x cajs office nov :33 DOCS The user (owner of the directory) can: List the contents of DOCS Add/delete files and directories to/from DOCS Change directory (cd) to DOCS The members of the group ‘office’ and others (anyone with a login on the system) can: Given the output below, what is the significance of the permissions for the file ‘abc’? -rwxr-xr-x cajs office nov :12 abc Nassau Community College ITE153 – Operating Systems Fall 2011

11 Changing Permisssions with chmod
chmod SETTING NAME(s) SETTING Symbolic or Octal notation Use symbols or octal numbers $ chmod g+w my.file $ chmod 664 my.file NAME(s) Name of file(s) or directory(s) There are two methods that change existing permissions. Both use the ‘change mode’ command. The symbolic method uses symbols in the setting field of the command. The octal method uses octal notation in the setting field of the command. Only the owner of the file or directory (AND the system administrator) can change the permissions. Nassau Community College ITE153 – Operating Systems Fall 2011

12 Nassau Community College ITE153 – Operating Systems
Symbolic Notation u user g group o other + add - subtract = set exactly r read w write x execute Symbolic setting examples u+r ugo+x g=r go+w ugo=rw g-w ug+w,o-r $ chmod setting filename(s) The setting in the symbolic method is composed of: The field you want to affect (user, group or other) The operation you want to perform (add, subtract or set exactly) The permission you want to turn on or off (read, write, execute) To change the permissions using the symbolic method, follow the following steps: 1. Determine the existing permissions using ls -l. 2. Decide on the new permission 3. Execute the chmod command with the correct setting 4. Use ls - l again to make sure that the new setting is correct. Nassau Community College ITE153 – Operating Systems Fall 2011

13 Practice Using Symbols
More Practice with Symbolic Notation What is the command line that would change the ‘before’ to ‘after’? Before After -rwxrwxrwx -rw-rw-rw- -r rw-r--r-- -rw-rw-r-- -rwxr-rx-x -rwxrwxr-- -r Nassau Community College ITE153 – Operating Systems Fall 2011

14 Nassau Community College ITE153 – Operating Systems
Octal Notation Common Octal Settings Directories 777 drwxrwxrwx 755 drwxr-xr-x 700 drwx------ Files 777 -rwxrwxrwx 644 -rw-r--r-- Shortcut Setting Value r 4 w 2 x 1 - 0 rwxrw-rw- is 766 rwx 4+2+1=7 rw =6 The Octal Method uses octal numbers translated from the binary code of ‘on’ (1) or ‘off’ (0). A permission is either on or off. If it is off, it is represented by a - (dash). If it is on, it is represented with an r, w, or x. So, we can translate the permission setting of rw-rw-r-- (664) from binary to octal: Permission On/Off Binary Octal rw- on, on, off 110 6 rw- on, on, off r- on, off, off 100 4 Rather that figuring this out every time, you can use the shortcut to add the values within each field: r has a value of 4 w has a value of 2 x has a value of 1 Nassau Community College ITE153 – Operating Systems Fall 2011

15 Nassau Community College ITE153 – Operating Systems
Practice With Octal More Practice with Octal Notation What is the command line that would change the ‘before’ to ‘after’? Before After -rwxrwxrwx -rw-rw-rw- -r rw-r--r-- -rw-rw-r-- -rwxr-rx-x -rwxrwxr-- -r Nassau Community College ITE153 – Operating Systems Fall 2011

16 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 Usually, a umask setting is created in your .profile. (A file that UNIX looks at when you log in.) It is rare that you will have change your umask setting. Nassau Community College ITE153 – Operating Systems Fall 2011

17 Nassau Community College ITE153 – Operating Systems
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 If you had a umask setting of 000 then: All new files would be created with a permission of -rw-rw-rw- All new directories would be created with a permission of drwxrwxrwx If you change your umask on the command line, it will only keep that setting until you log out. The change is session dependent. If you want to keep the change for all future session, you will need to make that change in your .profile. Later in the course, we will discuss how to make changes to your .profile. Look on the next page for some common umask settings. Nassau Community College ITE153 – Operating Systems Fall 2011

18 Nassau Community College ITE153 – Operating Systems
Common umask Settings Regardless of your umask setting, you can always use the chmod command to modify the permissions of the files and directories that you own. Nassau Community College ITE153 – Operating Systems Fall 2011

19 Nassau Community College
Fall 2011 Hands-on Exercises Nassau Community College ITE153 – Operating Systems Fall 2011 ITE153 - Operating Systems Management

20 Nassau Community College
Fall 2011 Session 6 vi Editor: Hands-On Commands Nassau Community College ITE153 – Operating Systems Fall 2011 20 ITE153 - Operating Systems Management

21 Nassau Community College ITE153 – Operating Systems
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 Nassau Community College ITE153 – Operating Systems Fall 2011

22 Nassau Community College ITE153 – Operating Systems
vi Overview With vi, you can: Create text Edit text Delete text Search for text Much more… vi is a text editor No automatic formatting Not a word processor There are many editors and word processing programs that work on UNIX systems. vi is the only editor that is available on all UNIX systems. Nassau Community College ITE153 – Operating Systems Fall 2011

23 Nassau Community College
Inventor of vi Editor Fall 2011 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 Nassau Community College ITE153 – Operating Systems Fall 2011 ITE153 - Operating Systems Management

24 Nassau Community College ITE153 – Operating Systems
vi Modes <esc> a, i, o... Input Command ex <enter> : $ vi has three modes. While you are in vi the functionality that is available to you, depends on what mode you are in. To enter vi, you type this at your shell prompt: $ vi filename If it is an existing file, vi will open it and put you into Command Mode with the cursor at the upper left of the screen. If the file does not exist, vi creates a new blank file and displays it on your screen. Command Mode When you enter vi, you are put in Command Mode. In this mode, you enter commands that move the cursor, search and more. From this mode, you can enter a command that will take you into Input Mode or ex Mode. Input Mode This mode is also called Append Mode in some documentation. Here, any text you enter will appear in the file. To return to Command Mode, press the escape key. (<esc>) ex Mode ex stands for ‘external’. In this mode you are entering commands that can affect the entire file. From ex Mode you can save your changes and return to Command Mode or exit vi and return to your shell prompt. $ vi filename Nassau Community College ITE153 – Operating Systems Fall 2011

25 Moving the Cursor: Little Moves
In Command Mode Moving by line: <enter> Moving by words: w W Moving by character: <space> <backspace> You can move by line, words, or character. Preceding most movement command with a number will multiply the action. For instance: 6w -Will move the cursor six words to the right. Nassau Community College ITE153 – Operating Systems Fall 2011

26 Moving the Cursor: Big Moves
In Command Mode Scroll up and down: <ctrl-u> <ctrl-d> Move within the screen: H home M middle L last Move to a specified line: 6G Move to line six G Move to the last line Where am I? <ctrl-g> In case you get a little lost, <ctrl-g> will tell you the line you are on and the name of the file you are editing. Nassau Community College ITE153 – Operating Systems Fall 2011

27 Nassau Community College ITE153 – Operating Systems
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 There are many input commands. All of them are relative to the position of the cursor. The commands listed above are: o (lower case) opens a line below the line the cursor is on O (upper case) opens a line above the line the cursor is on i inserts text before the cursor a appends text after the cursor As with all input commands, you must press <escape> to return to command mode. Nassau Community College ITE153 – Operating Systems Fall 2011

28 Nassau Community College ITE153 – Operating Systems
Changing Text Change word: cw Change 3 words: 3cw Change current line: cc The 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 When you type use vi’s change command, you will see that vi puts a $at the end of the word, group of words or line that you want changed. You change one word to fifty words. The change commands put you into input mode. You will stay there until you press <escape>. Nassau Community College ITE153 – Operating Systems Fall 2011

29 Nassau Community College ITE153 – Operating Systems
Deleting Text Delete word dw Delete 5 words 5dw Delete current line dd Delete current character x A number before the command multiplies the action. You can delete text by word, line or character. Using a number you can multiply the action. Nassau Community College ITE153 – Operating Systems Fall 2011

30 Nassau Community College ITE153 – Operating Systems
The Undo Command u Undo the last change U Restores the current line (Even after several changes.) I can delete two lines of text using 2dd. Then if I press ‘u’, the deleted lines will be returned to the file. However, if I deleted those lines one at a time using “dd” and then “dd” again, the undo command would only bring back the last line deleted. Nassau Community College ITE153 – Operating Systems Fall 2011

31 Nassau Community College ITE153 – Operating Systems
Searching for Text In command mode type: /pattern For 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 The / followed by text will perform a search from the current position of the cursor in a forward direction. The / command will wrap. But, if you want to search backwards in the file, use a ‘?’ instead of /. Nassau Community College ITE153 – Operating Systems Fall 2011

32 Nassau Community College ITE153 – Operating Systems
Copying & Moving Text To copy text use vi’s yank command: yw yanks (copies) one word yy yanks (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 When you delete or yank text, vi stores that text in something called the ‘Unnamed Buffer’. The p (put) command takes what ever is in that file and puts it back at the location of the cursor. Nassau Community College ITE153 – Operating Systems Fall 2011

33 Nassau Community College ITE153 – Operating Systems
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…. Most of the commands in ex Mode have an impact on the entire file. Nassau Community College ITE153 – Operating Systems Fall 2011

34 Nassau Community College ITE153 – Operating Systems
Save & Quit Write and quit vi :wq Write without quitting :w Quit without saving :q! Write to a new filename :w filename If you want to quit vi without saving any current changes, use: :q! The exclamation point forces the command. Without the exclamation point, vi will tell you that changes have been made to the file. Note: In UNIX, the exclamation point (!) is also known as a “bang”. Nassau Community College ITE153 – Operating Systems Fall 2011

35 Nassau Community College ITE153 – Operating Systems
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 There are a multitude of ways to perform a global substitution. The command line above is just one of those ways. In the first example: :1, $s/Monday/Friday/g We are telling vi that from line one [1] through the last line of the file [$], substitute [s] Monday with Friday and do it everywhere on the line [g] you find a Monday. If you omitted the g, the substitution would only work with the first ‘Monday ‘on any line. If a line contained two words ‘Monday’, only the first would be substituted with a ‘Friday’. For instance if you had the following lines: It has rained every Monday for the last few weeks. Monday’s are bad enough without rain. This Monday is no exception……. :1,$s/Monday/Friday Without a ‘g’ would make the following substitution: It has rained every Friday for the last few weeks. Friday’s are bad enough without rain. This Monday is Nassau Community College ITE153 – Operating Systems Fall 2011

36 Abbreviations :abbr UOS UNIX Operating System
When you type ‘UOS’ in input mode, vi will replace it with ‘UNIX Operating System’ Abbreviations can save you time when you are typing. However, they are session dependent. To keep abbreviations to all typing sessions, you must put them into a .exrc file (vi’s run control file).

37 Nassau Community College
Fall 2011 Hands-on Exercises Nassau Community College ITE153 – Operating Systems Fall 2011 ITE153 - Operating Systems Management

38 Nassau Community College
Fall 2011 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 Nassau Community College ITE153 – Operating Systems Fall 2011 ITE153 - Operating Systems Management

39 Nassau Community College
Homework Fall 2011 Review the Slides Keep Practicing Commands Compare to what you have learned on Linux to Windows Nassau Community College ITE153 – Operating Systems Fall 2011 ITE153 - Operating Systems Management


Download ppt "Nassau Community College"

Similar presentations


Ads by Google