LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 07-13-2003, 09:03 PM   #1
InsaneBob
Member
 
Registered: Mar 2003
Posts: 105

Rep: Reputation: 15
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?
 
Old 07-13-2003, 09:09 PM   #2
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Rep: Reputation: 69
Here's the best I've ever seen on an explanation:
http://www.linuxquestions.org/questi...threadid=25234

Cool
 
Old 07-13-2003, 09:39 PM   #3
Mathieu
Senior Member
 
Registered: Feb 2001
Location: Montreal, Quebec, Canada
Distribution: RedHat, Fedora, CentOS, SUSE
Posts: 1,403

Rep: Reputation: 46
A small tutorial on how to Setup Permissions
http://www.realitywebs.com/unix/permissions.shtml
 
Old 07-13-2003, 10:03 PM   #4
itsjustme
Senior Member
 
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571

Rep: Reputation: 47
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.
 
Old 07-13-2003, 10:59 PM   #5
itsjustme
Senior Member
 
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571

Rep: Reputation: 47
Quote:
Originally posted by Mathieu
A small tutorial on how to Setup Permissions
http://www.realitywebs.com/unix/permissions.shtml
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...
 
Old 07-14-2003, 03:54 PM   #6
itsjustme
Senior Member
 
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571

Rep: Reputation: 47
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."
 
Old 07-16-2003, 08:21 AM   #7
lido
Member
 
Registered: Jul 2003
Posts: 34

Rep: Reputation: 15
Smile

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
 
Old 07-16-2003, 08:56 AM   #8
Mons
LQ Newbie
 
Registered: Jul 2003
Location: Kerala
Posts: 5

Rep: Reputation: 0
Hello itsjustme:
Your small piece of tutorial was wonderful and fun.
Thank you for posting it, and do continue with it.
Mons...
 
Old 07-16-2003, 09:52 AM   #9
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,637

Rep: Reputation: Disabled
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.
 
Old 07-16-2003, 09:58 AM   #10
itsjustme
Senior Member
 
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571

Rep: Reputation: 47
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.
 
Old 07-16-2003, 10:13 AM   #11
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,637

Rep: Reputation: Disabled
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
 
Old 07-16-2003, 10:42 AM   #12
lido
Member
 
Registered: Jul 2003
Posts: 34

Rep: Reputation: 15
Thumbs up

I understand now.

Thank you very much for your explanation. You guys are fantastic!!!!
 
Old 07-16-2003, 11:19 AM   #13
Rumblefish
Member
 
Registered: Jun 2003
Location: Delaware
Distribution: Redhat 7.0, 7.2, 8.0, 9.0, FreeBSD 4.6.2
Posts: 51

Rep: Reputation: 15
Wow...

That's a topic that's really difficult to explain properly...and you guys did an excellent job. I'm very, very impressed!
 
Old 07-16-2003, 11:54 AM   #14
itsjustme
Senior Member
 
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571

Rep: Reputation: 47
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...
 
Old 07-16-2003, 12:31 PM   #15
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Rep: Reputation: 69
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
chmod + umask for a whole dir tree Ephracis Linux - Security 2 08-15-2005 07:55 PM
What can we do if we type chmod ugo-x /bin/chmod ?????? bunny123 Linux - Software 3 02-01-2005 09:53 PM
umask chmod?? blackzone Linux - Newbie 3 01-11-2005 02:50 AM
CHMOD in shell : chmod 777 /usr/ <---is that right? cpanelskindepot Programming 5 07-16-2004 06:37 AM
file perm, chgrp, chmod, and umask Martini Linux - Newbie 2 08-06-2002 09:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration