umask


it's a built-in command used to set the default permission of a file. By default, umask value is 022. This value directly affects the default value of files.

Let's check out -


$umask
0022
$mkdir check_perm_dir

$ls -l | grep check_perm_dir
drwxr-xr-x  2 pinku  guest   512 Jan 14 10:50 check_perm_dir
$umask 033
$umask
0033
$mkdir change_umask_dir
$ls -l | grep change_umask_dir
drwxr--r--  2 pinku  guest   512 Jan 14 10:54 change_umask_dir
$


whenever we create one directory, it default permission would be (drwxr-xr-x) 755 untill and unless we change the umask default value 022. So umask value is going to be subtracted from file values - 777 for directories and 666 for normal files. so it will be the outcome for the default value for directories 755 and for ordinary files 644.


let's check out for ordinary files:


$umask
0022
$umask 666
$umask
0666
$touch umaskfile_check
$ls -l umaskfile_check
----------  1 pinku  guest  0 Jan 14 11:14 umaskfile_check
$







chown

"change owner of a file"


This is used to transfer ownership of a file to other user. This change require a user ID of the user to whom you want to transfer the file ownership and super user permission (ID and password) for yourself to run this command.  


Syntax:

chown [option] username filename


Example:

$su vikas
Password:


$ls -l file5
-rw-r--r--  3 pinku  guest  52 Dec 25 00:10 file5
$chmod 777 file5
$ls -l file5
-rwxrwxrwx  3 pinku  guest  52 Dec 25 00:10 file5
$chown jessica file5

$ls -l file5
-rwxrwxrwx  3 jessica  guest  52 Dec 25 00:10 file5







chgrp

"change group of a file"


This is used to change group ownership of a file to other group. This change also require a user ID of the user to whom you want to transfer the file ownership and super user permission (ID and password) for yourself to run this command. 


Syntax: chgrp [option] groupname filename

Example:

$su vikas
Password:

$ls -l file5
-rwxrwxrwx  3 jessica  guest  52 Dec 25 00:10 file5
$chgrp developer file5
$ls -l file5
-rwxrwxrwx  3 jessica  developer  52 Dec 25 00:10 file5


NEXT ->

Cracking IT Interview