1752679 Members
5096 Online
108789 Solutions
New Discussion юеВ

Re: umask

 
SOLVED
Go to solution
Macho_2
Frequent Advisor

umask

How to read the umask setting like 022,027,0002 and 0113. Please explain the umask setting in the following format or any other easy way.
rwx--x-wx
15 REPLIES 15
Ivan Krastev
Honored Contributor

Re: umask

This may be useful - http://en.wikipedia.org/wiki/Umask


regards,
ivan
rariasn
Honored Contributor

Re: umask

Hi,

Sample use "umask".

$ umask 077
$ umask --> 077
$ umask -S --> u=rwx,g=,o=

$ man umask

rgs,
D Block 2
Respected Contributor

Re: umask

try this one:
cd /tmp
mkdir fun_umask
cd fun_umask
umask 022
touch file_with_022
ls -l file_with_022

grep umask /etc/profile

what is your systems default umask ?

now try this one:

umask 0
touch file_with_000
ls -l file_with_000

why did HP-UX provide the default umask settings ? A well known security hole, that's why..

the "touch" command provides a simple method of calling the system call function: creat().. using the umask(1) setting from the parent shell.

let me know if you need more lessons here..

best of luck and of couse we expect points, right :-)
Golf is a Good Walk Spoiled, Mark Twain.
Patrick Wallek
Honored Contributor
Solution

Re: umask

First, you must remember the default modes used to create files and directories. The default permissions for a file are -rw-rw-rw- (666) and directories drwxrwxrwx (777).

Now the umask "subtracts" (kinda sorta, but not really, but enough for this explanation) the umask bits from the default permissions.

So:

Example 1:

umask = 022

You create a file:

default perms 666 minus umask 022 = permissions on file of 644 (-rw-r--r--).

You create a directory:

default perms 777 minus umask 022 = permissions of 755 (drwxr-xr-x)


Example 2:

umask = 027

You create a file:
666 - 027 = 640 (-rw-r-----)

Create a dir:

777 - 027 = 750 (drwxr-x---)

If the umask has 4 digits, you can drop the leading 0 (as long as its a 0).
Raj D.
Honored Contributor

Re: umask

Macho,

For example you have umask set to 022, so when a file is created by default it gets (666-022) permission i.e 642 .

if you hav umask set to 000 , so the default file permission will be 666-000 = 666

umask on file and directory differs,

for
file = (666-umask value)
dir = (777-umask value)

Now the number convention to rwx

r w x
Owner: 400 200 100
Group: 40 20 10
Other: 4 2 1
-------------------------

So Umask 022 will provide default file creation permission to ( 666-022) = 644
i.e -rw-rw----


Hope this will help,
Cheers,


Raj.

" If u think u can , If u think u cannot , - You are always Right . "
D Block 2
Respected Contributor

Re: umask

Macho,

7 7 7
111 111 111

rwx rwx rwx

chmod 777 myfile

: provides mode 777

this assumes your umask is set to ZERO or 000

umask 000
touch myfile
ls -l myfile

mode of file is 777 or rwx-rwx-rwx

x = 1
w = 2
r = 4
=====
7

Golf is a Good Walk Spoiled, Mark Twain.
Patrick Wallek
Honored Contributor

Re: umask

Raj,

Sorry, but NO. 666 - 022 = 644 which = -rw-r--r-- (try it and see!)

The numerical notations are:

(r)ead = 4
(w)rite = 2
e(x)ecute = 1

This is the same for user/owner, group and other/world.

So rwxrwxrwx = 421 421 421 = 777 (if you add each triplet together).

With the chmod command you can use 'chmod 755 file' or 'chmod u=rwx,go=rx file' to grant rwxr-xr-x permissions to a file. u=user (or owner), g=group and o=other (or world). The chmod man page explains this. (I know you didn't ask about chmod, but I'm hoping this will help you understand.)
D Block 2
Respected Contributor

Re: umask

Macho, back to my math lesson..

if you have mode:

7 7 7

and umask is set (set to > 000), then you subtract.

example:

$ umask 022

math:
7 7 7
-
0 2 2
=====

well, the first 0 value might be interesting here.. what result do you get ?

try this one:

umask 022
touch file_junk
ls -l file_junk

do you get:
rwx-rx-rx

or

766

given: rwx = 7
rx = 5 (r=4 + x=1) = 5

again: rwx is simply the math of:
r = 4
w = 2
x = 1
=====
total 7
Golf is a Good Walk Spoiled, Mark Twain.
D Block 2
Respected Contributor

Re: umask

sorry, my math is a little off

umask 0
touch file
mode is 7 7 7
or
rwx rwx rwx

umask 022
touch file2
mode is 755 <--- note 755

or
rwx r x r x
not group write, not others write

best of luck and thanks for being a member here !!
Golf is a Good Walk Spoiled, Mark Twain.