1 / 55

Week 4 Agenda

Week 4 Agenda. UNIX Directory Structure Absolute pathname Relative pathname Permissions chmod (symbolic/absolute). UNIX Directory Structure. The UNIX system is structured hierarchically (upside down tree-like).

Download Presentation

Week 4 Agenda

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. Week 4 Agenda • UNIX Directory Structure • Absolute pathname • Relative pathname • Permissions • chmod (symbolic/absolute) Week 4 - Jan 31, 2005

  2. UNIX Directory Structure • The UNIX system is structured hierarchically (upside down tree-like). • You can have any number of files and subdirectories under it organized in any way. This structure leads to a parent-child relationship between a directory and its sub-directories. http://cs.senecac.on.ca/%7Efac/int120/labs/unixnotes.html Week 4 - Jan 31, 2005

  3. UNIX Directory Structure • The file system structure starts with one main directory, called the root directory. • From the root. At the end of each path is an ordinary file or a directory file. http://cs.senecac.on.ca/%7Efac/int120/labs/unixnotes.html Week 4 - Jan 31, 2005

  4. Ordinary file VS Directory File • Ordinary files (files) are at the end of paths and cannot support other paths while • Directory files (directories) are the points that other paths can branch from. Directories directly connected by a path called parents (closer to the root) and children (farther from the root) http://cs.senecac.on.ca/%7Efac/int120/labs/unixnotes.html Week 4 - Jan 31, 2005

  5. Different Directories • / Root directory – the ancestor of all directories and the start of all absolute pathnames. • ~ or $HOME Home directory - the working directory when you first login http://cs.senecac.on.ca/%7Efac/int120/labs/unixnotes.html Week 4 - Jan 31, 2005

  6. Different Directories • . Current working directory – the directory under which you are working • . . Parent directory – the directory above the working directory http://cs.senecac.on.ca/%7Efac/int120/labs/unixnotes.html Week 4 - Jan 31, 2005

  7. Pathname – Absolute VS Relative • Absolute pathname – A pathname that starts with root directory. It locates a file without regard to the working directory. • Relative pathname – A pathname that starts from the working directory. Week 4 - Jan 31, 2005

  8. Pathname – Example Your working directory is the_joker and home directory is action_heros1. Copy flinstones to your working directory by using relative pathname2. Copy flinstones to your working directory by using absolute pathname3. Delete simpsons by using relative pathname4. Rename cartoons to animation by using absolute pathname Week 4 - Jan 31, 2005

  9. Pathname – Example Week 4 - Jan 31, 2005

  10. How do you find out what permissions are on a file? • How do you change permissions • Directory Permissions • Default Permissions • What permissions do you need to do the following tasks...? Permissions- objectives Week 4 - Jan 31, 2005

  11. Key Concepts – File Permissions • UNIX security for users and for the system is based on who has access to files and directories • Setting “permissions” on a file controls who can read, write to or execute a file. • Use the ls -l command to see the permissions on a file Week 4 - Jan 31, 2005

  12. Warning! Your grocery lists and your Top Secret Buried Treasure maps should probably have different permissions! Week 4 - Jan 31, 2005

  13. Key Concepts - File Permissions The output of the ls - l command will look like this: total 66 -r-xr-x- - - 1 ling.zhu users 30 Mar26 19:49 colours drwxr-xr-x 4 ling.zhu sys 512 Apr 1 17:41 comfind Week 4 - Jan 31, 2005

  14. The Permission Field - the first field in the long listing entry It is10 characters long. example: [ling.zhu@zenit ling.zhu]>$ ls -l -r-xr-x- - - 1 ling.zhu users 54 Sep 26 19:49 lab2 Permissions Field Week 4 - Jan 31, 2005

  15. The Permission Field - The first character position -r-xr-x- - - 1 ling.zhu users 30 Mar26 19:49 colours drwxr-xr-x 4 ling.zhu sys 512 Apr 1 17:41 comfind - r-x r-x - - - file type Week 4 - Jan 31, 2005

  16. The Permission Field The first character position represents the file type: - a normal file d a directory l a soft or symbolic link s a socket c a character-special device b a block-special device Week 4 - Jan 31, 2005

  17. The Permission Field The next 9 characters in the Permissions Field are read as groups of 3 -r-xr-x- - - 1 ling.zhu staff 30 Mar26 19:49 colours drwxr-xr-x 4 ling.zhu sys 512 Apr 1 17:41 comfind - r-x r-x - - - Week 4 - Jan 31, 2005

  18. The Permission Field The next 9 characters in the Permissions Field are read as groups of 3 Each set of three characters is read the same way: r an “r” in the first position gives read permission for the file w a “w” in the second position gives write permission for the file x an “x” in the third position gives execute permission for the file Week 4 - Jan 31, 2005

  19. Similarly for each set of three characters.... - a “-” in the first position means no read permission for the file - a “-” in the second position means nowrite permission for the file - a “-” in the third position means no execute permission for the file Week 4 - Jan 31, 2005

  20. Warning! • For normal files execute permission means it is executable! • In DOS a file would have to have the proper extension in the filename to be executable. (.com, .exe , .bat) Week 4 - Jan 31, 2005

  21. The first set of three characters - indicates the permissions for the user who owns the file. - r-x r-x - - - The user that is the owner of a file is found in field 3 of the ls -l output. In this case ling.zhu has read and execute permission, no write permission user -r-xr-x- - - 1 ling.zhu users 30 Mar26 19:49 colours Week 4 - Jan 31, 2005

  22. Remember! UNIX, If you created it.... you own it! Week 4 - Jan 31, 2005

  23. The second set of three characters - indicates the permissions for the members of the file’s group. - r-x r-x - - - group The group that the file belongs to is found in field 4 of the ls -l output. In this case users have read & execute but no write permissions -r-xr-x- - - 1 ling.zhu users 30 Mar26 19:49 colours Week 4 - Jan 31, 2005

  24. The third set of three characters - indicates the permissions for all others on the system. - r-x r-x - - - others In this case others have no read, no write & no execute permissions... -r-xr-x- - - 1 ling.zhu users 30 Mar26 19:49 colours Week 4 - Jan 31, 2005

  25. Key Concepts - File Permissions -r-xr-x- - - 1 ling.zhu users 30 Mar26 19:49 colours drwxr-xr-x 4 ling.zhu sys 512 Apr 1 17:41 comfind - r-x r-x - - - file type group others user Week 4 - Jan 31, 2005

  26. chmod Week 4 - Jan 31, 2005

  27. 2 ways to specify permissions with the chmod command 1. add / remove permissions implicitly - symbolic method 2. set permissions explicitly - absolute or octal method Week 4 - Jan 31, 2005

  28. To add/remove permission implicitly (symbolic method) • You need to provide 3 pieces of information: • 1.WHOare you changing permissions for? • 2. whatOPERATIONdo you want to do? • 3. WHATare the permissions you want to • add/remove? Week 4 - Jan 31, 2005

  29. To add/remove permission implicitly (symbolic method) you need to provide 3 pieces of information: 1.WHOare you changing permissions for? u for the user g for the group o for all others a for all three Week 4 - Jan 31, 2005

  30. To add/remove permission implicitly (symbolic method) you need to provide 3 pieces of information: 2. whatOPERATIONdo you want to do? + (plus sign) add the permission - (minus sign) remove the permission = (equal sign) set it to indicated mode Week 4 - Jan 31, 2005

  31. To add/remove permission implicitly (symbolic method) you need to provide 3 pieces of information: 3. WHATare the permissions you want to add/remove? r read w write x execute Week 4 - Jan 31, 2005

  32. To add/remove permission implicitly (symbolic method) you need to provide 3 pieces of information: -r-xr-x- - - 1 ling.zhu users 30 Mar26 19:49 colours drwxr-xr-x 4 ling.zhu sys 512 Apr 1 17:41 comfind - r-x r-x - - - file type group others user Week 4 - Jan 31, 2005

  33. To add/remove permission implicitly (symbolic method) you need to provide 3 pieces of information: - r-x r-x - - - file type user group others To add write permission for user... 1. who?u (user) 2.whatoperation? + (add) 3.whatpermission? w (write) Week 4 - Jan 31, 2005

  34. To add/remove permission implicitly (symbolic method) you need to provide 3 pieces of information: - r-x r-x - - - file type user group others -r-xr-x- - - 1 ling.zhu users 30 Mar26 19:49 colours To add write permission for user for the file called colours the command would be: chmod u+w colours Week 4 - Jan 31, 2005

  35. To add/remove permission implicitly (symbolic method) you need to provide 3 pieces of information: The chmod u+w colours command results in the following permissions for the file colours: -rwxr-x- - - 1 ling.zhu users 30 Mar26 19:49 colours - rwx r-x - - - file type others Week 4 - Jan 31, 2005 user group

  36. To add/remove permission implicitly (symbolic method) you need to provide 3 pieces of information: - rwx r-x - - - file type user group others -rwxr-x- - - 1 ling.zhu users 30 Mar26 19:49 colours To remove write permission for user, and add write permission for the group for the file called colours the command would be: chmod u-w,g+w colours Week 4 - Jan 31, 2005

  37. To add/remove permission implicitly (symbolic method) you need to provide 3 pieces of information: The chmod u-w,g+w colours command results in the following permissions for the file colours: -r-xrwx- - - 1 ling.zhu users 30 Mar26 19:49 colours - r-x rwx - - - file type others Week 4 - Jan 31, 2005 user group

  38. Using Implicit or Symbolic Permissions! • To get the permissions exactly as you want them you may have to use a series of addition and removal commands.... • you can combine them all on one line, just make sure there are no spaces between them! Week 4 - Jan 31, 2005

  39. Key Concepts - File Permissions There are 2 ways to specify permissions with the chmod command: 1. add / remove permissions implicitly 2. set permissions explicitly Week 4 - Jan 31, 2005

  40. Setting permissions explicitly = octal = absolute Assign individual permission letters “point values” r = 4 w = 2 x = 1 deny all = 0 Week 4 - Jan 31, 2005

  41. 2. Setting permissions explicitly: r = 4 w = 2 x = 1 rwx = 4 + 2 + 1 = 7 read,write,execute rw- = 4 + 2 + 0 = 6 read, write r-x = 4 + 0 + 1 = 5 read, execute r-- = 4 + 0 + 0 = 4 read only -wx = 0 + 2 + 1 = 3 write, execute -w- = 0 + 2 + 0 = 2 write only --x = 0 + 0 + 1 = 1 execute only --- = 0 + 0 + 0 = 0 no permission Week 4 - Jan 31, 2005

  42. Setting permissions explicitly = octal = absolute -rwxr-x- - - 1 ling.zhu users 30 Mar26 19:49 colours chmod 777 colours - rwx rwx rwx rwx= 4+2+1=7 rwx= 4+2+1=7 rwx= 4+2+1=7 -rwxrwxrwx 1 ling.zhu users 30 Mar26 19:49 colours Week 4 - Jan 31, 2005

  43. Setting permissions explicitly = octal = absolute -rwxr-x- - - 1 ling.zhu users 30 Mar26 19:49 colours chmod 640 colours - rw- r-- --- rw-= 4+2+0=6 r--=4+0+0=4 ---= 0+0+0=0 -rw-r----- 1 ling.zhu users 30 Mar26 19:49 colours Week 4 - Jan 31, 2005

  44. Using Explicit or Octal Permissions ! • allows you need to specify the exact permissions you want... regardless of the current permissions Week 4 - Jan 31, 2005

  45. Directory Permissions Directory permissions are much the same as files • the owner of a directory decides who has access to its files • directory permissions are assigned using the same letters as for files but the meaning of the letters r,w,x are different..... Week 4 - Jan 31, 2005

  46. Directory Permissions Readpermission for a directory means you are allowed to list the files in the directory with ls Writepermission for a directory means you can create or remove files in it Execute permission for a directory means you can make it your working directory or pass through it in a path Read & execute = “search” permissions are required to get a long listing. Week 4 - Jan 31, 2005

  47. Directory Permissions Question: What permission do you need for a directory in order to remove a file under it? rw- ? -wx ? Week 4 - Jan 31, 2005

  48. Warning! • For directories, you need “execute” permission to search them! • ... without “search” permission in a directory you need to know the exact name of a file to read it Week 4 - Jan 31, 2005

  49. Question What is the minimum permission needed to view hiding.html under public_html/sub1/subsub1/week4 ? Week 4 - Jan 31, 2005

  50. Setting Default Permissions for New Files Two approaches to file security: 1. Permit wide access to your files and just turn off permissions for specific files and directories when more security is needed. 2. Permit limited access to your files and turn on permissions for specific files as needed. It’s YOUR choice! Week 4 - Jan 31, 2005

More Related