Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am reading The Linux Command Line by William Shotts and I read somewhere in the book a part regarding permissions which says The operation may be a “+” indicating that a permission is to be added, a “-” indicating that a permission is to be taken away, *or a “=” indicating that only the specified permissions are to be applied and that all others are to be removed*.(see the part between **)

So I tried it:

me@ubuntu:~$ > foo
me@ubuntu:~$ ls -al | grep foo
-rw-rw-r--  1 me me     0 Apr  2 05:17 foo
me@ubuntu:~$ chmod g=x foo 
me@ubuntu:~$ ls -al | grep foo
-rw---xr--  1 me me     0 Apr  2 05:17 foo
iuliu@ubuntu:~$ 

Now the file is created with -rw-rw-r-- rights assigned and after I execute chmod g=x foo I expect them to be ------x--- (only the group to have execution rights and nothing more). I understand that to have execution permission you have to have read permission, so the read permission for the group is needed, but why does the user permissions are still rw?

Thanks!

share|improve this question
1  
ls -al | grep foo??? Why don’t you just say ls -l foo? –  Scott Apr 2 '13 at 4:10
    
+1 Didn't know about that, thanks! –  John Smith Apr 2 '13 at 4:24
add comment

2 Answers

up vote 1 down vote accepted

To build upon and/or clarify Davidw’s answer:  Since you’re saying g=, you are asking for only the group permissions to be changed.  If you would say chmod =x foo, you would get ---x--x--x.  If you want to get ------x---, do

chmod =,g=x foo

This is the same as

chmod  =  foo
chmod g=x foo

The first command sets the permissions to 0 (----------), because it sets all three user groups (u, g, and o) to no access, and I guess by now you understand what the second one does.  As indicated, you can concatenate operations by separating them with commas.

I understand that to have execution permission you have to have read permission, so the read permission for the group is needed, …

This is true only if you’re talking about a script.  A (compiled) binary executable can be run with only execute permission.

share|improve this answer
add comment

g=x adds the execute permission to the group, without changing the other permissions. It only affects the specified portion of the permissions, when you choose a specific part of the permissions. If you use chmod with the numbers, for example, chmod 777, that will overwrite all of the current permissions.

share|improve this answer
    
Yes, 777 overwrites all the current permissions because it explicitly sets all permissions. But what I'm doing here its leaving some of the permissions untouched (e.g. user permissions). According to the text, it should set these permissions to 0 because all others (i.e. permissions) are to be removed. Isn't this true? –  John Smith Apr 2 '13 at 4:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.