Introduction to Unix
Directory
When you want to prepare Web pages that are going to be accessible by anyone in the world, you need to put these pages in a directory called public_html. Hence you need to create this directory in your home directory. You are also required to create a directory called WebDev in which you will store your tutorial work for this module. As this work needs to be accessible by anyone, this directory will have to be in your public_html directory.
Access Rights
When you type ls or ls -l in your terminal window, you will see lots of details about the contents of your directory:
11 grizzly.cscs.wmin.ac.uk% ls -l
total 41978
drwxr-xr-x 2 coloma 800 512 Feb 11 16:25 lect01
-rw-r--r-- 1 coloma 800 25126 Jan 02 09:23 lect01.html
drwxr-xr-x 2 coloma 800 512 Feb 20 08:54 lect02
-rw-r--r-- 1 coloma 800 29164 Feb 13 10:12 lect02.html
drwxr-xr-x 2 coloma 800 512 Feb 22 17:43 lect03
-rw-r--r-- 1 coloma 800 29816 Feb 20 11:52 lect03.html
drwx--x--x 2 coloma 800 512 Feb 28 12:47 lect04
-rw-r--r-- 1 coloma 800 29935 Mar 14 09:54 lect04.html
12 grizzly.cscs.wmin.ac.uk%
In the left-hand column is a 10 symbol âstringâ consisting of symbols d, r,w, x, -. If d is present, it will be at the left-hand end of the string, and indicates a directory. Otherwise â-â will be the starting symbol of the string.
The 9 remaining symbols indicate the permissions, or access rights, and are taken as three groups of 3:
- The left group of 3 gives the file permissions for the user that owns the file (or directory) (
colomain the above example); - the middle group gives the permissions for the group of people to whom the file (or directory) belongs (
800in the above example); - the rightmost group gives the permissions for all others.
The symbols r, w, etc., have slightly different meanings depending on whether they refer to a simple file or to a directory.
Access rights on files
r(or-), indicates read permission (or otherwise), that is, the presence or absence of permission to read and copy the filew(or-), indicates write permission (or otherwise), that is, the permission (or otherwise) to modify a filex(or-), indicates execution permission (or otherwise), that is, the permission to execute a file, where appropriate
Access rights on directories
rallows users to list files in the directory;wallows users to make changes to the content of the directory, including delete files from the directory or move files into it;xmeans the right to access files in the directory. This implies that users may read files in the directory provided they have read permission on the individual files.
Changing access right
Only the owner of a file can use chmod to change the permissions of a file. The options of chmod are as follows:
| Symbol | Meaning |
|---|---|
| u | user |
| g | group |
| o | other |
| a | all |
| r | read |
| w | write (and delete) |
| x | execute (and access directory) |
| + | add permission |
| - | take away permission |
For example, to remove read write and execute permissions on the file welcome.html for the group and others, type:
chmod go-rwx welcome.html
This will leave the other permissions unaffected.
To give read and write permissions on the file welcome.html to all:
chmod a+rw welcome.html
Alternatively, it is also possible to change access rights using the corresponding octal value of the permission: read permission is given the value 4, write permission the value 2 and execute permission 1:
rwx
421
These values are added together for any one user category:
| Value | Meaning |
|---|---|
| 1 | execute only |
| 2 | write only |
| 3 | write and execute (2 + 1) |
| 4 | read only |
| 5 | read and execute (4 + 1) |
| 6 | read and write (4 + 2) |
| 7 | read, write and execute (4 + 2 + 1) |
So access permissions can be expressed as three digits. For example:
user group others
chmod 644 file1 rw- r-- r--
chmod 711 dir1 drwx --x --x
chmod 600 file2 rw- --- ---
When creating web pages and setting up web sites, your pages need to be accessible by anyone in the world. You need to set permissions to directories and files as follows:
| Action | Code to type in your terminal |
|---|---|
Directory permissions to be set up for:
public_html directory as well as subdirectories inside your public_html directory. So we'll start by changing permission to your home directory by going to the home directory and changing permissions to the current (.) folder, and then your public_html directory. Finally, we create the WebDev directory, and change its permission to 711.
|
|
File permissions to be set up for:
|
|
Review Questions
- Question 1 - What Permissions should you set to directories for your pages to be viewed on the Web but not allow file listing?
- Question 2 - What Permissions should you set to files for your pages to be viewed on the Web?