LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 10-28-2016, 03:24 AM   #1
leeondet
LQ Newbie
 
Registered: Oct 2016
Posts: 3

Rep: Reputation: Disabled
Changing permissions with chmod (numbers)


Hi,

I am unsure how the following command #chmod 755 file, results in the permission: rwxr-xr-x

My understanding is that you have a 9 bit permission and you add up numbers (r=4, w=2, x=1)) to set each of the 3 parts of the permission(owner, group, and others)

I would have thought that the permission 755 would read rwx-xr-xr not rwxr-xr-x

I am new to Linux and this is an example in the Linux bible 9th edition, page 111.

Thanks,

Lee
 
Old 10-28-2016, 04:07 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,423
Blog Entries: 3

Rep: Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788
The grouping is a little different: rwx r-x r-x

The first triplet is for the first octal number.
The middle triplet is for the middle octal number.
The last triplet is for the last octal number.

So the letters have to be grouped that way.
 
1 members found this post helpful.
Old 10-28-2016, 05:48 AM   #3
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 364Reputation: 364Reputation: 364Reputation: 364
Welcome! Great book! (I just got it from library today!)

For example, in your last 3 characters (perm. mode for 'others'; same for 'group')
where you guessed "-xr",
you have the right idea: no w=no2, an x=1, and an r=4 (your order, but not Linux's!)
but `ls -l` specifically 'reports' them in a particular order:
first: an r or - if no4, then second: a w or - if no2, then third: an x or - if no1,
so, to put it in a [strange] Y/N way: 5=binary101=YNY is reported as "r-x".

By the way, you'll see the owner called "user" and referred to as 'u',
to leave the 'o' for "other", on the next page in that book ['ugo']
(owner=User vs. Other/world can get confusing too)

Enjoy reading! Best wishes! (p.s. What 'distro' do you use? PC/boot?)

Last edited by Jjanel; 10-28-2016 at 06:19 AM.
 
1 members found this post helpful.
Old 10-28-2016, 10:24 AM   #4
linux4evr5581
Member
 
Registered: Sep 2016
Location: USA
Posts: 275

Rep: Reputation: Disabled
[7=rwx|6=rw-|5=r-x|4=r--|3=-wx|2=-w-|1=--x] Just so you know the numerical version of chmod is for setting permissions absolutely, and should used when creating new files. The letter version adds or subtracts permissions as opposed to setting absolute values, for example:

chmod ugo+rwx or chmod u-rw or chmod u=rwx,g=rwx,o=rwx or a=rwx (a means all)

chmod -R ugo-rwx * (revokes all permissions for the current directory aswell as its sub directories), chmod ugo= * (revokes all permissions for all files in the current directory, but not the current directory its sub directories)

Last edited by linux4evr5581; 10-28-2016 at 10:38 AM.
 
1 members found this post helpful.
Old 10-28-2016, 10:32 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,423
Blog Entries: 3

Rep: Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788
Quote:
Originally Posted by linux4evr5581 View Post
[7=rwx|6=rw-|5=r-x|4=r--|3=-wx|2=-w-|1=--x] Just so you know the numerical version of chmod is for setting permissions absolutely, and should used when creating new files. The letter version adds or subtracts permissions as opposed to setting absolute values, for example:
chmod ugo+rwx or chmod u-rw or chmod u=rwx,g=rwx,o=rwx or a=rwx (a means all)
At the risk of scaring with a short shell script, it is possible to view all the permissions minus the sticky bit, the SetGUID bit, and the SetUID bit using some loops:

Code:
#!/bin/bash

temp=$(mktemp || exit);

touch $temp;

{ 
    for o in {0..7}; do 
        for g in {0..7}; do 
            for u in {0..7}; do 

                chmod $u$g$o $temp; 
                echo chmod $u$g$o : $(stat --printf "%A" $temp); 

            done; 
        done; 
    done; 
} | less  

rm -f $temp;
 
Old 10-28-2016, 10:46 AM   #6
linux4evr5581
Member
 
Registered: Sep 2016
Location: USA
Posts: 275

Rep: Reputation: Disabled
Sounds useful, I have no idea how to read that but I get the idea
 
Old 10-28-2016, 10:59 AM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,423
Blog Entries: 3

Rep: Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788
"stat" is the useful part there, if only one part should be highlighted.

Code:
man stat
 
Old 10-28-2016, 11:04 AM   #8
linux4evr5581
Member
 
Registered: Sep 2016
Location: USA
Posts: 275

Rep: Reputation: Disabled
stat as in status I guess.. I really need to lean shell scripting, sed, awk and all that, im just so overwhelmed with everything else computer related. But one day...
 
Old 10-28-2016, 11:38 AM   #9
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,890
Blog Entries: 13

Rep: Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934
Quote:
Originally Posted by leeondet View Post
My understanding is that you have a 9 bit permission and you add up numbers (r=4, w=2, x=1)) to set each of the 3 parts of the permission(owner, group, and others)

