Root root 584 20071014 0829 root

Numerical Permissions

On many occasions when permissions are discussed, you will see them being described in a three-digit numerical form (sometimes more digits for exceptional cases), such as 644. If a file has permissions 644, it has read and write permissions for the owner and read permissions for the group and for others. This works because Linux actually stores file permissions as sequences of octal numbers. This is easiest to see by example:

421421421 -rw-i—i— 644 -rwxr-xr-x 755 -i—i—i— 444 -r-------- 400

So for each owner, group, and others, a read permission is represented by 4 (the high bit of a 3-bit octal value), a write permission is represented by 2 (the middle bit of a 3-bit octal value), and an execute permission is represented by 1 (the low bit of a 3-bit octal value).

Changing Ownership and Permissions

You can change the ownership of a file with the command chown. If you are logged in as ioot, you can issue a command like this:

chown haipoiuseis file.txt

This changes the ownership of the file file.txt to the user haipo and the group useis.

To change the ownership of a directory and everything in it, you can use the command with the -R (recursive) option, like this:

chown -R haipo:useis /home/harpo/some_directory/

The chmod command is used to change file permissions. You can use chmod with both the numerical and the iwx notation we discussed earlier in the chapter. Again, this is easiest to follow by looking at a few examples:

■ chmod u+x afile: Adds execute permissions for the owner of the file

■ chmodg+i afile: Adds read permissions for the group owning the file

■ chmod o-i afile: Removes read permission for others

■ chmod a+w afile: Adds write permissions for all

■ chmod 644 afile: Changes the permissions to 644 (owner can read and write; group members and others can only read)

■ chmod 755 afile: Changes the permissions to 755 (owner can read, write and execute; group members and others can only read and execute)

If you use chmod with the iwx notation, u means the owner, g means the group, o means others, and a means all (in other words a is equivalent to ugo: user, group, and others). In addition, + means add permissions, and - means remove permissions, whereas i w, and x still represent read, write, and execute, respectively. When setting permissions, you can see the translation between the two notations by executing the chmod command with the -v (verbose) option. For example:

Was this article helpful?

0 0

Post a comment