Under the UNIX operating system, every file or directory has three rights (or permissions) attached to it: read, write, and execute. A file permission refers to the contents of the file; a directory permission refers to all files and subdirectories within the directory.
These three permissions may be independently assigned to (1) the owner of the file (or directory), (2) any groups the owner belongs to, and (3) everybody else (i.e., the world). Thus any given file or directory has a total of nine permissions attached to it.
Example: The UNIX command
% chmod 711 .assigns read, write, and execute permissions to the owner of the current directory, and makes the current directory group-executable and world-executable. To understand how this works, convert the octal number 711 to binary:
7118 = 1110010012Now compare this binary number to the output of an ls command executed after the chmod command has been executed:
% ls -al drwx--x--x 13 trscavo depend 1536 Jan 31 16:59 ./Observe the correspondence between the output of the ls command and the binary number 111001001:
111001001 drwx--x--xTherein lies the meaning of the octal number 711.
Example: The UNIX command
% chmod 755 public_htmlassigns read, write, and execute permissions to the owner of the directory public_html. It also makes public_html group-readable, group-executable, world-readable, and world-executable. The only thing this command does not do is make public_html group-writable and world-writeable (the latter, in particular, is not recommended). This is because 7558 = 1111011012 and so the corresponding permissions are
111101101 drwxr-xr-xExample: The first of the following two UNIX commands
% chmod -R 755 * % chmod -R 644 *.html *.gif *.jpgchanges the permissions of all files and directories in the current directory to 755, that is, all permissions are enabled except the group-writable and world-writeable characteristics. (Note: the -R switch (or option) tells the chmod command to recursively descend into the directory hierarchy and change the permissions of all files and directories, no matter how deeply buried they are.)
The second chmod command changes the permissions of all files ending in html, gif, or jpg. Since these files are not executable, the desired permissions are 644. Note that 6448 = 1101001002, and so
110100100 drw-r--r--which implies that the files are owner-readable, owner-writable, group-readable, and world-readable.