LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   umask chmod?? (https://www.linuxquestions.org/questions/linux-newbie-8/umask-chmod-276398/)

blackzone 01-11-2005 01:09 AM

umask chmod??
 
my umask shows the following:

> umask
0022


my question is when I create a file

> touch file; ls -al

the file permision is 644??

I thought the file should be permission 777-022 = 755 ??

Dark_Helmet 01-11-2005 01:32 AM

The execute permissions are only given to execute-capable files. It makes no sense to try and run a file you've only touch'ed. It's the same thing with text editors like vi, emacs, nano, etc. You're creating a text file, and it makes no sense to execute a text file. The exception would be scripts, but there's no way the text editor can know if you're writing plain text or a script. So, I suspect the decision to set file attributes is embedded in the program somewhere. If you want to see an example of what you were expecting, do this:

in file hello.c:
Code:

#include <stdio.h>

int main( int argc, char *argv[] )
{
  printf( "Hello world.\n" );
  return 0;
}

from a prompt:
Code:

gcc -o hello hello.c
ls -al

You'll see the hello binary listed with 755 permissions.

foo_bar_foo 01-11-2005 01:35 AM

now this is a good question (lke you care what i think ;) )
traditionally standard utils like touch when they create files create them 0666
here is some code from an ancient unix V7 version of touch
Code:

if( (fd = creat(name, 0666)) < 0)
                goto bad;
 close(fd);

from modern Linux coreutils-5.2.1
Code:

if (! no_create)
    {
      /* Try to open FILE, creating it if necessary.  */
      fd = open (file, O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY,
                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);

S_IRUSR = 00400
S_IWUSER = 00200
and you can extrapolate the rest
so it's still the same 00666 as it's always been

Berhanie 01-11-2005 01:50 AM

default permissions are 666 for files and 777 for directories. umask is subtracted from those.


All times are GMT -5. The time now is 12:31 PM.