1838192 Members
4414 Online
110125 Solutions
New Discussion

Re: PUNKED BY UMASK

 
millsm
Advisor

PUNKED BY UMASK

Why is it that both users below have the same umask but when they make a file they get different permissions. check it out below. Thanks in advance....

millsm@ngbva (/home/millsm)$umask
022
millsm@ngbva (/home/millsm)$umask -S
u=rwx,g=rx,o=rx
millsm@ngbva (/home/millsm)$> test
millsm@ngbva (/home/millsm)$ll test
-rw-rw-r-- 1 comp comp 0 Mar 7 14:32 test

comp@ngbva (/comp)$umask -S
u=rwx,g=rx,o=rx
comp@ngbva (/comp)$umask
022
comp@ngbva (/comp)$> test
comp@ngbva (/comp)$ll test
-rw-r--r-- 1 comp comp 0 Mar 7 14:20 test
10 REPLIES 10
A. Clay Stephenson
Acclaimed Contributor

Re: PUNKED BY UMASK

Best guess. In the first case, the file "test" already existed and had 664 mode and in the second case "test" did not exist.

rm both files first and repeat your test.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: PUNKED BY UMASK

Hi:

This could easily be explained if your file already existed. The redirection simply truncates (sets the file's end-of-file pointer) to the beginning but does nothing to the permissions.

Consider:

# cd /tmp
# umask 022
# touch me
# ls -l me
-rw-r--r-- 1 root sys 0 Mar 7 14:44 me
# chmod 664 me
# ls -l me
-rw-rw-r-- 1 root sys 0 Mar 7 14:44 me
# > me
# ls -l me
-rw-rw-r-- 1 root sys 0 Mar 7 14:45 me

Regards!

...JRF...
Court Campbell
Honored Contributor

Re: PUNKED BY UMASK

can you post the output from

ll -d /comp
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
millsm
Advisor

Re: PUNKED BY UMASK

drwxrwxrwx 30 comp comp 26624 Mar 7 13:26 /comp

This is the output
millsm
Advisor

Re: PUNKED BY UMASK

riddle me this... you guys are right... if you write over a file it gets differnt permissions... this is crazy... why?
James R. Ferguson
Acclaimed Contributor

Re: PUNKED BY UMASK

Hi:

> if you write over a file it gets differnt permissions... this is crazy... why?

The redirection operator ('>') _truncates_ and existing file. That is, the file's end-of-file pointer is set to offset-0 (as if nothing had been written). The existing file is not removed and hence no permission bits are setup as when a file is created.

Regards!

...JRF...
Patrick Wallek
Honored Contributor

Re: PUNKED BY UMASK

No, it doesn't get different permissions, the permissions stay the same.

Try re-running your test, but make sure you remove the 'test' file BEFORE doing the '> test'. I think you will see the results you are expecting.
A. Clay Stephenson
Acclaimed Contributor

Re: PUNKED BY UMASK

riddle me this... you guys are right... if you write over a file it gets differnt permissions... this is crazy... why?

It's not crazy; it's behaving exactly as documented. It's crazy to assume that the shell behaves as you expect rather than how it is documented.
If it ain't broke, I can fix that.
millsm
Advisor

Re: PUNKED BY UMASK

tnx
James R. Ferguson
Acclaimed Contributor

Re: PUNKED BY UMASK

Hi (again):

Welcome, as a new member to the community. If you haven't already, please see:

http://forums1.itrc.hp.com/service/forums/helptips.do?#28

Regards!

...JRF...