Not everyone has used UNIX before, and as web developer there's every chance that at some point you'll want to use UNIX commands to perform tasks such as changing the permissions of a folder or file. This is where this guide comes in handy - it should help give you the commands you need for basic tasks, with a description of what they do in an easy to understand way!
Changing Permissions
The most likely thing you'll want to do with UNIX is to change the permissions of a file or folder. This so that user's other than the one that created the file or folder can make modifications to it. Unix permissions have three "groups": Owner, Group, Others. Each of these groups can have any combination of Read, Write, and Execute permissions.
The owner and group for the file can be changed using a command called chown. This is short for "Change Ownership" so should be an easy command to remember after you've used it a few times. The syntax for the command is as follows:
chown [OPTIONS] OWNER[:GROUP] FILE
Anything in square brackets means that it is optional. For the OPTIONS part, the only one you're likely to need is the -R option as if the FILE you specify is a folder it will apply the new owner(s) to all the files in the folder.
If we wanted a webpage to be able to write to the file called test.txt in the current folder then we would use:
chown www-data:www-data test.txt
However, doing it this way would mean if logged in to the "bash" prompt, then you would not be able to edit this contents of this file yourself (unless you are logged in as www-data or root) and so another way to do give writing permissions without changing the owner is to modify the permissions for owner, group, and other. The basic syntax of chmod is:
chmod [OPTIONS] (MODE|OCTAL) FILE
In the above syntax, anything in square brackets is optional. In the case of (MODE|OCTAL) it means one or the other MUST be included. MODE means that you can use one of the following:
- +x
- Add executable permissions for owner, group and other
- -x
- Remove executable permissions for owner, group and other
- +r
- Add readable permissions for owner, group and other
- -r
- Remove readable permissions for owner, group and other
- +w
- Add writeable permissions for owner, group and other
- -w
- Remove writeable permissions for owner, group and other
If you want to be more specific about the permissions you want to give, then you must use the OCTAL method. OCTAL means that for owner, group and other we represent which permissions it has using a number from 0 to 7. Each permission has a value of:
- Execute (x) - 1
- Write (w) - 2
- Read (r) - 4
These go in the order Owner, Group, Other. To see the existing permissions on the files in the current folder, you can use ls -a. This will produce a list that has attributes marked as:
rwxrwxr-x
In this example the Owner and Group have full privileges, but everyone else would only have read and executable privileges. In Octal this would be represented as 775. In the above example a hyphen (-) means that it doesn't have that particular permission. The 7 for read, write, and execute permissions is calculated by adding together the values for each. A quick way to remember these are:
- Execute
- Write
- Write + Execute
- Read
- Read + Execute
- Read + Write
- Read + Write + Execute













