1 / 36

Unix Comp-145

Unix Comp-145. Lecture 3: The UNIX File System Source: S. Das, “Your Unix: The ultimate Guide”, 2 nd Edition, McGraw Hill, 2006. Objectives. Who is logged on The Path & Privacy File Naming and Properties File Access & Navigation Types & Structures of files File Access Permissions

morey
Download Presentation

Unix Comp-145

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unix Comp-145 Lecture 3: The UNIX File System Source: S. Das, “Your Unix: The ultimate Guide”, 2nd Edition, McGraw Hill, 2006 BROOKDALE COMMUNITY COLLEGE

  2. Objectives Who is logged on The Path & Privacy File Naming and Properties File Access & Navigation Types & Structures of files File Access Permissions Mounting File Systems BROOKDALE COMMUNITY COLLEGE

  3. Who is logged on & what are they doing? • users • Shows a list of all currently logged on users • whoandwhoami • Display a list of all currently logged on users and where they are logged on from • w • Shows a list of all currently logged on users and what they are running • finger • Tells a little more information about users BROOKDALE COMMUNITY COLLEGE

  4. Privacy issue? • You can tell when someone else is logged on & exactly what they are doing • Everyone else can see what you are doing • Is this acceptable? BROOKDALE COMMUNITY COLLEGE

  5. The UNIX File & Naming • A container for storing information and data. • Filename - 1. Limited to 255 characters. 2. Can’t contain /orNULL. • Filenames are case-sensitive, i.e., chapandChapare two different filenames. • Upper case “A” not same ASCII value as “a”. BROOKDALE COMMUNITY COLLEGE

  6. The UNIX File & Naming (Cont’d) • Group of filenames held together in a directory. • Directory listing contains name of the file. • Both files and directories are subject to access control. BROOKDALE COMMUNITY COLLEGE

  7. The UNIX File (Cont’d) • File content can be any sequence of ASCII characters or binary encoded characters • Neither file name or size is stored in file • Filenames can be: • Up to 255 char in length, file extensions are optional. • Can’t contain “/” or NULL (ASCII value = 0 [i.e., zero] • Avoid using $ ` ? * & in names BROOKDALE COMMUNITY COLLEGE

  8. File Types • Ordinary or regular file: Contains data as a stream of characters. This file can be a • TEXT file (program sources, configuration files) – Contains only printable and EOL characters visible with “od” command. • BINARY file (executables, graphic and multimedia files). • Directory: Contains the filename and a number (inode number). • Device file: Contains no data whatsoever. • Symbolic link: Contains the location of another file. BROOKDALE COMMUNITY COLLEGE

  9. Properties Of Files All files have these properties Permissions Links For directories, this lists the number of subdirectories Owner Owner group Size Timestamp Name

  10. The Hierarchical Structure of the File System • A single hierarchical structure that contains all files. • Top signified by root(/). • Existence of a parent-child relationship. • Parent of any file must be a directory. • Files accessed with pathnames(e.g., /etc/passwd). BROOKDALE COMMUNITY COLLEGE

  11. Hierarchical File Structure Illustrated BROOKDALE COMMUNITY COLLEGE

  12. What Goes Where? / Root of the entire system Comparable in Windows to C:\ Windows, however, has several roots depending on what partition and device you are looking at /bin Commonly used binaries (programs) BROOKDALE COMMUNITY COLLEGE

  13. What Goes Where? (Cont’d) /sbin More programs to run Statically linked Still should run if you tinker around and mess things up /usr User related commands as well as a whole bunch of random stuff BROOKDALE COMMUNITY COLLEGE

  14. /lib Libraries (re-used files/executables) go in here /dev All devices are located in here /home Traditionally, this is where user accounts are stored /etc Startup files and configuration files for daemons and other programs What Goes Where? (Cont’d) BROOKDALE COMMUNITY COLLEGE

  15. What Goes Where? (Cont’d) • /var • Various files go in here • Traditional location of mailboxes • /var/spool/mail • /proc • Special files that contain information about the system or info from running programs BROOKDALE COMMUNITY COLLEGE

  16. Navigating The Directory Structure You are always located at one location in the tree ls Provides a listing of the current directory All files and directories are shown cd Change directory “cd /” Moves your current directory to / cdwithout any arguments moves you to your home directory BROOKDALE COMMUNITY COLLEGE

  17. Special Notation for Traversing Directories . This stands for the current directory .. This stands for the directory directly above the current directory ~ Your home directory These directories can be “stacked” “../..” stands for two directories directly above the current directory BROOKDALE COMMUNITY COLLEGE

  18. Pathnames: Two Types • Absolute pathname: Specifies location with reference to the file system top (e.g, cat /etc/passwd). • Relative pathname: Specifies location with reference to the user’s current location (e.g., cd../include). • Both commands and filename arguments can be represented in either form. BROOKDALE COMMUNITY COLLEGE

  19. Pathnames With Respect To File Hierarchy root / bin dev home lib tmp sbin etc usr var dsk fd0 fd1 bin lib sbin local austin julie progs login.sql .profile BROOKDALE COMMUNITY COLLEGE

  20. Useful Pathnames • /bin & /usr/bin directories: • User accessible - commonly used command repository • bin indicates binary file store • /sbin& /usr/sbindirectories. • SuperUser or Adminsitrator accessible command repository • /etc directory • Configuration file repository: e.g., /etc/passwd& /etc/shadow. • /dev directory • All device files • May have sub-dirctories: pts, dsk, rdsk BROOKDALE COMMUNITY COLLEGE

  21. Useful Pathnames (Cont’d) • /lib & /usr/lib directories: • User accessible – all reusable files in binary form. • /usr/include directory: • User accessible – all standard header files used in C programs • Naming: Usually have a suffix “.h” • C-code#include stdio.hwhich instructs compiler to include the file stdio.h when it creates the executable for C-prog. • /usr/share/mandirectory • man page repository. • /tmpdirectory • Users create temporary files. BROOKDALE COMMUNITY COLLEGE

  22. Useful Pathnames (Cont’d) • User specific directories: • /tmpdirectory • Repository for temporary files; • deleted regularly by system • /var directory • Temporary repository for print jobs & e-mail; • Temporary repository for in-coming and out-going e-mail • /home directory • Often users located as child directories of /home; BROOKDALE COMMUNITY COLLEGE

  23. Absolute Pathname • Begins with a / (e.g., /etc/passwd). • First / signifies the root directory. • System configuration files that normally don’t change location should be addressed in absolute manner. • Used with a command that • doesn’t feature in PATH. • resides in two or more directories of PATH. BROOKDALE COMMUNITY COLLEGE

  24. Relative Pathname • To signify the current directory use . • To signify the parent directory use .. • RP used to refer to files that are (1) impossible or (2) inconvenient to access in an absolute manner. • RP can be a synonym for a filename argument that doesn’t have a/ (e.g., cat foois the synonym for cat ./foo.) • Same synonym doesn’t automatically exist for commands. • ( e.g., cat fooMAY NOT be the same as ./cat foo.) BROOKDALE COMMUNITY COLLEGE

  25. The Home Directory • Directory where user is placed on login. • Determined by sixth field in /etc/passwd: • romeo:x:500:100:romeo vincent:/home/romeo:/bin/bash • Can also be referred to by • the shell variable $HOME (e.g. cat $HOME/foo). • tilde (~) expansion in most shells: (e.g. cat ~/foo). • cdcommand used without arguments returns user to home directory. • User can create and remove files in their home directory but not in other directories. BROOKDALE COMMUNITY COLLEGE

  26. File Access Permissions -rwxrwxrwx - rwx rwx rwx File Type Owner Group World • = file • d = directory BROOKDALE COMMUNITY COLLEGE

  27. Owner, Group, The World Owner The creator of the file Group A set of users grouped together The world Every other account not in the group BROOKDALE COMMUNITY COLLEGE

  28. Read, Write, Execute Read File can be read, but not modified Write Permission is granted to modify the file Execute Run directly as if the file is a program All programs should be executable(/bin) BROOKDALE COMMUNITY COLLEGE

  29. What Permissions Mean On A Directory Read Users can get a listing of that directory Write Users can create and remove files in that directory Execute Users can examine files in that directory BROOKDALE COMMUNITY COLLEGE

  30. Changing Permissions With chmod chmod<SETTINGS> <FILE> u = user g = group o = other a = all • + (add) • (remove) • = (set) r = read w = write x = execute chmod a-x testFile BROOKDALE COMMUNITY COLLEGE

  31. More Examples Set read and write access for all? chmod a=rw<FILE> Add executable access for others? chmod o+x<FILE> Remove all access for owner? chmod u-rwx<FILE> Set read, write & execute access for all? chmod a=rwx <FILE> 777 permissions Octal Representation of -rwxrwxrwx Three binary digits or bits corresponds to one octal digit: Read = 4, Write = 2 Execute =1 i.e., rwx = 4+2+1 = 7 chmod 750 <file> same as chmod u=rwx,g=rx,o= <file> BROOKDALE COMMUNITY COLLEGE

  32. AdvancedchmodUsage Most Unix hackers don’t use this form They prefer the more direct approach Set permissions for owner, group, and others all with one number Unfortunately, this approach requires a little bit of information BROOKDALE COMMUNITY COLLEGE

  33. Mount & Un-mount • Command line utilities. • Require root user privilege or the corresponding fine-grained privilege, except if the file system is defined as "user mountable" in /etc/fstabfilefile(only be modifiable by the root user). • mount • Instructs the OS that a file system is ready to use, • Associates it with a particular point in the system's file system hierarchy (its mount point). • NOTE: Each mount point is mapped to a remote file • unmount • Instructs the OS that that the file system should be disassociated from its mount point, i.e., make it no longer accessible. BROOKDALE COMMUNITY COLLEGE

  34. Backup Slides BROOKDALE COMMUNITY COLLEGE

  35. man Page Sections & What They Mean • 1 – User commands • 2 – System Calls • 3 – C library routines • 4 – Administrative files • 5 – Miscellaneous • 6 – Games • 7 – I/O and special files • 8 – System administration commands BROOKDALE COMMUNITY COLLEGE

  36. More on man • Other sections exist (such as the perl reference manual and the tcl reference manual) • -a will show all the man pages that match • First is shown by default • How would you find out more about man? • man man BROOKDALE COMMUNITY COLLEGE

More Related