Wednesday, July 10, 2013

Unix/Linux Fundamentals



File Permission in Unix
File ownership is an important component of UNIX that provides a secure method for storing files. Every file in UNIX has the attributes as follows-
# Owner permissions:  The owner's permissions determine what actions the owner of the file can perform on the file.
# Group permissions: The group's permissions determine what actions a user, who is a member of the group that a file belongs to, can perform on the file.
# Other (world) permissions: The permissions for others indicate what action all other users can perform on the file.

[oracle@localhost ~]$ ls -l
total 32
drwxrwx---  6 oracle oinstall 4096 Jan 29 10:50 oraInventory

The permissions are broken into groups of threes, and each position in the group denotes a specific permission, in this order: directory(d), read (r), write (w), execute (x)

# The first four characters (1-4) i.e. drwx represent the permissions for the file's owner.
# The second group of three characters (5-7) i.e. rwx consists of the permissions for the group to which the file belongs.
# The last group of three characters (8-10) i.e. --- represents the permissions for everyone else. Here, any other person has no permission on oraInventory.

File Access Modes
There are three different access modes for a file/directory as follows-
# Read- Having read permission can read the file i.e. view the contents of the file.
# Write- Having write permission can modify, delete the contents of the file.
# Execute- Having the execute permission can run the file as a program.

Changing Permissions in file(chmod)
To change file or directory permissions, you use the  chmod  (change mode) command. There
are two ways to use chmod: symbolic mode and absolute mode.

Using chmod in Symbolic Mode
The easiest way for a beginner to modify file or directory permissions is to use the symbolic mode. With symbolic permissions you can add, delete, or specify the permission set you want by using the operators in the following table.
(+)    Adds the designated permission(s) to a file or directory.
(- )    Removes the designated permission(s) from a file or directory.
(=)    Sets the designated permission(s).

Using chmod with Absolute Permissions
The second way to modify permissions with the chmod command is to use a number to specify
each set of permissions for the file.

Each permission is assigned a value, as the following table shows, and the total of each set of
permissions provides a number for that set.
Number representation for File permission
      0    No permission (---)
1      Execute permission (--x)
2      Write permission (-w-)
3      Execute and write permission: 1 (execute) + 2 (write) = 3; (-wx)
4      Read Permission (r--)
5      Read and execute permission: 4 (read) + 1 (execute) = 5 (r-x)
6      Read and write permission: 4 (read) + 2 (write) = 6 (rw-)
7      All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 (rwx)

Changing Owners and Groups(chown, chgrp)
# chown:  The chown command stands for "change owner" and is used to change the
owner of a file.
# chgrp: The chgrp command stands for "change group" and is used to change the group
of a file.

Changing Ownership(chown)- The chown command changes the ownership of a file. It is used as follow-
[oracle@localhost ~]$ chown user_name filename

The above command changes the owner of filename file to user_name. The value of user can be either the name of a user on the system or the user id (uid) of a user
on the system.

Changing Group Ownership(chgrp)- The chrgp command changes the group ownership of a file.
It is used as follows-
[oracle@localhost ~]$ chown group_name filename

The above command changes the group owner of filename file to group_name.



No comments:

Post a Comment