Nassau Community College

Slides:



Advertisements
Similar presentations
In the last Session… ls -l command seven fields nine permissions of a file ls -ld file ownership file permissions (three-tiered file protection system)
Advertisements

CS 497C – Introduction to UNIX Lecture 8: The vi/vim Editor Chin-Chih Chang
Utilizing the GDB debugger to analyze programs Background and application.
A Guide to Unix Using Linux Fourth Edition
Editing with vi Or more fun than you thought you’d have without a mouse Prof. Chris GauthierDickey.
Program Development Tools IDE vs point tools Two tool flavors exist for developing embedded software: -IDEs: (Integrated Development Environments) i.e.,
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Vi Editor TA for ITIS3100: Xu Fei
Chapter 5 Editing Text Files
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Starting Vi Opening an existing file vi filename Creating a new file vi filename In your workshop directory, create a new file called mysong vi mysong.
CS465 - UNIX The vi Editor. Creating Files Most human-readable files on Unix are created with a text editor Unix has many, many different editors ed a.
CSCI 330 T HE UNIX S YSTEM Editing files. E DITOR C ONCEPTS Editing a file is to modify the content of a file Text editor: Enter and modify text in a.
Using Linux Text Editors. Use Non-Graphical Linux Text Editors Graphical Text Editor.
1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date:
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Chapter 3 Mastering Editors
Title Slide CSS 404/504 The UNIX Operating System (2) By Ralph B. Bisland, Jr.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
The UNIX development environment CS 400/600 – Data Structures.
T HE VI EDITOR. vi has 2 modes: command mode (initial or "default" mode) insert mode [Esc] is used to switch to command mode. In general, vi commands:
Software I: Utilities and Internals Lecture 2 – The vi Text Editor * Modified from Dr. Robert Siegfried original presentation.
Introduction to Vim Robbie CSCI2100 Data Structures Tutorial 3.
Intro. To Unix commands For those who’ve never used Unix before Quick tutorial to let you move around your Unix Accounts No discussion of inner workings.
Chapter8 The vi Editor. Introduction to vi u Modes of Operation u The Work Buffer  During the editing session, vi make all changes in the buffer  Advantage.
UNIX Intro vi  vi is the standard UNIX text editor v Contents 1.Why use vi ? 2. vi Basics 3.Moving Around 4.Inserting Text.
Text editors Why should I use an editor ? It is very important to able to use at least one text mode editor a text mode editor is so useful on remote machines.
Unix Editors. u Editors in Unix come in two general flavours: –modal editors have "modes" v generally input mode and command mode –input mode allows entry.
Tony Kombol.  Why text edit?  Many programs and features require configuration ▪ Configuration is kept in files ▪ Usually in the /etc directory  Changes.
Unix Session IV.
Text Editing February 2 nd, 2004 Class Meeting 3.
Unix Commands PowerPoint Presentation developed for LS 560 Information Technology online class - University of Alabama by Debey Sklenar TENacious Cohort.
1 of 47 Chapter 4: The vi Editor – First Look Copyright ©2008 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved.
Chapter Three Text Editing1 System Programming Text Editing.
Unix Environment Input Output 2  List Content (ls) ◦ ls (list current directory) ◦ ls –all (include hidden files/folders)  Make directory (mkdir) ◦
VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file.
Introduction to Unix (CA263) File Editing By Tariq Ibn Aziz.
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
Chapter Three The UNIX Editors.
Linux Class #03. File Access Permissions Types of users in Linux: Local User (u) Group User (g) Other User (o) Each User can have 3 types of permissions:
Isecur1ty training center Presented by : Eng. Mohammad Khreesha.
Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving Edited File Aborting Editing Session.
Agenda Using vi Editor Starting vi Session Command / Input Modes
Vi editor Pronounced: `vee eye‘’. Agenda Describe the background of vi Editor Use vi editor to: create text files edit text files Our Goal is to create.
Amir Afzal UNIX Unbounded, 5th Edition Copyright ©2008 Chapter 6: The vi Editor – Last Look 1 of 55 Copyright ©2008 by Pearson Education, Inc. Upper Saddle.
BIF703 FTP (File Transfer Protocol) Utility vi editor Utility.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 14 – UNIX vi text editor.
Purdue Linux Users Group Presents Linux 201: Session 1 Everything you ever wanted to do in VIM Thor Smith.
CS:414 introduction to Unix and Linux
SUSE Linux Enterprise Desktop Administration
Vim basics Vi IMproved.
Guide To UNIX Using Linux Third Edition
Vi Editor.
Unix Fundamentals - Part iii vi Editor
Vim.
Vi Introduction Tony Kombol.
Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
UNIT-2 Basic File Attributes Course code: 10CS44
Technical University of Kosice
Using Linux Commands Lab 3.
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
Multi-host Internet Access Portal (MIAP) Enhancement Guide
Web Programming Essentials:
Chapter 2 Basic vi Editor.
Linux Operations and Administration
The Emacs Editor Read: Forouzan, Appendix C
CSCI The UNIX System Editing files
In the last class… The vi basics command, input and ex mode
Presentation transcript:

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

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

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

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

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

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

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

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

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

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 2 cajs office 32 nov 27 2002 06: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 1 cajs office 96 nov 27 2002 14:12 abc Nassau Community College ITE153 – Operating Systems Fall 2011

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

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

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

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 4+2+0=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 110 6 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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