2.2. Handling File Attributes

The series of commands shown here are used to change the owner or owner group of a file or its permissions. We looked at the different permissions in chapter Basic UNIX System Concepts of the User Guide.

2.2.1. chown, chgrp: Change The Owner And Group of One or More Files

The syntax of the chown (CHange OWNer) command is as follows:

chown [options] <user[.group]> <file|directory> [file|directory...]

The options include:

Some examples:

The chgrp (CHange GRouP) command lets you change the group ownership of a file (or files); its syntax is very similar to that of chown:
chgrp [options] <group> <file|directory> [file|directory...]
The options for this command are the same as for chown, and it is used in a very similar way. Thus, the command:
chgrp disk /dev/hd*
changes the ownership of all files in directory /dev/ with names beginning with hd to group disk.

2.2.2. chmod: Changing Permissions on Files And Directories

The chmod (CHange MODe) command has a very distinct syntax. The general syntax is:
chmod [options] <change mode> <file|directory> [file|directory...]
but what distinguishes it is the different forms that the mode change can take. It can be specified in two ways:

  1. in octal. The owner user permissions then correspond to figures with the form <x>00, where <x> corresponds to the permission assigned: 4 for read permission, 2 for write permission and 1 for execute permission. Similarly, the owner group permissions take the form <x>0 and permissions for "others" the form <x>. Then, all you need to do is add together the assigned permissions to get the right mode. Thus, the permissions rwxr-xr-- correspond to 400+200+100 (owner permissions, rwx) +40+10 (group permissions, r-x) +4 (others' permissions, r--) = 754; in this way, the permissions are expressed in absolute terms. This means that previous permissions are unconditionally replaced;

  2. with expressions. Here permissions are expressed by a sequence of expressions separated by commas. Hence an expression takes the following form: [category]<+|-|=><permissions>.

    The category may be one or more of:

    • u (User, permissions for owner);

    • g (Group, permissions for owner group);

    • o (Others, permissions for "others").

    If no category is specified, changes will apply to all categories. A + sets a permission, a - removes the permission and a = sets the permission. Finally, the permission is one or more of the following:

    • r (Read);

    • w (Write) or;

    • x (eXecute).

The main options are quite similar to those of chown or chgrp:

Examples:


Tux on Star from MandrakeSoft Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights are the property of their respective owners.
Unless otherwise stated, all the content of these pages and all images are Copyright MandrakeSoft S.A. and MandrakeSoft Inc. 2002.
http://www.mandrakelinux.com/