
Can you explain exactly how umask works in Unix and Linux?
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?
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon
Categorized:
Unix and Linux Help
(Article 3820)
Tagged: Previous: Can I crack a password protected Microsoft Word file? Next: How do I validate my Web HTML pages? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. The octal level for Linux starts at 666. The magic numbers to remember are- 4 2 1 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 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 Posted by: kjteoh at August 5, 2005 2:15 PMkjteoh ,thank you for good explanation!You shoud write book learn Linux in 12 hours ;) Posted by: Sasha at May 7, 2007 3:55 PMThis 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? Posted by: Abrar Ahmad at September 4, 2007 3:36 AMumasks 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. Posted by: Dave Taylor at September 4, 2007 6:45 AMLet me tell you what I am exactly doing on my system. # umask 0022 And this is the long listing of my files -rw-r--r-- 1 root root 44 Sep 4 19:32 test 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 Posted by: Abrar Ahmad at September 4, 2007 8:09 AMBy 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. Posted by: Dave Taylor at September 4, 2007 8:37 AMThe thing to remember about umask, is it's a mask and not a 'setting' chmod creates a setting. 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-- Posted by: Paul at November 4, 2009 10:49 PMI have a lot to say, but ...
I do have a comment, now that you mention it!
|
![]()
Search
Find just the answers you seek from among our 2300+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Industry News and Trade Shows Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Book Links
|