Previous Table of Contents Next


Changing File Ownership or Permissions

Many user problems can be traced to file ownership or permissions problems. Use the ls command to check the permissions and ownership on a file. If you need to change one or both, use the chown, chmod, and chgrp commands.

Changing File Ownership You must own a file or directory (or have root permission) to be able to change its owner:

1.  Type ls -l filename and press Return. The owner of the file is displayed in the third column.
2.  Become superuser.
3.  Type chown new-owner filename and press Return. Ownership is assigned to the new owner you specify:
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
#

See Chapter 10, "Recognizing File Access Problems," for more information.

Changing File Permissions You can change file permissions by using the symbolic values r, w, x, and -. You can also change file permissions by using a set of octal numbers. Table 1-8 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.

Table 1-8 Octal Values for File Permissions

Value Description
0 No permissions
1 Execute-only
2 Write-only
3 Write, execute
4 Read-only
5 Read, execute
6 Read, write
7 Read, write, execute

1.  Type ls -l filename and press Return. The long listing shows the current permissions for the file.
2.  Type chmod nnn filename and press Return. Permissions are changed using the numbers you specify.


NOTE:  You can change permissions on groups of files, or on all files in a directory using metacharacters such as (*?) 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
-rw-r--r--  1 ignatz   staff    6Ø23 Aug  5 12:Ø6 quest
oak%

Changing File Group Ownership

To change the group ownership of a file, type chgrp gid filename and press Return. The group ID for the file you specify is changed:

$ 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
$

Group IDs are defined in the Group database or the local /etc /group file. See Chapter 7, "Administering User Accounts and Groups," for more information about groups.

Setting or Displaying the System Environment

The shell maintains an environment with a set of specifications that it gets from the shell initialization files. Users can also modify the shell environment for a session by issuing commands directly to the shell. The shell receives its information about the environment from environment variables. The SunOS 5.x system software provides several default environment variables:

  PS1: Defines the shell prompt. The default prompt for the Bourne and Korn shells is $. The default prompt for the C shell is %. The default prompt for root in either shell is #. Users can specify a different shell prompt in the .profile, .login, or .cshrc files.
  HOME: Defines the absolute path to the user's home directory. The default value for HOME is automatically defined and set to the login directory specified in the /etc/passwd file as part of the login process. The shell subsequently uses this information to determine the directory to change to when you type the cd command without an argument.
  LOGNAME: Defines the user's login name. The default value for LOGNAME is automatically defined and set to the login name specified in the /etc/passwd file as part of the login process.
  PATH: Lists, in order, the directories that the shell searches to find the program to run when the user types a command. If the directory is not in the search path, users must type the complete pathname of a command. The default PATH is automatically defined and set as specified in .profile ( Bourne or Korn shell), or .cshrc (C shell ) as part of the login process. The order of the search path is very important. When identically named commands exist in different locations, the first command found with that name is used. For example, suppose that PATH is defined (in Bourne and Korn shell syntax) as PATH=/bin:/usr/bin:/usr/sbin:$HOME/bin and a file named sample resides in both /usr/bin and /home/jean/ bin. If the user types the command sample without specifying its full path name, the version found in /usr/bin is used.


Previous Table of Contents Next