File Permissions
All the three owners (user owner, group, others) in the Linux system have three types of permissions defined. Nine characters denotes the three types of permissions.
- Read (r) : The read permission allows you to open and read the content of a file. But you can't do any editing or modification in the file.
- Write (w) : The write permission allows you to edit, remove or rename a file. For instance, if a file is present in a directory, and write permission is set on the file but not on the directory, then you can edit the content of the file but can't remove, or rename it.
- Execute (x): In Unix type system, you can't run or execute a program unless execute permission is set.But in Windows, there is no such permission available.
--------------------------------------------------------------------------------------------------------------------
permission on a file on a directory
--------------------------------------------------------------------------------------------------------------------
r (read) read file content (cat) read directory content (ls)
w (write) change file content (vi) create file in directory (touch)
x (execute) execute the file enter the directory (cd)
--------------------------------------------------------------------------------------------------------------------
position characters ownership
--------------------------------------------------------------------------------------------------------------------
1 - denotes file type
2-4 rw- permission for user
5-7 rw- permission for group
8-10 r-- permission for other
-rw-r--r-- 12 linuxize users 12.0K Apr 28 10:10 file_name
|[-][-][-]- [------] [---]
| | | | | | |
| | | | | | +-----------> 7. Group
| | | | | +-------------------> 6. Owner
| | | | +--------------------------> 5. Alternate Access Method
| | | +----------------------------> 4. Others Permissions
| | +-------------------------------> 3. Group Permissions
| +----------------------------------> 2. Owner Permissions
+------------------------------------> 1. File Type
-rw-r--r-- 1 haritaraka12078 haritaraka12078 125 Jun 9 13:52 StudentMarks
[haritaraka12078@cxln4 ~]$ chmod u+x StudentMarks
[haritaraka12078@cxln4 ~]$ ls -l StudentMarks
-rwxr--r-- 1 haritaraka12078 haritaraka12078 125 Jun 9 13:52 StudentMarks
[haritaraka12078@cxln4 ~]$ chmod u-w StudentMarks
[haritaraka12078@cxln4 ~]$ ls -l StudentMarks
-r-xr--r-- 1 haritaraka12078 haritaraka12078 125 Jun 9 13:52 StudentMarks
[haritaraka12078@cxln4 ~]$ chmod +w exm.txt
[haritaraka12078@cxln4 ~]$ ls -l exm.txt
-rw-r--r-- 1 haritaraka12078 haritaraka12078 94 Jun 8 06:17 exm.txt
[haritaraka12078@cxln4 ~]$ chmod o=rw exm.txt
[haritaraka12078@cxln4 ~]$ ls -l exm.txt
-rw-r--rw- 1 haritaraka12078 haritaraka12078 94 Jun 8 06:17 exm.txt
[haritaraka12078@cxln4 ~]$ chmod u=rwx,g=rw,o=r exm.txt
[haritaraka12078@cxln4 ~]$ ls -l exm.txt
-rwxrw-r-- 1 haritaraka12078 haritaraka12078 94 Jun 8 06:17 exm.txt
--------------------------------------------------------------------------------------------------------------------
Setting Octal Permissions
--------------------------------------------------------------------------------------------------------------------
Octal permissions can also be set for the groups.
For example, to set r octal will be 4, to set w octal will be 2, to set x octal will be 1.
Octal Table:
--------------------------------------------------------------------------------------------------------------------
binary octal permissions
--------------------------------------------------------------------------------------------------------------------
000 0 ---
001 1 --x
010 2 -w-
011 3 -wx
100 4 r--
101 5 r-x
110 6 rw-
111 7 rwx
777 = rwxrwxrwx
765 = rwxrw-r-x
654 = rw-r-xr--
[haritaraka12078@cxln4 ~]$ mkdir -m 777 new1
[haritaraka12078@cxln4 ~]$ ls -ltr
drwxrwxrwx 2 haritaraka12078 haritaraka12078 4096 Jun 9 15:16 new1