[Gambas-user] OT: Linux files question

Rob sourceforge-raindog2 at ...94...
Mon Mar 15 23:59:17 CET 2004


On Monday 15 March 2004 16:47, ron wrote:
> > chmod a+x will accomplish what you meant to do, should be a
> This is the same as chmod 666 file_to_set ?

No, quite different.  chmod 666 filename blows away all the 
permissions on the file, and replaces them with this: rw-rw-rw- 
meaning it's more like a-x.  But not the same, because a+x and 
a-x only touch the x bit, leaving r and w as they were.

chmod seems like magic to a lot of people, so here's a nutshell 
explanation of the numeric vs. the symbolic modes of chmod:

You have three types of user (user, group and other) and three 
types of permission (read, write, and x for execute.)  There are 
other kinds of permission but forget about those for now.  You 
can add or remove permissions by using the first letter of the 
type of user and the first letter of the type of permission, 
with a plus or minus:

o-r turns off read permission for others.
ug+x turns on execute permission for everyone BUT others.
ugo+rwx is equivalent to chmod 777 filename.

That 777 thing is the numeric mode of chmod, and each digit 
refers to a set of permissions: first digit being user, second 
being group, third being other.  You make the digits by adding 
together the read, write and execute bits like so: read is 4, 
write is 2, and execute is 1.  It's called an "octal number" 
because each digit can only be 0 through 7, but just thinking of 
it as three separate digits jammed together and your head will 
hurt less.

However, if you use the numeric mode, it will always get rid of 
whatever permissions a file has and replace them with those 
specified by your number.  Like so:

a file that's rw-rw-rw- (666) and you set it to 700 becomes: 
rwx------.
a file that's rw------- (400) and you make it 777 becomes: 
rwxrwxrwx.
a file that's rwxr-xr-x (755, what you would typically want a 
shell script or gambas executable to be) and you make it 000 
becomes ---------.  Oops!  Now you can't write to it until you 
chmod it again.

People who have a tough time wrapping their brains around the 
octal permissions should just avoid them and use the symbolic 
ones, and even more advanced users will use the symbolic modes 
when, for example, we want to make all the directories in a tree 
executable but none of the files (chmod -R a+X dirname.)

Rob





More information about the User mailing list