Changing permissions and ownership of files and directories in AIX


CHOWN command - used to change the ownership of any files and directories.
CHMOD command - used to change the permissions of any files and directories.

These commands can also be used to change sub-directories ownership & permissions with single command.

Chown

Syntax
chown [  -f ] [ -h ] [  -R ] Owner [ :Group ] { File ... | Directory ... }
chown -R  [  -f ] [ -H | -L | -P ] Owner [ :Group ] { File ... | Directory ... }
Description
The chown command changes the owner of the file or directory specified by the File or Directory parameter to the user specified by the Owner parameter. The value of the Owner parameter can be a user name from the user database or a numeric user ID. Optionally, a group can also be specified. The value of the Group parameter can be a group name from the group database or a numeric group ID.

Also Read: Storage Area Network (SAN) Basic Free Tutorials
Only the root user can change the owner of a file. You can change the group of a file only if you are a root user or if you own the file. If you own the file but are not a root user, you can change the group only to a group of which you are a member.

Examples

  • To change the owner of the directory softwares to TOM:

                  chown  TOM softwares

  • To change the owner and group of all files in the directory /tmp/tsm to owner TOM and group build:

                  chown -R TOM:tsmgroup /tmp/tsm


Chmod

Description
The chmod command modifies the mode bits and the extended access control lists (ACLs) of the specified files or directories. The mode can be defined symbolically or numerically (absolute mode).
When a symbolic link is encountered and you have not specified the -h flag, the chmod command changes the mode of the file or directory pointed to by the link and not the mode of the link itself. If you specify the -h flag, the chmod command prevents this mode change.
If you specify both the -h flag and the -R flag, the chmod command descends the specified directories recursively, and when a symbolic link is encountered, the mode of the file or directory pointed to by the link is not changed.
Syntax

To Change File Modes Symbolically

chmod [ -R ] [ -h ] [ -f ] [ [ ] [ ] [ ] | [ ] ] { { - | + | = } [ ] [ ] [ ] [ ] [ ] [ ] } { File ... | Directory ... }

To Change File Modes Numerically

chmod [ -R ] [ -h ] [ -f ] PermissionCode { File ... | Directory ... }

The first set of flags specifies who is granted or denied the specified permissions, as follows:
u  File owner.
g  Group and extended ACL entries pertaining to the file's group.
o  All others.
a  User, group, and all others. The a flag has the same effect as specifying the ugo flags together. If none of these flags are       specified, the default is the a flag and the file creation mask (umask) is applied.

The second set of flags specifies whether the permissions are to be removed, applied, or set:

-
  Removes specified permissions.
+
  Applies specified permissions.
=
  Clears the selected permission field and sets it to the permission specified. If you do not specify a permission following =,    the chmod command removes all permissions from the selected field.

The third set of flags specifies the permissions that are to be removed, applied, or set:

r    Read permission.
w   Write permission.
x    Execute permission for files; search permission for directories.
X   Execute permission for files if the current (unmodified) mode bits have at least one of the user, group, or other execute       bits set. The X flag is ignored if the File parameter is specified and none of the execute bits are set in the current mode       bits. Search permission for directories.


Also Read: Frequently Asked Interview Questions and Answers 

s   Set-user-ID-on-execution permission if the u flag is specified or implied. Set-group-ID-on-execution permission if theg       flag is specified or implied.
t   For directories, indicates that only file owners can link or unlink files in the specified directory. For files, sets thesave-         text attribute.

Examples
  1. To add a type of permission to several files:
    chmod  g+w  chap1  chap2
    This adds write permission for group members to the files chap1 and chap2.
  2. To make several permission changes at once:
    chmod  go-w+x  mydir
    This denies group members and others the permission to create or delete files in mydir (go-w) and allows group members and others to search mydir or use it in a path name (go+x). This is equivalent to the command sequence:
    chmod  g-w  mydir
    chmod  o-w  mydir
    chmod  g+x  mydir
    chmod  o+x  mydir
  3. To permit only the owner to use a shell procedure as a command:
    chmod  u=rwx,go= cmd
    This gives read, write, and execute permission to the user who owns the file (u=rwx). It also denies the group and others the permission to access cmd in any way (go=).
    If you have permission to execute the cmd shell command file, then you can run it by entering:
    cmd
    Note: Depending on the PATH shell variable, you may need to specify the full path to the cmd file.
  4. To use the absolute mode form of the chmod command:
    chmod  644  text
    This sets read and write permission for the owner, and it sets read-only mode for the group and others. This also removes all extended ACLs that might be associated with the file.
  5. To recursively descend directories and change file and directory permissions given the tree structure:
    ./dir1/dir2/file1
    ./dir1/dir2/file2
    ./dir1/file1
    enter this command sequence:
    chmod -R 777 f*
    which will change permissions on ./dir1/file1.
    But given the tree structure of:
    ./dir1/fdir2/file1
    ./dir1/fdir2/file2
    ./dir1/file3
    the command sequence:
    chmod -R 777 f*
    will change permissions on:
    ./dir1/fdir2
    ./dir1/fdir2/file1
    ./dir1/fdir2/file2
    ./dir1/file3





What Others are Reading Now...

0 Comment to "Changing permissions and ownership of files and directories in AIX"

Post a Comment