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 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

Access rights on directories

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:

SymbolMeaning
uuser
ggroup
oother
aall
rread
wwrite (and delete)
xexecute (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:

ValueMeaning
1execute only
2write only
3write and execute (2 + 1)
4read only
5read and execute (4 + 1)
6read and write (4 + 2)
7read, 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:

ActionCode to type in your terminal
Directory permissions to be set up for:
  • read/write/execute for you
  • execute for your group
  • execute for others
Please note that this concerns files in the 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.
cd 
chmod 711 .
cd 
chmod 711 public_html
cd public_html
mkdir WebDev
chmod 711 WebDev
File permissions to be set up for:
  • read/write for you
  • read for your group
  • read for others
cd WebDev
chmod 644 tut1.html