Showing posts with label Default permission of file and directory in Linux / UNIX. Show all posts
Showing posts with label Default permission of file and directory in Linux / UNIX. Show all posts

Friday 25 December 2015

Default permission of file and directory in Linux / UNIX

What is UMASK

UMASK (User Mask or User file creation MASK) is the default permission of file and directory in Linux or UNIX. There are three types of permission for every file and directory (read, write and execute) for three types of user (Owner, Groups and Others).

[wasi@saidrasel ~]]$ mkdir cde
[wasi@saidrasel ~]]$ touch abc
[wasi@saidrasel ~]$ ls -l abc
-rw-rw-r--. 1 wasi wasi 0 Dec 26 11:12 abc

In the above example

  • User (wasi) has read,write permission
  • Group has read, write permission
  • Others have read permission

Three file permissions:

read: permission to read the contents of file.
write: permission to write to the file.
execute: permission to execute the file as a program/script.

Three directory permissions:

read: permission to read the contents of directory ( view files and sub-directories in that directory ).
write: permission to write in to the directory. ( create files and sub-directories in that directory )
execute: permission to enter into that directory.

Numeric values for the read, write and execute permissions:
read--4
write--2
execute--1

[wasi@saidrasel ~]$ ls -l abc
-rw-rw-r--. 1 wasi wasi 0 Dec 26 11:12 abc
drwxrwxr-x. 2 wasi wasi 6 Dec 26 11:31 cde

So the numeric value permission for this file is-- 4+2 4+2 4 --->664
and the numeric value permission for the directory is-- 4+2+1 4+2+1 4+1 --->775

Umask is responsible for the default permission

[wasi@saidrasel ~]$ umask
0002
[wasi@saidrasel ~]$

Final default permission for a file is calculated as shown below:

Default file permission: 666
Default umask : 002
Final default file permission: 664 (666-002)

Final default permission for a directory is calculated as shown below:

Default directory permission: 777
Default umask: 002
Final default directory permission: 775 (777-002)

We can find umask value setting from /etc/bashrc or /etc/profile