Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
07-13-2003, 09:03 PM
|
#1
|
Member
Registered: Mar 2003
Posts: 105
Rep:
|
chmod and umask
I need to change permissions for some folders and files but I do not get how the octal number representation work. Also how do you use umask with fstab file?
|
|
|
07-13-2003, 09:09 PM
|
#2
|
LQ Guru
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613
Rep:
|
Here's the best I've ever seen on an explanation:
http://www.linuxquestions.org/questi...threadid=25234
Cool
|
|
|
07-13-2003, 09:39 PM
|
#3
|
Senior Member
Registered: Feb 2001
Location: Montreal, Quebec, Canada
Distribution: RedHat, Fedora, CentOS, SUSE
Posts: 1,403
Rep:
|
|
|
|
07-13-2003, 10:03 PM
|
#4
|
Senior Member
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571
Rep:
|
Here, this was fun. See if it helps. Corrections, more explanations welcome:
(i hope this formatting works.)
Code:
8+4+2+1 = 15 = 8+4+2+1
- - - - - -- - - - - -
0 0 0 0 = 00 = 0+0+0+0
0 0 0 1 = 01 = 0+0+0+1
0 0 1 0 = 02 = 0+0+2+0
0 0 1 1 = 03 = 0+0+2+1
0 1 0 0 = 04 = 0+4+0+0
0 1 0 1 = 05 = 0+4+0+1
0 1 1 0 = 06 = 0+4+2+0
0 1 1 1 = 07 = 0+4+2+1
1 0 0 0 = 08 = 8+0+0+0
1 0 0 1 = 09 = 8+0+0+1
1 0 1 0 = 10 = 8+0+2+0
1 0 1 1 = 11 = 8+0+2+1
1 1 0 0 = 12 = 8+4+0+0
1 1 0 1 = 13 = 8+4+0+1
1 1 1 0 = 14 = 8+4+2+0
1 1 1 1 = 15 = 8+4+2+1
Chop off the '8' part and:
owner group others
4-2-1 4-2-1 4-2-1 (value)
r w x r w x r w x (mode)
Examples:
chmod 444
--4-- --4-- --4--
4+0+0 4+0+0 4+0+0
1 0 0 1 0 0 1 0 0
r - - r - - r - -
chmod 744
--7-- --4-- --4--
4+2+1 4+0+0 4+0+0
1 1 1 1 0 0 1 0 0
r w x r - - r - -
chmod 665
--6-- --6-- --5--
4+2+0 4+2+0 4+0+1
1 1 0 1 1 0 1 0 1
r w - r w - r - x
etc...
.
Code:
[bsl1@localhost bsl1]$ chmod 444 test.txt
[bsl1@localhost bsl1]$ ls -l test.txt
-r--r--r-- 1 bsl1 bsl1 15 Jul 13 21:13 test.txt
[bsl1@localhost bsl1]$ chmod 744 test.txt
[bsl1@localhost bsl1]$ ls -l test.txt
-rwxr--r-- 1 bsl1 bsl1 15 Jul 13 21:13 test.txt
[bsl1@localhost bsl1]$ chmod 665 test.txt
[bsl1@localhost bsl1]$ ls -l test.txt
-rw-rw-r-x 1 bsl1 bsl1 15 Jul 13 21:13 test.txt
Code:
umask:
subtract the 'values' in the umask columns from 777
to get the default permission set for directories
(not sure about the deal with files):
[bsl1@localhost bsl1]$ umask
0002
[bsl1@localhost bsl1]$ mkdir zzz
[bsl1@localhost bsl1]$ ls -ld zzz
drwxrwxr-x 2 bsl1 bsl1 4096 Jul 13 21:13 zzz
(default)
-----rwx-rwx-rwx
0777 (7) (7) (7)
-----111 111 111 (4+2+1)(4+2+1)(4+2+1)
----------------
0002 (0) (0) (2) (umask)(minus)
----------------
0775 (7) (7) (5)
-----111 111 101 (4+2+1)(4+2+1)(4+0+1)
-----rwx rwx r-x
Isn't this fun!
Last edited by itsjustme; 07-13-2003 at 10:38 PM.
|
|
|
07-13-2003, 10:59 PM
|
#5
|
Senior Member
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571
Rep:
|
If you can get your mind around the relationship of '4 2 1' with the mode bits 'r w x' as I posted above, then you don't need to do all that adding of 400 200 100 40 20 10 4 2 1.
It's the bit relationships, not the actual value in the hundreds.
regards...
|
|
|
07-14-2003, 03:54 PM
|
#6
|
Senior Member
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571
Rep:
|
More that I just learned about umask from:
Introduction to Linux
A Hands on Guide
Machtelt Garrels
CoreSequence.com
<tille@coresequence.com>
Version 3.0.2 Last updated 20030228 Edition
"...before the mask is applied, a directory has permissions 777 or rwxrwxrwx, a plain file 666 or
rw−rw−rw−.
The umask value is substracted from these default permissions after the function has created the new file or
directory. Thus, a directory will have permissions of 775 by default, a file 664, if the mask value is (0)002."
|
|
|
07-16-2003, 08:21 AM
|
#7
|
Member
Registered: Jul 2003
Posts: 34
Rep:
|
Hi,
I'm using linux the first time and trying to understand the permission.
The permission i have for my newly created directory and file is different. My default umask is 0022. I'm wondering why the umask value shown in my pc is having 4 digits instead of the standard 3 digit 022? And using 777 to minus away 022 should be 755. But both my directory and file does not have the permission of 755 as shown below. Appreciate if anyone can kindly explain to me...
[root@cm]# mkdir directory
[root@cm]# ls -ld directory
drwxr-xr-x 2 root root 4096 Jul 16 20:17 directory
[root@cm]# touch file.c
[root@cm]# ls -ld file.c
-rw-r--r-- 1 root root 0 Jul 16 20:18 file.c
[root@cm]# umask
0022
|
|
|
07-16-2003, 08:56 AM
|
#8
|
LQ Newbie
Registered: Jul 2003
Location: Kerala
Posts: 5
Rep:
|
Hello itsjustme:
Your small piece of tutorial was wonderful and fun.
Thank you for posting it, and do continue with it.
Mons...
|
|
|
07-16-2003, 09:52 AM
|
#9
|
Senior Member
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,637
Rep:
|
Quote:
Originally posted by lido
...
The permission i have for my newly created directory and file is different. My default umask is 0022. I'm wondering why the umask value shown in my pc is having 4 digits instead of the standard 3 digit 022? And using 777 to minus away 022 should be 755. But both my directory and file does not have the permission of 755 as shown below. Appreciate if anyone can kindly explain to me...
[root@cm]# mkdir directory
[root@cm]# ls -ld directory
drwxr-xr-x 2 root root 4096 Jul 16 20:17 directory
[root@cm]# touch file.c
[root@cm]# ls -ld file.c
-rw-r--r-- 1 root root 0 Jul 16 20:18 file.c
[root@cm]# umask
0022
|
Please read post #6 carefully again .
drwxr-xr-x
d4+2+1, 4+1, 4+1 = 7,5,5 = 7,7,7 - 0,2,2
-rw-r--r--
-4+2, 4, 4 = 6,4,4 = 6,6,6 - 0,2,2
Okay?
Last edited by JZL240I-U; 07-16-2003 at 10:09 AM.
|
|
|
07-16-2003, 09:58 AM
|
#10
|
Senior Member
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571
Rep:
|
Here is a link to that Introduction to Linux
Go down to " 3.4.2.2. The file mask" and check that out. You can ignore the first 0 in 0022 for this.
lido, 755 is rwxr-xr-x .
Touch just changes the file time stamp. What do you get when you create a new file? Should be 0666 - 0022 = 0644 = rw-r--r-- (oh, which is what you do have for file.c).
Directory default before umask = 777
File default, before umask = 666
(according to that Introduction to Linux book.)
(rwx)(r-x)(r-x) = (4+2+1)(4+0+1)(4+0+1) = 755 = 777 - 022
(rw-)(r--)(r--) = (4+2+0)(4+0+0)(4+0+0) = 644 = 666 - 022
I think I'm right, therefore I am.
regards...
Edit: Oh, hey, thanks JZL240I-U .
Last edited by itsjustme; 07-16-2003 at 10:09 AM.
|
|
|
07-16-2003, 10:13 AM
|
#11
|
Senior Member
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,637
Rep:
|
Quote:
Originally posted by itsjustme
I think I'm right, therefore I am.
Edit: Oh, hey, thanks JZL240I-U
|
I like that one. And you are wellcome
|
|
|
07-16-2003, 10:42 AM
|
#12
|
Member
Registered: Jul 2003
Posts: 34
Rep:
|
I understand now.
Thank you very much for your explanation. You guys are fantastic!!!!
|
|
|
07-16-2003, 11:19 AM
|
#13
|
Member
Registered: Jun 2003
Location: Delaware
Distribution: Redhat 7.0, 7.2, 8.0, 9.0, FreeBSD 4.6.2
Posts: 51
Rep:
|
Wow...
That's a topic that's really difficult to explain properly...and you guys did an excellent job. I'm very, very impressed!
|
|
|
07-16-2003, 11:54 AM
|
#14
|
Senior Member
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571
Rep:
|
Re: chmod and umask
OOPS....
Quote:
Originally posted by InsaneBob
Also how do you use umask with fstab file?
|
For me, I'll have to do some more research to find the answer to that...
|
|
|
07-16-2003, 12:31 PM
|
#15
|
LQ Guru
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613
Rep:
|
Umask is just chmod reversed. Count backwards from 7, so for a umask of 7 you would use 0. For 6, you would use 1, and so on:
0 : 7
1 : 6
2 : 5
3 : 4
4 : 3
5 : 2
6 : 1
7 : 0
And as a side note:
Happy Birthday ItsJustMe!
Cool
|
|
|
All times are GMT -5. The time now is 01:16 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|