Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I knew that there is a diffrence between umask of folders and umask of files
and i found the umask value of folder in /etc/bashrc and i can control it but i can't find the umask of files
You should read some documents on how masks and premission works.
I can give you a short summary:
1 = x
2 = w
4 = r
So as you can se, we add this up, so that
rwx = 1+2+4 = 7
rw- = 2+4 = 6
r-x = 1+4 = 5
-wx = 1+2 = 3
r-- = 4, -w- = 2, --x = 1
--- = 0
Then we use the same order, ugo. If we want to make rwxrw-r--, then we use this tabel (Or our heads as this is easy math ) and get 764. So insted of using:
chmod u=rwx,g=rw,o=r <file>
we use:
chmod 764 <file>
This is a training matter, and is pretty easy after a while
In your case, 3 = 1 + 2 = -wx, wich is rather useless. Good luck
Thanks alot for your help and i got a summry for this from RHCE book
but I;m sorry i don't understand the permission of file
let's say it is rwxrwxrwx = 4+2+1 = 777 and you said for file is only 666
Last edited by sophisticate; 01-09-2008 at 08:19 AM.
That is because files and folders have different needs.
To access a folder, you need it to be executable, but it's a bad idea to have every file +x as default. Therefor it makes perfect sense to use 777 for folders and 666 for files. Try it out with different umasks. And again, I recommend you to read some documents on permissions.
Edit:
777 and 666 is just the starting point from where the rights are calculated. I can give a little example:
To have every permission on something, we use umask 000
For a folder that would be: 777, or rwx for ugo.
For a file it would be 666, or rw for ugo.
Note that umask are used when we create new files, and we would not want new files to be +x as default. We can still set the execute flag manually.
I was wondering about the values
r = 4
w = 2
x = 1
------
rwx 7 this make sence for directory but for file rwx should equal to 6
so the rwx have diffrent values than 421
No, you are confusing permissions with umask. Umask are only used when you create new files. And umask are the inverted value of the permissions.
When you decide what umask to use, you first look at what you want. If you want rw-r----- as default FILE mask, you calculate the octal value for that permission. In this case it is:
4+2+0 4+0+0 0+0+0 = 642. Since your start with a file, you subtract this from 666
666 - 640 = 026, this is your umask.
With this umask newly created files will get permission as described earlier and folders will get:
777 - 026 = 751, rwxr-x--x
On the other hand, if you want to use a folder as starting point, you figure out what rights you want the folders to have, if you want i.e. rwxr-x---, the octal value is:
4+2+1 4+0+1 0+0+0 = 750, subtract this from 777 (Since we now use folder as a starting point)
777 - 750 = 027, this is the NEW umask.
With this umask our new folders will get the desired permission (rwxr-x---). New FILES will now get this permission:
666 - 027 = 640 (They can't be -1), and would be printed as rw-r-----.
Now we got the same file permission as the first example, and that is just a coincidence, since we cant have a negative value. Try it out with different permissions/umask and create files/folders to understand it correctly.
So as we can see, there is no perfect solution. We can't have rwxrwxrwx for folders and rw-r--r-- for files, there have to be a compromise between one or the other.
I will say it again. Umask are ONLY used when you create a new file. You can modify permission as you pleases after the file/folder is created using chmod.
I'm very thankful for your explaination it's perfectly clear now and i red about umask and permission and i know most of that but the misunderstanding was in how to compromise between file and direcotry and as you explained the perfect solution up till now is chmod
No, you are confusing permissions with umask. Umask are only used when you create new files. And umask are the inverted value of the permissions.
When you decide what umask to use, you first look at what you want. If you want rw-r----- as default FILE mask, you calculate the octal value for that permission. In this case it is:
4+2+0 4+0+0 0+0+0 = 642. Since your start with a file, you subtract this from 666
666 - 640 = 026, this is your umask.
With this umask newly created files will get permission as described earlier and folders will get:
777 - 026 = 751, rwxr-x--x
On the other hand, if you want to use a folder as starting point, you figure out what rights you want the folders to have, if you want i.e. rwxr-x---, the octal value is:
4+2+1 4+0+1 0+0+0 = 750, subtract this from 777 (Since we now use folder as a starting point)
777 - 750 = 027, this is the NEW umask.
With this umask our new folders will get the desired permission (rwxr-x---). New FILES will now get this permission:
666 - 027 = 640 (They can't be -1), and would be printed as rw-r-----.
Now we got the same file permission as the first example, and that is just a coincidence, since we cant have a negative value. Try it out with different permissions/umask and create files/folders to understand it correctly.
So as we can see, there is no perfect solution. We can't have rwxrwxrwx for folders and rw-r--r-- for files, there have to be a compromise between one or the other.
I will say it again. Umask are ONLY used when you create a new file. You can modify permission as you pleases after the file/folder is created using chmod.
Hi ! Your examples are simple and clear
But I have a question.
If umask = 333 then I calculate that NEW FILES get permission 666-333 = 333 i.e. wxwxwx. But when I check on my machine I see that NEW FILES get permission -r--r--r--. Where is my mistake ?
Thats a really good question. As that permission is rather useless, I have never used that one before. I think however that there is some kind of exception, as the umask is "useless". It's no good idea to have only wx to a file.
Hi ! Your examples are simple and clear
But I have a question.
If umask = 333 then I calculate that NEW FILES get permission 666-333 = 333 i.e. wxwxwx. But when I check on my machine I see that NEW FILES get permission -r--r--r--. Where is my mistake ?
I think you're not wrong.
The way Dinithion is calculating the permission is not correct. You should not use the decimal to subtract. For a umask of 333, you are basically having
021 user
021 group
021 other
, transform it to 'BIT' concept, it will be:
off on on -user
off on on -group
off on on -other
, and then since this is a umask, revert it to become your file permission:
on off off -user
on off off -group
on off off -other
, and transform it back to 'decimal' concept, it will be:
400 user
400 group
400 other
, which make sense you are having -r--r--r-- for the files you created.
It's funny that when Dinithion is keep on asking people to read some doc on how this works and as if he knows a lot, but in fact he is teaching people a wrong way of the knowledge. And if one is already asking question here, we shouldn't ask people to read the manual again. If one already know, he wouldn't be desperately finding solution here. So please stop asking people to 'read more docs', to me that is arrogant. Just my humble opinion. Thanks.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.