Every file and every folder in the Unix environment has a code that describes who may access and modify the file. There are three pertinent users of any file or folder:
The owner
The designated group
The "world" or "others".
This page explains how to use binary codes to change permissions. You may learn how to use mnemonic alternatives from the "man" page for chmod.
When you use ls -l to view a directory you get something like the following:
beast[10]% cd Castles
beast[11]% ls -l
total 20
-rw-r--r-- 1 wolz cs 671 Sep 25 23:47 Castle.html
-rw-r--r-- 1 wolz cs 2236 Sep 25 23:21 Castle.java
-rwxr-xr-x 1 wolz cs 1139 Sep 25 23:30 GoodCastle.class
-rw-r--r-- 1 wolz cs 530 Sep 25 23:51 GoodCastle.html
-rwx------ 1 wolz cs 2250 Sep 25 23:50 GoodCastle.java
The code at the beginning of the line contains 10 columns that are interpreted as follows:
| type: - means file, d means directory |
owner read bit: r means readable, - means not |
owner write bit: w means writable, - means not |
owner execute bit: x means executable, - means not |
group read | group write | group execute | world read | world write | world execute |
Ignoring the left most column, the columns are group by threes. For example, the Castle.java file above may be read and written (saved) by the owner, but may only be read by the group and world. Generally we don't worry about the group at TCNJ. Groups are usually used for administrative purposes rather than to define useful groups who would want access to something. The file GoodCastle.java may be read, saved and executed by the owner, but not by anyone else. The GoodCastle.class file however may be read and execute by everyone, but may only be written, (saved or changed) by the owner.
This scheme exploits binary numbers as shown in the following table. The protection setting bit is "on" for the corresponding binary digit. For example the binary number 5 is 101, which corresponds to r-x, the protection is read and execute, but not write.
| Binary Number | Decimal Representation | Protection Setting |
| 000 | 0 | --- |
| 001 | 1 | --x |
| 010 | 2 | -w- |
| 011 | 3 | -wx |
| 100 | 4 | r-- |
| 101 | 5 | r-x |
| 110 | 6 | rw- |
| 111 | 7 | rwx |
You can change the protection of a file, a group of files or a directory with the command chmod. One version of chmod takes two arguments: the protection code and the file(s) that are to be given that code. For example:
chmod 644 *.*
sets all the files in the current directory to read/write for the owner (6), and read only (4) for the group and everyone.
In order to allow others to view your applets and html files you must make sure that files are properly set. In general 755 works for anything. Some people suggest using 644 for files and 755 for directories because there can be a security breach for files that are executable.