Russian News Network |
|
UNIX Lecture 7
Greetings to All, This is Lecture 7. Today I would like to begin this lecture by talking a bit more about directories. Home Directory Symbol There is a symbol that is used to represent the home directory. The symbol is: ~ So ~smith is equivalent to the home directory belonging to the user "smith". So if at your prompt you were to type: cd ~smith ...you would change directory into "smith's" home directory. The single and double dot directories Note: "single dot" means "." and "double dot" means ".." This is pretty simple. A single dot, ".", in place of a directory name in a command represents the current directory. A double dot, "..", in place of a directory name in a command represents the parent directory. Man Pages These pages are the online manual pages. You can use the "man" command to reference commands, etc. If you wanted to bring up the manual pages that deal with the ls command, at the prompt you would type: "man ls". (without the quotes or the dot). The pages will be displayed one screenful at a time. To go to the next screenful, press the enter key. To get out of the man pages, type "q". System Users and Permissions System users are classified into 3 different categories: -- the owner -- the group -- others The owner is the user who originally created the file. The group is the group of users to which the user belongs. The group is defined by the system administrator. "Others" are simply everyone else. Every file has the following permission categories for the three user categories: -- read - you can read the contents of the file. -- write - you can change the contents of the file. -- execute - you can execute the file (assuming that it is an executable file). Therefore, each file has 9 associated attributes. These are referred to as the "access permissions". The phrase "access mode" also refers to this set of attributes. This is how you can see the access permissions on a file: Use the ls command with the -l option to display the access mode of a file. For example, if at the prompt you type: ls -l, the output will be a long listing of files in your current directory. Lets say the total is 150 and you see several lines that look like this: -rw-rw-r-x 1 smith staff 82141 Sept 15 17:18 one.c The first line tells you how much space the directory takes up on the disk (in this case 150). The second line has 9 different parts: I am assigning a capital letter to each part, in the table below. PART Letter What It Looks Like A <----------------> -rw-rw-r-x B <----------------> 1 C <----------------> smith D <----------------> staff E <----------------> 82141 F <----------------> Sept G <----------------> 15 H <----------------> 17:18 I <----------------> test.c Here's what each part means: A --> indicates the permissions B --> tells you the number of links C --> Is the name of the person who created the file (the owner). D --> Tells you the group name E --> File size in bytes F --> The month of file creation/last edit G --> The day of file creation/last edit H --> The time of file creation/last edit I --> The file name (in this case, "test.c") Take note of A --> -rw-rw-r-x !! How many spaces does it take up? It takes up 10 spaces. What do they mean? Take this generic example for clarification: Lets replace all those letters and dashes with numbers, starting from 1 to 10. So in out example above, the first dash on the left is represented by a 1 and the last x on the right is represented by the number 10. Here's what the spaces tell you: Position 1 indicates the nature of the file: a dash (-) means that it is a standard file, a "d" would indicate that it is a directory. (Other letters will be treated in the future). Positions 2, 3, and 4 indicate the access permissions for the owner: Position 2 is read permission --> an "r" = yes, a dash (-) = no. Position 3 is write permission --> a "w" = yes, a dash (-) = no. Position 4 is execute permission --> an "x" = yes, a dash (-) = no. Positions 5, 6, and 7 indicate the access permissions for the group: Position 5 is read permission --> an "r" = yes, a dash (-) = no. Position 6 is write permission --> a "w" = yes, a dash (-) = no. Position 7 is execute permission --> an "x" = yes, a dash (-) = no. Positions 8, 9, and 10 indicate access permissions for all (everyone else): Position 8 is read permission --> an "r" = yes, a dash (-) = no. Position 9 is write permission --> a "w" = yes, a dash (-) = no. Position 10 is execute permission --> an "x" =yes, a dash (-) = no. Let's do an example: Here is the hypothetical access mode: -rwxr-x--x What does it tell you?? From the first dash on the left we know that it is a ordinary, standard file (ie, not a directory). That was position 1. From positions 2, 3, and 4, we know that the owner can read, write and execute the file. From positions 5, 6, and 7, we know that the group can read and execute the file, but the group is not allowed to write to the file. From positions 8, 9, and 10 we know that all other users can execute the file, but not read or write to the file. Directories and Permissions The access codes with directories have slightly different meanings, but this is not cause for despair. You must have read permission to use ls on a directory. You must have write permission to add or delete files from the directory. You must have execute permission to enter the directory (in other words, to use the cd command to change into the directory). What if you want to change access mode? Use chmod!!! The owner is can change the access mode of a file. chmod is the command that is used for changing access modes (chmod stands for "changing mode"). Here is how you use it: At the prompt, you would type: chmod ... ... ... ..... No, you don't type in a bunch of dots. Here the dots are being used as place holders....... First 3 dots = class Second 3 dots = operation Third 3 dots = permission Fourth 5 dots = file name Meanings of the above: class is: u --> user (ie, owner) g --> group o --> others a -->all (ugo) operation is: Equal sign, "=", this assigns permission absolutely (ie, it will assign the new permissions that you specified and remove the old ones) Dash, "-", remove access Plus sign , "+", give access permission is: r --> read w --> write x --> execute Keep in mind that "class" is optional and if you omit it, "all" will be assumed. Some examples: Typing this at prompt: chmod g+w file_A will change permission of file_A so that the group has write permission. Typing this at the prompt: chmod o-r file_A will disable read permission of file_A to "others". Typing this at the prompt: chmod o=r file_A gives only read permission to "others". Typing this at the prompt: ls -l file_A lets you check the permissions of file_A. Some of you have probably seen chmod used with numbers.... Permissions can also be specified using a 3 digit number (well, to be technical, it is called a 3 digit octal number). If you replace each octal digit with its three bit equivalent, you have converted it to its binary form. You get as a result a nine bit representation. The first group of 3 bits represent the permission for the owner. The second group of 3 bits represent the permission for the group. The last group of 3 bits represent the permission for all others. The number one (1) indicates "enable" The number zero (0) indicates "disable" So, chmod with numbers looks like this: chmod ... ... where first three dots = a three digit number and second 3 dots = file name Some examples: typing this at the prompt: chmod 777 file_A will change permissions of the file so that all have all permission. typing this at the prompt: chmod 644 file_ A will change permission of the file so that the owner has read and write permissions and everyone else has read permissions only. typing this at the prompt: chmod 764 file_A will change permission of the file so that the owner has all permissions, the group has read and write permissions, and others have read permission only. That will be all for today. Until next time, take care. Vladimir Polyakov PS And a special thanks to my friends at the Russian News Network website for their help in this endeavor. http://www.russiannewsnetwork.com
|