Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8525353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:57:15+00:00 2026-06-11T07:57:15+00:00

I am writing a bash script to update some files/directories and I want to

  • 0

I am writing a bash script to update some files/directories and I want to run umask in the script to set default permissions for files/directories created by the script. I know I can umask to set the permissions for both files and directories however I need the permissions to be different for files and folders.

I want files to be:   -rw----r-- (0604)
I want folders to be: drwx-----x (0701)

Can I do this using umask? If so how do I go about doing it? If not what is the best way to achieve it? Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:57:16+00:00Added an answer on June 11, 2026 at 7:57 am

    Interesting requirement. Currently (at least in bash), umask is a global setting and you cannot set it based on object type.

    One solution that comes to mind would be to set the umask to the file variant and then intercept calls to mkdir (such as with a user-created mkdir script earlier in the path) to do:

    umask 0701 ; /path/to/real/mkdir $1 ; umask 0604
    

    That way, assuming all your directory creations are done with mkdir, you can ensure they use a different umask setting.

    Note that the script should probably be a little more robust such as restoring the previous umask rather than forcing it to 0604, and adding some better error checking and possibly the ability to handle multiple arguments.

    But that’s all detail, the framework above should be enough to get you started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing some BASH script and I want it have some error handling
I'm writing a bash script that I want by default to output everything into
I am writing a Bash script to set some environment variables and then start
I am writing a bash script that calls some apps that run in their
I am writing a bash script, and I would like to know which files
I'm writing a bash script and I have errexit set, so that the script
I am writing a bash script that is supposed to do some confirmation and
I'm writing a Bash script that prints some text to the screen: echo Some
I am writing a bash script to run an integration test of a tool
I'm writing a bash script to get some podcasts. The problem is that some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.