Unix

Unix
Caution!!

Tuesday, 1 July 2014

Unix File Permissions

In this post we would discuss about the file permissions.

Also on the way of learning about file permissions in UNIX we would discuss the below commands :-

1.chmod

2.chown
3.chgrp

The default file permission are :-

1.666 for a file (i.e rw-rw-rw)
2.777 for a directory(i.e rwx-rwx-rwx)

*** The default permissions can be change by umask command

The long listing of a file can be read as 

-rwxrw--w-    1 anik unixsizzlers     217 Jun 26 14:08 filename  


  • The first part represnets the type of file and the file permission.The first hypen "-" of -rwxrw-w- represents the type of file .- means its a normal file.l represnets a soft link.d represensta a directpry.
  • The digits 2,3 and 4 represents the permissions of the owner of the file (i.e rwx which means read,write and executable permissions).
  • The didigts 5,6, and 7 represents the permission of the group (i.e rw- which means read ad write permission).
  • The digits 8,9,10 represents the permission of the owner (-w- which means write permission only).

1.chmod:- used to change the permission of the file  

Permission can be changed in a file by two methods

a.Relative permission.
b.Absolute permission.

a.Relative permission:-

ex:- chmod g+x,o+r filename

Which means change the permissions of the file such that group have additional executable permission and others have additonal read permission of the file.

The file after the permission change would look like


-rwxrwxrw-    1 anik unixsizzlers     217 Jun 26 14:08 filename

b.Absolute permission:-

ex:- chmod 776 filename

where 4=read permission
2=write permission
1=executable permission

Which means change the permissions of the file such that group have additional executable permission and others have additonal read permission of the file.


The file after the permission change would look like


-rwxrwxrw-    1 anik unixsizzlers     217 Jun 26 14:08 filename

2.chown:- change the ownership of the file

ex:- chown newowner filename; ls -ltr filename

The ownership of the file would change from anik to newowner.


The file after the ownership change would look like


-rwxrw--w-    1 newowner unixsizzlers     217 Jun 26 14:08 filename

2.chgrp:- change the group of the file

ex:- chgrp unixtutorial filename; ls -ltr filename

The group  of the file would change from unixsizzlers to unixtutorial.


The file after the group change would look like


-rwxrw--w-    1 anik unixtutorial 217 Jun 26 14:08 filename

No comments:

Post a Comment