File Permissions

What are file permissions?

File permissions are settings that all files and directories have. FIle permissions allow you to set who can read, write or execute certain files, in a limited way. You can see what file permissions a file has by doing ls -l. Here is an example:

darwin 5:38pm etc> ls -l /bin/ls
-r-xr-xr-x  1 root  wheel  59300 Apr  2 00:03 /bin/ls*

Here we are looking at the file permissions for the program /bin/ls. The -r-xr-xr-x section is displaying the permissions on the file. The first character on the left, which is - in this example, says what type of file it is. It this were a directory, it would be a d, but /bin/ls is a normal file, so it is a -. The rest can be broken into 3 different sections, each with the same information. In this example, we would have r-x repeated three times. The first instance is the permissions for the owner of the file (in this case, root), the second instance is the permissions for the group the file is in (in this case, wheel), and the last instance is the permissions for everybody on the system.

In this example, everyone (owner, group and everyone) has read and execute permissions. If anyone had write permissions, there would be a w in the middle character between the r and the x.

How do I change file permissions?

You can change permissions with the chmod command. You can use either symbolic or octal representation of the fiel permissions. For example, to remove world write permissions on a file, here's how to do it using symbolic representation:

chmod o+w file

And here's how to set the file permission to the owner being able to read and write a file, the group and world being able to read the world:

chmod 644 file