Ask Dave Taylor
  • Facebook
  • Instagram
  • Linkedin
  • Pinterest
  • Twitter
  • YouTube
  • Home
  • YouTube Videos
  • Top Categories
  • Subscribe via Email
  • Ask A Question
  • Meet Dave
  • Home
  • Linux Help
  • Can you explain exactly how umask works in Unix and Linux?

Can you explain exactly how umask works in Unix and Linux?

December 21, 2004 / Dave Taylor / Linux Help / 7 Comments

Dave, I know you can’t solve trivial questions for everyone, but if you could have someone help me with the umask command and the content on pp. 107-109 of your book Teach Yourself Unix is 24 Hours, I’d appreciate it. I’ve taken two hours to try to figure out how in the world umask 277 produces a read-only file. It seems to me it would be write only. Can you shed some light on this, please?

Thanks for your note. Your quesiton isn’t trivial (but if it were, I’d suggest you pop over to the fun site Trivial.Net, but that’s another story entirely!)

In terms of umask, you need to look at things backwards…

When you see a umask of 277 it’s the same as a pattern of -x- xxx xxx, right?

Now, since it’s a umask you need to INVERT that to figure out how it turns into an actual permission string. That makes it x-x — —.

To make this a bit more complex, remember that the touch command shown in the book example that’s stumped you can only give you read or write permissions, so that’s kinda/sorta another mask.

All that’s left is r– — — and that’s exactly what permission you get.

Here’s the actual example out of the book that you’re asking about:

$ umask 277
$ touch testfile.277
$ ls -l testfile.277
-r--------  1 taylor  staff  0 16 Dec 22:44 testfile.277
$

Got it now?

Let’s Stay In Touch!

Never miss a single article, review or tutorial here on AskDaveTaylor, sign up for my fun weekly newsletter!
Name: 
Your email address:*
Please enter all required fields
Correct invalid entries
No spam, ever. Promise. Powered by FeedBlitz
Please choose a color:
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you, Dave, for all your helpful information by buying you a cup of coffee!

7 comments on “Can you explain exactly how umask works in Unix and Linux?”

  1. Paul says:
    November 4, 2009 at 10:49 pm

    The thing to remember about umask, is it’s a mask and not a ‘setting’
    chmod creates a setting.
    umask just specifies the ‘bits’ you can’t have!
    So if you have a program ‘touch’ for example, it is going to try and create a file naturally with 666 as its permissions #rw-,rw-,rw-#
    umask, essentually, tells ‘touch’ to hang on a minute, it can’t have#assuming 022# write on groups and world, so you end up with, rw-,r–,r–

    Reply
  2. Dave Taylor says:
    September 4, 2007 at 8:37 am

    By default, programs set the minimum logical permissions when it comes to execute: if you “vi test” it’ll be a read-write file you create, it’ll never create an executable file. Other than manually using “chmod” the only programs I know that create *executable* files are compilers and the like.

    Reply
  3. Abrar Ahmad says:
    September 4, 2007 at 8:09 am

    Let me tell you what I am exactly doing on my system.
    # umask 0022
    # touch test
    # vi test2
    And this is the long listing of my files
    -rw-r–r– 1 root root 44 Sep 4 19:32 test
    -rw-r–r– 1 root root 6 Sep 4 19:32 test2
    As you can see i am still unable to achieve desired default permissions for my newly created files which should be rwxr–r–(755)
    I quickly went through an online reference for this but truly speaking i need somebody to explain it to me with an example.
    http://en.wikipedia.org/wiki/Umask

    Reply
  4. Dave Taylor says:
    September 4, 2007 at 6:45 am

    umasks are always the opposite of what you want, so if you want to end up with 755 then you need to use 022 as the mask. 0+7 = 7, 5 + 2 = 7, etc.

    Reply
  5. Abrar Ahmad says:
    September 4, 2007 at 3:36 am

    This is again regarding umask. Suppose i want my new file to have 755 pemissions. What should be the umask in this case now and most importantly how to calculate it?

    Reply
  6. Sasha says:
    May 7, 2007 at 3:55 pm

    kjteoh ,thank you for good explanation!You shoud write book learn Linux in 12 hours 😉

    Reply
  7. kjteoh says:
    August 5, 2005 at 2:15 pm

    The octal level for Linux starts at 666. The magic numbers to remember are-
    4 2 1
    r w x
    4+2+1 = 7 = rwx
    4+0+1 = 5 = r-x
    hence
    4+2+0 = 6 = rw-
    If you have a file with -rwx rwx rwx then you must have the octals 777 to match.
    If your file is -rwx r-x r-x then the octals that match are 755
    Now that we understand that we look at umask.
    We start with a base figure of
    666
    -022
    644 = rw- r– r–
    You will see your default umask level or setting in the /etc/profile file … most of the time.
    Some sysadmins will alter it to something stricter to help ensure more privacy between users ie 066 or 026
    kjteoh

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Recent Posts

  • How Do I Download Movies & Shows from HBOMax.com?
  • Can I Calculate Mortgage Payments with Online Tools?
  • How Do I Find Available Disk Space on my Mac System?
  • How to Identify Plants and Flowers with Google Lens on Android?
  • Windows Security Wants Me to Enable “App & Browser Control”?

On Our YouTube Channel

Catalyst Total Protection Apple Watch & AirPods Case -- INSTALL & REVIEW

Acer Chromebook 317 -- Budget 17.3" Laptop -- REVIEW

Categories

  • AdSense, AdWords, and PPC Help (106)
  • Amazon, eBay, and Online Shopping Help, (161)
  • Android Help (197)
  • Apple iPad Help (144)
  • Apple Watch Help (52)
  • Articles, Tutorials, and Reviews (344)
  • Auto Tech Help (11)
  • Business Advice (199)
  • Chrome OS Help (23)
  • Computer & Internet Basics (763)
  • d) None of the Above (165)
  • Facebook Help (383)
  • Google, Chrome & Gmail Help (177)
  • HTML & Web Page Design (245)
  • Instagram Help (47)
  • iPhone & iOS Help (605)
  • iPod & MP3 Player Help (173)
  • Kindle & Nook Help (92)
  • LinkedIn Help (85)
  • Linux Help (164)
  • Linux Shell Script Programming (86)
  • Mac & MacOS Help (891)
  • Most Popular (16)
  • Outlook & Office 365 Help (24)
  • PayPal Help (69)
  • Pinterest Help (53)
  • Reddit Help (17)
  • SEO & Marketing (81)
  • Spam, Scams & Security (92)
  • Trade Show News & Updates (23)
  • Twitter Help (217)
  • Video Game Tips (66)
  • Web Site Traffic Tips (62)
  • Windows PC Help (915)
  • Wordpress Help (204)
  • Writing and Publishing (72)
  • YouTube Help (46)
  • YouTube Video Reviews (159)
  • Zoom, Skype & Video Chat Help (56)

Archives

Social Connections:

Ask Dave Taylor


Follow Me on Pinterest
Follow me on Twitter
Follow me on LinkedIn
Follow me on Instagram


AskDaveTaylor on Facebook



microsoft insider mvp


This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this site or on any linked site. Further, please note that by submitting a question or comment you're agreeing to our terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site. Our lawyer says "Thanks for your cooperation."
© 2022 by Dave Taylor. "Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.
Privacy Policy - Terms and Conditions - Accessibility Policy