a

Lorem ipsum dolor sit amet, elit eget consectetuer adipiscing aenean dolor

The Geekiest One

intro to unix

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

When you type ls or ls -l in your terminal window, you will see lots of details about the contents of your directory:

11 geeky.csss.geek.cc.uk% ls -l
 total 41978
 drwxr-xr-x   2 geek   800       512 Feb 11 16:25 file01
 -rw-r--r--   1 geek   800     25126 Jan 02 09:23 file01.html 
 drwxr-xr-x   2 geek   800       512 Feb 20 08:54 file02
 -rw-r--r--   1 geek   800     29164 Feb 13 10:12 file02.html
 drwxr-xr-x   2 geek   800       512 Feb 22 17:43 file03
 -rw-r--r--   1 geek   800     29816 Feb 20 11:52 file03.html
 drwx--x--x   2 geek   800       512 Feb 28 12:47 file04
 -rw-r--r--   1 geek   800     29935 Mar 14 09:54 file04.html
12 geeky.csss.geek.cc.uk%

In the left-hand column is a 10 symbol ‘string’ consisting of symbols dr,wx-. 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) (geek in the above example);
  • the middle group gives the permissions for the group of people to whom the file (or directory) belongs (800 in the above example);
  • the rightmost group gives the permissions for all others.

The symbols rw, etc., have slightly different meanings depending on whether they refer to a simple file or to a directory.

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: readpermission is given the value 4write 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:

  • 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
Add Comment