|Previous||Table of Contents||Next|
NOTE: You must own a file or directory (or have root permission) to be able to change its ownership.
Follow these steps to change file ownership:
oak% ls -l quest -rw-r--r-- 1 fred staff 6Ø23 Aug 5 12:Ø6 quest oak% su Password: # chown ignatz quest # ls -l quest -rw-r--r-- 1 ignatz staff 6Ø23 Aug 5 12:Ø6 quest #
You use the chmod command to change file permissions. You can change permissions in two ways. If you use letters, use this syntax:
chmod [who]operator[permission(s)] file-name
For who, you can specify u, g, or o (for user, group, or other). You can specify a to change all operators. If you do not specify who permissions are for, permissions are changed for all three groups. The operator is either + to add permission or - to take away permission. The permissions are r, w, or x, for read, write, or execute. See the chmod(1) manual page for more permissions.
For example, to grant read, write, and execute permissions to everyone, type chmod +wrx file-name and press Return:
oak% chmod +wrx dog oak% ls -l dog -rwxrwxrwx 1 janice staff 54 Jul 7 11:33 dog oak%
To grant read and execute permissions to everyone, type chmod +rx file-name and press Return:
oak% chmod +rx dog oak% ls -l dog -r-xr-xr-x 1 janice staff 54 Jul 7 11:34 dog oak%
Another way to change the permissions to read and execute only would be to deny write permission to everyone. Type chmod -w file-name and press Return:
oak% chmod -w dog oak% ls -l dog -r-xr-xr-x 1 janice staff 54 Jul 7 11:35 dog oak%
To change ownership for a specific group, type the letter for the group followed by the operator and the permission. In the following example, read, write, and execute permissions have been granted for the owner to the file dog:
oak% chmod u+wrx dog oak% ls -l dog -rwxr-xr-x 1 janice staff 54 Jul 7 11:36 dog oak%
To deny execute permissions to group and other, type chmod go-x file-name and press Return.
oak% chmod go-x dog oak% ls -l dog -rwxr--r-- 1 janice staff 54 Jul 7 11:37 dog oak%
You can also use a numeric argument with the chmod command that describes the user class and permission to change as a sequence of bits. Table 10-1 shows the octal values for setting file permissions. You use these numbers in sets of three to set permissions for owner, group, and other. For example, the value 644 sets read/write permissions for owner, and read-only permissions for group and other.
|7||Read, write, execute|
Follow these steps to change permissions on a file:
NOTE: You can change permissions on groups of files or on all files in a directory using metacharacters such as * and ? in place of file names or in combination with them.
This example changes the permissions of a file from 666 (read/write, read/write, read/write) to 644 (read/write, read-only, read-only):
oak% ls -l quest -rw-rw-rw- 1 ignatz staff 6Ø23 Aug 5 12:Ø6 quest oak% chmod 644 quest oak% ls -l quest -rw-r--r-- 1 ignatz staff 6Ø23 Aug 5 12:Ø6 quest oak%
If a file has an incorrect group owner, users of the group will not be able to make changes to the file. To change file group ownership, you must either be a member of the group, own the file, or change it as root.
To change the group ID for a file, type chgrp gid filename and press Return. The group ID for the file you specify is changed. With Solaris 2.x, the ls -l command shows the owner and the group for the file. You can display only the group owner using the ls -lg command:
$ ls -lg junk -rw-r--r-- 1 other Ø Oct 31 14:49 junk $ chgrp 1Ø junk $ ls -lg junk -rw-r--r-- 1 staff Ø Oct 31 14:49 junk $
The group ID is found in the Group database or the local /etc/group file.
|Previous||Table of Contents||Next|