I would have thought that the permission 755 would read rwx-xr-xr not rwxr-xr-x
Hi and Welcome to LQ!

Pretty much all of the answers given are valid, not changing them. However please look at how your perceived this because even I got confused with your thinking.

"Weighting is r=4, w=2, x=1" - Yes, that's fine.

But you interpreted 755 to mean rwx -xr -xr. By the convention you mentioned, w=2 and x=1, well that adds up to 3. I believe this is where you confused yourself, right from the get-go.
 
Old 10-28-2016, 02:53 PM   #10
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
binary octal sets. AKA 3 bit groups.

000 000 000 == 000
111 111 111 == 777

421 421 421
rwx rwx rwx

r+x == 4+1 == 5
r+w+x == 4+2+1 == 7

Most chmod setups let you use the +x and similar flags now instead of doing the math. Although the math is more predictable and definitive.
 
1 members found this post helpful.
Old 10-28-2016, 04:29 PM   #11
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by rtmistler View Post
But you interpreted 755 to mean rwx -xr -xr. By the convention you mentioned, w=2 and x=1, well that adds up to 3. I believe this is where you confused yourself, right from the get-go.
He still has the letters write, x and r for 5, he just rearranged them, putting "-xr" instead of "r-x".

OP - the order in the permissions is ALWAYS "r w x", in that order, no exceptions. If the bit is set, you put the letter, if it's not, you put a "-". "5" is "4+1", which means r (read) and x (execute) are set, while w (write) is not, so you would write it as "r-x". That's not "r minus x" or "r and x", it's "r <blank> x", where <blank> would be "w", if "w" was set. Similarly, permission 0 is written "---", permission 1 is written "--x", permission 2 is written "-w-", and so on.

Last edited by suicidaleggroll; 10-28-2016 at 04:32 PM.
 
1 members found this post helpful.
Old 10-28-2016, 09:18 PM   #12
leeondet
LQ Newbie
 
Registered: Oct 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks for taking the time to respond. It makes sense now that i know that there is a specific order that can not be changed, and that the permission is represented by a letter for on, or a dash for off. I was viewing the dash as a separator rather than an indicator of a permission.

Last edited by leeondet; 10-28-2016 at 09:20 PM.
 
Old 10-28-2016, 09:22 PM   #13
leeondet
LQ Newbie
 
Registered: Oct 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi Jjanel, i'm using Fedora workstation 24 and just booting it from a USB stick at the moment. I want to work through the book before deciding whether to completely change over from Windows
 
Old 10-29-2016, 12:04 AM   #14
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 364Reputation: 364Reputation: 364Reputation: 364
Cool! Maybe I can 'sell' you dozens of free&EASY&safe VirtualBox'es, with DistroWatch's .iso

Looking forward to your next question! Best Wishes... (p.s. what computer do you use?)

Last edited by Jjanel; 10-29-2016 at 12:06 AM.
 
  


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: changing permissions mm_kanish05 Linux - Software 1 06-24-2012 01:08 AM
Problems changing file and directory permissions using chmod southwlm Linux - Newbie 4 03-29-2012 02:57 PM
chmod: changing permissions of `public_html': Operation not permitted painterj Linux - Newbie 11 04-09-2010 09:40 PM
Changing permissions (chmod) teyesahr Linux - Newbie 1 07-31-2003 04:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:20 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