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?
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–
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.
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
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.
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?
kjteoh ,thank you for good explanation!You shoud write book learn Linux in 12 hours 😉
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