Change File Permissions using Terminal in Mac OS X

Changing file permissions on the Mac is something you need to know how to do if you want to create your own non-home directory only shares on the Mac. Leopard implements folder sharing similarly to the way SharePoints does. I find myself needing to change permissions regularly because certain programs like to change file permissions on their own. The Terminal is generally better for changing permissions because it is much faster and also because you have more control. Sometimes you may need to do this is the file permissions get messed up in Leopard’s File Sharing under System Preferences.
Here’s how it works:
* First, open the Terminal, then use the command ‘cd‘. For example, if you wanted to change to your Desktop directory, you would type:
cd ~/Desktop
to change to your desired directory. Note that the tilde ‘~’ represents your home directory.
The command ‘ls‘ then shows the files within the current directory. You can also use:
ls -la
The ‘l’ switch lists files in long format, and the ‘a’ switch lists all files, including hidden ones.
If you are the owner of a file, you have the ability to change its permissions with the command:
chmod
There are several ways chmod can be used, however I will only focus on the octal system. The first number represents the owner’s permission, the 2nd represents the groups permission, and the last one represents the world’s or everyone’s access. The permission is calculated using simple arithmetic.
The first number represents the access granted to the file’s owner. The next number, represent access granted to the file’s group owner, and the last number represents everyone else’s level of access. The possibilities for permissions include: read (4), write (2), execute (1), and no permission (0).
The permission is set using the chmod command:
chmod 755 filename
However a more practical use of the command would be:
sudo chmod -R 755 /directoryname
This command will recursively change the permissions on all files and folders contained within that directory because we used -R.
Okay, so just to rehash again:
The 7 comes from 1 + 2 + 4. This means read, write and execute permission (for the owner).
The 5 comes from 1 + 4. This means execute and read permission (for the group).
The 5 comes from 1 + 4. This means execute and read permission (for everyone).
This means that the file’s owner has read, write, and execute permission, but group and world only have read and execute permissions. Managing file permissions on the Mac isn’t that difficult once you get the hang of it. And doinging it youself if more powerful that using Disk Utiity, however you should take care as you can screw things up when using the sudo (root permission) command.