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 |
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.
|
 |
10-28-2016, 03:24 AM
|
#1
|
LQ Newbie
Registered: Oct 2016
Posts: 3
Rep: 
|
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
|
|
|
10-28-2016, 04:07 AM
|
#2
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
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.
|
10-28-2016, 05:48 AM
|
#3
|
Member
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
|
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.
|
10-28-2016, 10:24 AM
|
#4
|
Member
Registered: Sep 2016
Location: USA
Posts: 275
Rep: 
|
[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.
|
10-28-2016, 10:32 AM
|
#5
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
Quote:
Originally Posted by linux4evr5581
[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;
|
|
|
10-28-2016, 10:46 AM
|
#6
|
Member
Registered: Sep 2016
Location: USA
Posts: 275
Rep: 
|
Sounds useful, I have no idea how to read that but I get the idea
|
|
|
10-28-2016, 10:59 AM
|
#7
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
"stat" is the useful part there, if only one part should be highlighted.
|
|
|
10-28-2016, 11:04 AM
|
#8
|
Member
Registered: Sep 2016
Location: USA
Posts: 275
Rep: 
|
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...
|
|
|
10-28-2016, 11:38 AM
|
#9
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,968
|
Quote:
Originally Posted by leeondet
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.
|
|
|
10-28-2016, 02:53 PM
|
#10
|
Senior Member
Registered: Feb 2003
Distribution: debian
Posts: 4,137
|
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.
|
10-28-2016, 04:29 PM
|
#11
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
Quote:
Originally Posted by rtmistler
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.
|
10-28-2016, 09:18 PM
|
#12
|
LQ Newbie
Registered: Oct 2016
Posts: 3
Original Poster
Rep: 
|
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.
|
|
|
10-28-2016, 09:22 PM
|
#13
|
LQ Newbie
Registered: Oct 2016
Posts: 3
Original Poster
Rep: 
|
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
|
|
|
10-29-2016, 12:04 AM
|
#14
|
Member
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
|
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.
|
|
|
All times are GMT -5. The time now is 11:27 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
|
|