1819902 Members
2154 Online
109607 Solutions
New Discussion юеВ

file permissions (umask)

 
SOLVED
Go to solution
Eli Daniel
Super Advisor

file permissions (umask)

hi,
i have the problem whe generate file.
the user dbeadm generate flie new wiht permissions 660. i need generate the new file wiht 770.

the file system where generate file is NFS.

how cant generate new flie wiht permissions 770?
change umask user dbeadm?
add line command in the .profile?

thanks for you comments....
13 REPLIES 13
Dennis Handly
Acclaimed Contributor
Solution

Re: file permissions (umask)

>I need generate the new file with 770.

You can not, unless you are copying a file with that permission. By default, only directories can be created with execute permission. Otherwise only ld creates files with execute permission. All others must be changed with chmod(1).

>how can generate new file with permissions 770?

Why would you want files created that way? The only files like that would be scripts and it is better if you deliberately use chmod to make sure that's what you want.
Eli Daniel
Super Advisor

Re: file permissions (umask)

hi dennis
exist document for HP where specify what you say?
The NFS is other operation system.
Bill Hassell
Honored Contributor

Re: file permissions (umask)

The documentation is in the umask man page (hint: man umask). All files have a default permission of 666 and umask subtracts permission, for example, umask 002 means file will have 660 permissions when created.

You do NOT want every file to have 770 permission. 660 is the proper permission for all files *except* for scripts. Making every file 770 means that typing the name of the file will cause the shell to run it as a script even when it contains data and this could create a big problem.

If you are writing a script, you save the file along with the interpreter line (first line in the script) and then change the permission to 770 for that one script.

If you have read where permission problems are solved by changing everything to 777, please scrap that book and get a quality book on Unix and shells.


Bill Hassell, sysadmin
James R. Ferguson
Acclaimed Contributor

Re: file permissions (umask)

Hi Eli:

> exist document for HP where specify what you say?

In addition to looking at the 'umask(1)' manpages as suggested, look at the manpages for the 'creat(2)' system call. This is where the 'mode' is given if you look at the code that creates a file (or directory). As already stated, for files, most programs (including the shell) use 0666 as the mode's value. This parameter determines the "most liberal" permission bits. It is to this initial value that the process's 'umask' is applied when the process goes to create a file. With a 'umask' of 000 the file thus created has permissions of 0666 too. Unless you would modify the source code and recompile the binary executable, you're stuck with this default.

Regards!

...JRF...
Patrick Wallek
Honored Contributor

Re: file permissions (umask)

>>All files have a default permission of 666
>>and umask subtracts permission, for example,
>>umask 002 means file will have 660
>>permissions when created.

I'm sure just a typo by Bill, but 666 - umask 002 = 664 permissions.

To yield 660 permissions you would need a umask of 006.

Bill Hassell
Honored Contributor

Re: file permissions (umask)

> Patrick: yep, you're right. The 2 and the 6 are so close to each other on the keyboard. :-) Since umask is a 'take-away', umask 006 or 007 will product the same results for a simple file.


Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: file permissions (umask)

>exist document for HP where specify what you say?

Other than umask(1) and creat(2) I don't think there is any documentation saying that the creat(2) default mode is 0666 for files and 0x777 for directories. This is just a UNIX convention.
In C++ iostreams, you can actually see the default value expressed as 0666.

A previous thread with a similar request:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1275381913104+28353475&threadId=1006891

>Patrick: but 666 - umask 002 = 664

Or use:
typeset -i8 x=$(( 8#666 & ! 8#002 )); echo $x
Dennis Handly
Acclaimed Contributor

Re: file permissions (umask)

Oops, typo: 0666 for files and 0777 for directories
Eli Daniel
Super Advisor

Re: file permissions (umask)

but no HP documents where you clarify?
only in the manual and create umask?
Bill Hassell
Honored Contributor

Re: file permissions (umask)

>> but no HP documents where you clarify?
>> only in the manual and create umask?

HP documents? Where do you think the man pages came from? Do you see this line:

Hewlett-Packard Company - 1 - HP-UX 11i Version 3 Feb 2007

on all the manpages? If you want to buy a book, get copies of Marty Poniatowski's books on HP-UX, or read this manual:

http://docs.hp.com/en/B2355-90164/ch07s08.html

This isn't something unique to HP-UX. I am not aware of any version of Unix that does not follow these rules for files and umask.


Bill Hassell, sysadmin
James R. Ferguson
Acclaimed Contributor

Re: file permissions (umask)

Hi (again):

> but no HP documents where you clarify?
only in the manual and create umask?

What's wrong with the *HP-UX* manpages for 'creat(2)' and for 'umask(1)'? The behavior is ubiquitous to Unix.

Regards!

...JRF...
Eli Daniel
Super Advisor

Re: file permissions (umask)

thanks for information
Dennis Handly
Acclaimed Contributor

Re: file permissions (umask)

>JRF: The behavior is ubiquitous to Unix.

Yes but it's not obvious where to find a statement that EVERY command uses 666 to create new files.