LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 03-19-2010, 11:05 AM   #1
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Rep: Reputation: 85
chmod octal numbers


Is there an easy way to remember what the each of the 8 numbers, 0-7 represent for chmod and umask? That way I would not have to keep guessing until I get it right.
 
Old 03-19-2010, 11:27 AM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by fakie_flip View Post
Is there an easy way to remember what the each of the 8 numbers, 0-7 represent for chmod and umask? That way I would not have to keep guessing until I get it right.
in short -
wrt chmod, simplest way to remember apart from doing all the binary stuff is

r=4
w=2
x=1


the stat command will give a helping hand here..... stat <file>
with umask an example is

000 = creation of folders with 777 perms (rwxrwxrwx)
creation of files 666 (rw-rw-rw)

777 = creation of folders 000 perms (---------)
and same with files

Last edited by centosboy; 03-19-2010 at 11:33 AM.
 
Old 03-19-2010, 11:31 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Yes. Think at permissions:
Code:
-rwxrwxrwx
as numbers
Code:
-421421421
each set of permissions (user, group, other) is given by the sum of the three numbers. So that (just some examples):
Code:
-rw-------  is 4+2 0 0 = 600
-rwxr-xr-x  is 4+2+1 4+1 4+1 = 755
-rw-r--r--  is 4+2 4 4 = 644
The umask is the reverse and you have to subtract permissions from 777 one digit at a time, for example:
Code:
               777 -
permissions:   755 =
---------------------
umask:         022
Edit: too late... sorry for redundancy!
 
Old 03-24-2010, 01:26 PM   #4
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Original Poster
Rep: Reputation: 85
Thanks.

Now I know I only have to remember that r=4, w=2, x=1, and I can figure out the rest with simple addition.
 
Old 03-24-2010, 07:28 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
In fact you can use the symbolic notation ie rwx for chmod and umask; I always do. There is no difference for chmod, but for umask, you quote the protections you want instead of the reverse ie no subtraction involved.
http://linux.die.net/man/1/umask
 
Old 03-27-2010, 03:03 AM   #6
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Original Poster
Rep: Reputation: 85
Cool

Quote:
Originally Posted by chrism01 View Post
In fact you can use the symbolic notation ie rwx for chmod and umask; I always do. There is no difference for chmod, but for umask, you quote the protections you want instead of the reverse ie no subtraction involved.
http://linux.die.net/man/1/umask
I am aware, but I like using octal numbers, maybe because I'm a computer nerd plus it's shorter to write.

One thing I have to remember when using rwx for chmod is that 'o' does not stand for owner. It stands for other. I've often made that mistake. It's easy to do. Even the man page for chmod says this.

"A combination of the letters ugoa controls which users' access to the
file will be changed: the user who owns it (u)"

Code:
chris@ubuntu910:/tmp$ touch test{1,2}
chris@ubuntu910:/tmp$ chmod u+r,u-wx,g+w,g-rx,o+x,o-rw test1
chris@ubuntu910:/tmp$ ls -l test1 
-r---w---x 1 chris chris 0 2010-03-27 02:50 test1
chris@ubuntu910:/tmp$ chmod 421 test2 
chris@ubuntu910:/tmp$ ls -l test2 
-r---w---x 1 chris chris 0 2010-03-27 02:50 test2
chris@ubuntu910:/tmp$
See how much shorter and simpler to write the command using octal numbers is? Now that I know that figuring out octal numbers for permissions can be found using simple addition rather than memorizing, I find it much easier.

Last edited by fakie_flip; 03-27-2010 at 03:05 AM.
 
Old 03-29-2010, 01:24 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You don't write it that way:

chmod u=r,g=w,o=x filename

some people find letters (user, group, other), (read, write, exe) easier than nums. Its just personal preference.
I can do either...
 
Old 03-31-2010, 10:54 AM   #8
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Original Poster
Rep: Reputation: 85
Quote:
Originally Posted by chrism01 View Post
You don't write it that way:

chmod u=r,g=w,o=x filename

some people find letters (user, group, other), (read, write, exe) easier than nums. Its just personal preference.
I can do either...
Shows how little I use it. This thread is about the octal numbers.
 
Old 03-31-2010, 11:00 AM   #9
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I prefer octal.

Anyway, reading about the binary system could help you understand it better.
 
  


Reply



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
Sticky Bit? (ie: chmod 2770 vs chmod 770) JeffC1 Linux - Newbie 7 03-18-2010 07:39 AM
Apache: difference between chmod 644 and chmod 666 and chmod 600 for output/txt/dat? frenchn00b Programming 6 04-22-2009 01:10 PM
sequence of numbers, how to extract which numbers are missing jonlake Programming 13 06-26-2006 03:28 AM
chmod, external usb, vfat - can't chmod a directory itsjustme Slackware 2 04-02-2006 04:23 PM
C, read 8 bit octal numbers, convert to 24 bit binary bamalabs Programming 3 01-20-2004 09:59 AM

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

All times are GMT -5. The time now is 10:17 PM.

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