Different Umask for Directories and Files

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












How can I set up a different umask for directories then files?



I need dirs with umask 003 and files with umask 117










share|improve this question





















  • Sorry, there's just one umask. BTW, 003 for directories seems weird: why would you allow other-read, but not other-execute? That will allow listing the directory, but not accessing any of the files in it.
    – Barmar
    Jan 13 '17 at 16:39














up vote
2
down vote

favorite












How can I set up a different umask for directories then files?



I need dirs with umask 003 and files with umask 117










share|improve this question





















  • Sorry, there's just one umask. BTW, 003 for directories seems weird: why would you allow other-read, but not other-execute? That will allow listing the directory, but not accessing any of the files in it.
    – Barmar
    Jan 13 '17 at 16:39












up vote
2
down vote

favorite









up vote
2
down vote

favorite











How can I set up a different umask for directories then files?



I need dirs with umask 003 and files with umask 117










share|improve this question













How can I set up a different umask for directories then files?



I need dirs with umask 003 and files with umask 117







umask






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 13 '17 at 16:34









Luigi T.

88210




88210











  • Sorry, there's just one umask. BTW, 003 for directories seems weird: why would you allow other-read, but not other-execute? That will allow listing the directory, but not accessing any of the files in it.
    – Barmar
    Jan 13 '17 at 16:39
















  • Sorry, there's just one umask. BTW, 003 for directories seems weird: why would you allow other-read, but not other-execute? That will allow listing the directory, but not accessing any of the files in it.
    – Barmar
    Jan 13 '17 at 16:39















Sorry, there's just one umask. BTW, 003 for directories seems weird: why would you allow other-read, but not other-execute? That will allow listing the directory, but not accessing any of the files in it.
– Barmar
Jan 13 '17 at 16:39




Sorry, there's just one umask. BTW, 003 for directories seems weird: why would you allow other-read, but not other-execute? That will allow listing the directory, but not accessing any of the files in it.
– Barmar
Jan 13 '17 at 16:39










2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










umask is global in bash. One thing you could do is to create a mkdir wrapper(a script, you give the name to it) that would change the mask after executing it.



#!/bin/bash
umask 0701 ; /path/to/real/mkdir $1 ; umask 0604


This was answered here:



  • StackOverflow - Set Different Umask For Files And Folders

Remember: For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666, meaning, you will not achieve execute permissions on file creation inside your shell even if the umask allows. This is clearly done to increase security on new files creation.



Example:



[admin@host test]$ pwd
/home/admin/test
[admin@host test]$ umask
0002
[admin@host test]$ mkdir test
[admin@host test]$ touch test_file
[admin@host test]$ ls -l
total 4
drwxrwxr-x 2 admin admin 4096 Jan 13 14:53 test
-rw-rw-r-- 1 admin admin 0 Jan 13 14:53 test_file


umask Unix Specification tells nothing about this file permission math specifics. It's up to the shell developers to decide(and OS makers).






share|improve this answer






















  • umask is per process, but inherited, rather than global. In the wrapper script there is no need to reset the umask after the real mkdir has completed, it will just cange the umask for the shell running the script, which is just about to exit anyway. Removing the umask will allow the return code of the real mkdir, as an extra bonus.
    – icarus
    Jan 13 '17 at 20:03

















up vote
0
down vote













Please note the mkdir command has a -m option to set the permission bits at creation time:



 -m mode
Set the file permission bits of the final created directory to the specified mode. The mode argument can be in any of the for-
mats specified to the chmod(1) command. If a symbolic mode is specified, the operation characters ``+'' and ``-'' are inter-
preted relative to an initial mode of ``a=rwx''.


in your case you could set the umask to whatever you need for the permissions of your files, and use the -m option for the folder creation.





share








New contributor




bla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f337182%2fdifferent-umask-for-directories-and-files%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote



    accepted










    umask is global in bash. One thing you could do is to create a mkdir wrapper(a script, you give the name to it) that would change the mask after executing it.



    #!/bin/bash
    umask 0701 ; /path/to/real/mkdir $1 ; umask 0604


    This was answered here:



    • StackOverflow - Set Different Umask For Files And Folders

    Remember: For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666, meaning, you will not achieve execute permissions on file creation inside your shell even if the umask allows. This is clearly done to increase security on new files creation.



    Example:



    [admin@host test]$ pwd
    /home/admin/test
    [admin@host test]$ umask
    0002
    [admin@host test]$ mkdir test
    [admin@host test]$ touch test_file
    [admin@host test]$ ls -l
    total 4
    drwxrwxr-x 2 admin admin 4096 Jan 13 14:53 test
    -rw-rw-r-- 1 admin admin 0 Jan 13 14:53 test_file


    umask Unix Specification tells nothing about this file permission math specifics. It's up to the shell developers to decide(and OS makers).






    share|improve this answer






















    • umask is per process, but inherited, rather than global. In the wrapper script there is no need to reset the umask after the real mkdir has completed, it will just cange the umask for the shell running the script, which is just about to exit anyway. Removing the umask will allow the return code of the real mkdir, as an extra bonus.
      – icarus
      Jan 13 '17 at 20:03














    up vote
    3
    down vote



    accepted










    umask is global in bash. One thing you could do is to create a mkdir wrapper(a script, you give the name to it) that would change the mask after executing it.



    #!/bin/bash
    umask 0701 ; /path/to/real/mkdir $1 ; umask 0604


    This was answered here:



    • StackOverflow - Set Different Umask For Files And Folders

    Remember: For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666, meaning, you will not achieve execute permissions on file creation inside your shell even if the umask allows. This is clearly done to increase security on new files creation.



    Example:



    [admin@host test]$ pwd
    /home/admin/test
    [admin@host test]$ umask
    0002
    [admin@host test]$ mkdir test
    [admin@host test]$ touch test_file
    [admin@host test]$ ls -l
    total 4
    drwxrwxr-x 2 admin admin 4096 Jan 13 14:53 test
    -rw-rw-r-- 1 admin admin 0 Jan 13 14:53 test_file


    umask Unix Specification tells nothing about this file permission math specifics. It's up to the shell developers to decide(and OS makers).






    share|improve this answer






















    • umask is per process, but inherited, rather than global. In the wrapper script there is no need to reset the umask after the real mkdir has completed, it will just cange the umask for the shell running the script, which is just about to exit anyway. Removing the umask will allow the return code of the real mkdir, as an extra bonus.
      – icarus
      Jan 13 '17 at 20:03












    up vote
    3
    down vote



    accepted







    up vote
    3
    down vote



    accepted






    umask is global in bash. One thing you could do is to create a mkdir wrapper(a script, you give the name to it) that would change the mask after executing it.



    #!/bin/bash
    umask 0701 ; /path/to/real/mkdir $1 ; umask 0604


    This was answered here:



    • StackOverflow - Set Different Umask For Files And Folders

    Remember: For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666, meaning, you will not achieve execute permissions on file creation inside your shell even if the umask allows. This is clearly done to increase security on new files creation.



    Example:



    [admin@host test]$ pwd
    /home/admin/test
    [admin@host test]$ umask
    0002
    [admin@host test]$ mkdir test
    [admin@host test]$ touch test_file
    [admin@host test]$ ls -l
    total 4
    drwxrwxr-x 2 admin admin 4096 Jan 13 14:53 test
    -rw-rw-r-- 1 admin admin 0 Jan 13 14:53 test_file


    umask Unix Specification tells nothing about this file permission math specifics. It's up to the shell developers to decide(and OS makers).






    share|improve this answer














    umask is global in bash. One thing you could do is to create a mkdir wrapper(a script, you give the name to it) that would change the mask after executing it.



    #!/bin/bash
    umask 0701 ; /path/to/real/mkdir $1 ; umask 0604


    This was answered here:



    • StackOverflow - Set Different Umask For Files And Folders

    Remember: For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666, meaning, you will not achieve execute permissions on file creation inside your shell even if the umask allows. This is clearly done to increase security on new files creation.



    Example:



    [admin@host test]$ pwd
    /home/admin/test
    [admin@host test]$ umask
    0002
    [admin@host test]$ mkdir test
    [admin@host test]$ touch test_file
    [admin@host test]$ ls -l
    total 4
    drwxrwxr-x 2 admin admin 4096 Jan 13 14:53 test
    -rw-rw-r-- 1 admin admin 0 Jan 13 14:53 test_file


    umask Unix Specification tells nothing about this file permission math specifics. It's up to the shell developers to decide(and OS makers).







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 23 '17 at 12:39









    Community♦

    1




    1










    answered Jan 13 '17 at 16:48









    nwildner

    13.5k14073




    13.5k14073











    • umask is per process, but inherited, rather than global. In the wrapper script there is no need to reset the umask after the real mkdir has completed, it will just cange the umask for the shell running the script, which is just about to exit anyway. Removing the umask will allow the return code of the real mkdir, as an extra bonus.
      – icarus
      Jan 13 '17 at 20:03
















    • umask is per process, but inherited, rather than global. In the wrapper script there is no need to reset the umask after the real mkdir has completed, it will just cange the umask for the shell running the script, which is just about to exit anyway. Removing the umask will allow the return code of the real mkdir, as an extra bonus.
      – icarus
      Jan 13 '17 at 20:03















    umask is per process, but inherited, rather than global. In the wrapper script there is no need to reset the umask after the real mkdir has completed, it will just cange the umask for the shell running the script, which is just about to exit anyway. Removing the umask will allow the return code of the real mkdir, as an extra bonus.
    – icarus
    Jan 13 '17 at 20:03




    umask is per process, but inherited, rather than global. In the wrapper script there is no need to reset the umask after the real mkdir has completed, it will just cange the umask for the shell running the script, which is just about to exit anyway. Removing the umask will allow the return code of the real mkdir, as an extra bonus.
    – icarus
    Jan 13 '17 at 20:03












    up vote
    0
    down vote













    Please note the mkdir command has a -m option to set the permission bits at creation time:



     -m mode
    Set the file permission bits of the final created directory to the specified mode. The mode argument can be in any of the for-
    mats specified to the chmod(1) command. If a symbolic mode is specified, the operation characters ``+'' and ``-'' are inter-
    preted relative to an initial mode of ``a=rwx''.


    in your case you could set the umask to whatever you need for the permissions of your files, and use the -m option for the folder creation.





    share








    New contributor




    bla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      0
      down vote













      Please note the mkdir command has a -m option to set the permission bits at creation time:



       -m mode
      Set the file permission bits of the final created directory to the specified mode. The mode argument can be in any of the for-
      mats specified to the chmod(1) command. If a symbolic mode is specified, the operation characters ``+'' and ``-'' are inter-
      preted relative to an initial mode of ``a=rwx''.


      in your case you could set the umask to whatever you need for the permissions of your files, and use the -m option for the folder creation.





      share








      New contributor




      bla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



















        up vote
        0
        down vote










        up vote
        0
        down vote









        Please note the mkdir command has a -m option to set the permission bits at creation time:



         -m mode
        Set the file permission bits of the final created directory to the specified mode. The mode argument can be in any of the for-
        mats specified to the chmod(1) command. If a symbolic mode is specified, the operation characters ``+'' and ``-'' are inter-
        preted relative to an initial mode of ``a=rwx''.


        in your case you could set the umask to whatever you need for the permissions of your files, and use the -m option for the folder creation.





        share








        New contributor




        bla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        Please note the mkdir command has a -m option to set the permission bits at creation time:



         -m mode
        Set the file permission bits of the final created directory to the specified mode. The mode argument can be in any of the for-
        mats specified to the chmod(1) command. If a symbolic mode is specified, the operation characters ``+'' and ``-'' are inter-
        preted relative to an initial mode of ``a=rwx''.


        in your case you could set the umask to whatever you need for the permissions of your files, and use the -m option for the folder creation.






        share








        New contributor




        bla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.








        share


        share






        New contributor




        bla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 3 mins ago









        bla

        1




        1




        New contributor




        bla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        bla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        bla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f337182%2fdifferent-umask-for-directories-and-files%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?