An introduction of the Terminal for Mac OS X
- cd - change directory
- ls - list the content of a directory
- pwd - parent working dir
- mkdir - create a new directory
- rm - Remove files and folders
- cp - Copy files and folders
- mv - Move files and folders
- ditto - Move files and folders (advanced)
Manage permission of files and folders in the Terminal for Mac OS X
- Every file and folder on your Mac has permission rules which decides who gets to access those files.
Permissions can be set for three different categories: User, Group and Global.
Whenever you set new permissions of a file or a folder you have to decide which categories should be affected of this change:
The current User,
Every user in the same group as the file (Group)
or everyone else that's not in the same group as the file (Global).
In order for you to be able to change permissions of a file or a folder you need to have sufficient permissions yourself.
If you can't change permission of a file or a folder, try using the sudo-command which is described here.
Permissions can be set in two different ways: Symbolic mode and Numeric mode.
We are now going to explain these two options.
Setting permissions with Symbolic values (Symbolic mode)
When setting permissions with symbolic values you're mostly going to use three different letters:
- R - Read permission
- W - Write permission
- X - Execute permission
A file with read / write permissions would get the value RW.
Setting permissions with Numeric values (Numeric mode)
Permissions with numeric values are based on the octal numeral system. If you're not familiar with octal numbers you can read Wikipedia's section about the Octal numeral system.
A numeric permission consists of 4 numbers where each number represents a certain permission category, for instance: 0775.
|First number:||Set attributes for set user ID, and set group ID. (This is almost always the number zero ("0"))|
|Second number:||Permission for the User who owns the file|
|Third number:||Permission for other users within the same group as the file.|
|Fourth number:||Permission for all other who doesn't belong to the same group as the file.|
This can be illustrated in the following way:
So what does this values mean?
Well, even the numeric mode is based on the same kind of permissions we've seen in the symbolic mode: Read(R), Write(W) and Execute(X).
The only difference is that these letters have been translated into numerical values.
- R (Read) = 4
- W (Write) = 2
- X (Execute) = 1
These numeric values which represents a specific permission are added using simple addition to set the permission of a file or a folder. For example:
|Read / Write||R + W||4 + 2||6|
|Full access (read, write, execute)||R + W + X||4 + 2 + 1||7|
|Read and Execute, but not Write||R + X||4 + 1||5|
The trick, or the important thing to understand here is this:
No matter how you combine these three permissions you will never get the same numeric values for two different kind of permissions.
- The numeric value 5 can only mean the combination of 4 + 1 = Permission to read and execute.
- The numeric value 6 can only mean the combination of 4 + 2 = Read / Write permission.
- The numeric value 4 will always mean just Read permission.
Let's go back to the example above with the combined numeric value of 0775:
The Owner had the numeric permission value of 7.
This means that the owner has full permissions since 4 + 2 + 1 = 7.
- The Group also have the numeric value 7 which gives them the same permissions as the owner.
- The last digit, representing permissions for all Others, only had the numeric value of 5, which means a combination of 4 + 1 = Read and Execute, but no permission to Write to the specific file or folder.