Introduction to Operating Systems

Introduction to Operating Systems

Outline Working with files and directories Working with file editor pico To be done by the next class Assignment 1. 05/24/11 unix-lect02-file1.pdf 1 Review: Major Components of the Unix OS Kernel The master control program to control both hardware and software Schedules tasks and provides multitasking and multi-user operations Manages resources Shell Interprets user commands Passes user commands to the kernel for execution (executes programs) File System Information organized as files and directories (special files) Utilities Software tools provided as part of the OS 05/24/11 unix-lect02-file1.pdf 2 Review: Syntax of UNIX Command Lines A UNIX command may have arguments, which can be an option or a filename The general format for UNIX command line is command option(s) filename(s) A command is typically in lowercase Options modify the way in which a command works Options are often single letters prefixed with a dash Some of options can be made from complete words There are also special characters (such ‘>’, ‘<‘, ‘&’, ‘|’) 05/24/11 unix-lect02-file1.pdf 3 Files The most common entity users manipulate (directly or indirectly) is files (and directories) Files A well defined repository of information saved on a storage device Program or component of a program Arbitrary text An executable (binary text) A UNIX operating system itself consists of a set of files and directories 05/24/11 unix-lect02-file1.pdf 4 File Examples The linux operating system on shell.cs.fsu.edu is saved in files -rw-r--r-- 1 root root 1401588 Jun 9 2005 /boot/vmlinuz-2.6.9-11.ELsmp -rw-r--r-- 1 root root 390536 Jul 11 2005 /boot/initrd-2.6.9-11.ELsmp.img The tcsh shell program is a file -rwxr-xr-x 1 root root 307488 Feb 17 2005 /bin/tcsh The cpuinfo of shell.cs.fsu.edu is a file -r--r--r-- 1 root root 0 Jan 8 17:17 /proc/cpuinfo The usernames and their information are saved in a file -rw-r--r-- 1 root root 1473 Dec 22 2005 /etc/passwd The information about the file systems is a file -rw-r--r-- 1 root root 1212 Sep 8 15:37 /etc/fstab 05/24/11 unix-lect02-file1.pdf 5 Directories Special files called directories contain pointers to other files In other words, a directory is a file that contains a list of files and subdirectories A directory is changed when a file name is changed or a file is deleted Structure of directories Hierarchically structured like an inverted tree / is the starting directory or “root” 05/24/11 unix-lect02-file1.pdf 6 Example Set of Directories and Files / bin home etc tcsh majors grads faculty fstab … nienaber … … research teaching … vision cop3353 … notes homework 05/24/11 unix-lect02-file1.pdf 7 unix-lect01-intro.ppt unix-lect02-file1.ppt Identifying Files and Directories Pathnames Identifying a file by following a sequence of directories until you reach the file/directory / is also the separator among the subdirectories and final file Examples /bin/tcsh /etc/fstab /home/grads/nienaber/teaching/cop3353/notes/unix-lect02- file1.ppt 05/24/11 unix-lect02-file1.pdf 8 Current Working Directory In order to be able to specify a file name or directory more efficiently, the UNIX (actually the shell program) also remembers the directory where you currently work You can then identify a file or directory relative to the current working directory Suppose the current working directory is “home/grads/nienaber”, then: “teaching” would refer to the same directory as: /home/grads/nienaber/teaching 05/24/11 unix-lect02-file1.pdf 9 More on Pathnames Absolute pathnames start at root /home/grads/nienaber /bin/tcsh Relative pathnames start at the current working directory Special symbols for the current directory and parent directory “..” refers to the parent directory (the directory “above”) “.” is the current directory Referencing user directories ~nienaber is the absolute pathname to the user’s home directory “nienaber” (directory “/home/grads/nienaber” in this example) ~/ is shorthand for the absolute path to your own user directory For me, it is the same as ~nienaber 05/24/11 unix-lect02-file1.pdf 10 Pathname Examples / bin home etc tcsh majors grads faculty fstab … nienaber … … research teaching … vision cop3353 notes homework 05/24/11 unix-lect02-file1.pdf 11 unix-lect01-intro.ppt unix-lect02-file1.ppt Potential Exam Questions True/false For any file, the absolute path to the file always starts with /. [T/F] For any directory, the absolute path to the directory is always the same. [T/F] For any file or directory, its relative pathname depends on the current working directory and is not unique. [T/F] Using relative pathnames only, some files and directories can not be referenced when the current working directory is at the bottom of the directory tree (note / is at the top of the tree). [T/F] 05/24/11 unix-lect02-file1.pdf 12 Common UNIX File Commands ls List files and subdirectories cat View file content more/less View file content (pause each screen) touch Create a file / update its time stamp cp Copy file to a new file mv Move file to a new directory, rename file rm Delete a file 05/24/11 unix-lect02-file1.pdf 13 Common Directory Commands pwd Display absolute pathname to current working directory mkdir Create a directory rmdir Remove a directory cd Change the current working directory 05/24/11 unix-lect02-file1.pdf 14 Command Examples pwd Prints the absolute pathname of the current working directory ls –l The ls command lists the files and subdirectories in a directory. The ‘l’ flag gives detailed information. touch The touch commands creates an empty file or updates the timestamp of an existing file cp The cp command copies the contents of a file or directory to another file or directory (two parameters). The ‘i’ flag asks before it replaces an existing file; the r flag recursively copies all subdirectories also 05/24/11 unix-lect02-file1.pdf 15 Command Examples – cont. mv The mv command renames a file (it takes two arguments) mv oldfilename newfilename If the second argument is a directory it moves it to that directory cd Changes the current working directory to another one cd notes cd .. cd ../notes Command --help Most commands have a summary of options via --help (or – h) Manual pages give more detailed information 05/24/11 unix-lect02-file1.pdf 16 Characters in Filenames File names can contain any characters except “/”, but it is recommended that you use upper or lower case letters, numbers, and “-” “.” For example, although a file name could contain a space or spaces confusing name commands using this would not work correctly unless you tell the shell to not break an argument at the spaces by quoting the filename or using special characters rm “confusing name” (or rm confusing\ name) 05/24/11 unix-lect02-file1.pdf 17 File Permissions Three types of running programs (or processes) can access a file User (or owner): process spawned by the user who created the file Group: process spawned by a member of the same group of a file Other: process spawned by anyone else Permission types Read: access to a file or list files of a directory Write: modify / remove / write to a file (directory) Execute: run a file as a program or enter a directory 05/24/11 unix-lect02-file1.pdf 18 Example Outputs Current permissions can be viewed using “ls –l” First line is the number of disk blocks (1 block is 1024 (or 512) bytes) taken up by all the files 05/24/11 unix-lect02-file1.pdf 19 Columns in the Display from “ls –l” First entry in a line is the mode The first character is d for directory, else - for a normal file The remain 9 characters in groups of threes are r, w, x permissions for user, group and other respectively (- indicates not having that permission) Second entry indicates number of links to the file (usually 1 for a file and 2 for a directory) Third entry is the user id of owner and the fourth entry is the group id Fifth entry is the number of bytes of the file Sixth entry is the date the file was last modified The last entry is the file/directory name 05/24/11 unix-lect02-file1.pdf 20 Potential Exam Questions True/false In order to read homework1.txt, a user must have read permission and execute permission for all directories along its absolute path. [F] Without writing permssion to the current working directory, a user can not delete a file from it. [T] 05/24/11 unix-lect02-file1.pdf 21 Changing Permissions Using the chmod command to set/change permissions Numeric (as octal numbers) Directly set the permissions for u, g, o using each 3 bit value as an octal value chmod 754 unix-lect02-file1.ppt will set to 111 101 100 or rwx r-x r-- chmod 700 unix-lect02-file1.ppt will set to 111 000 000 or rwx --- --- chmod 644 unix-lect02-file1.ppt will set to 110 100 100 or rw- r-- r-- 05/24/11 unix-lect02-file1.pdf 22 Changing Permissions - cont. Symbolic Format: chmod mode,[mode] <filename> The format of mode is who operation permission Who is one or more of u, g, o, a (for all) operation is + (add), - (remove), = (set) Permissions are one or more of r, w, x Examples chmod 654 unix-lect02-file1.ppt chmod go-rwx unix-lect02-file1.ppt chmod g+w unix-lect02-file1.ppt chmod u=rwx,g=rx,o=r unix-lect02-file1.ppt 05/24/11 unix-lect02-file1.pdf 23 Changing Permissions - cont.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    39 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us