Thursday, March 18, 2004

CHANGING FILE PERMISSIONS


Changing the permissions can be done with names and numbers, I like the numbers:
( do you remember the chmod 755 command from a few posts ago ? )

CODE
# chmod 754 tessst.txt

( Will put the file tessst.txt to rwx r-x r-- )

Here is why:
4=read 2=write 1=execute.
The three numbers in the chmod above are for the "user" ( the first number ), "group" ( the second number ) and "others" ( the third number )

So if I want to give the user all permissions: 4+2+1=7
and i give the group read an execute permissions: 4+1=5
and all others only read permission 4=4



Chown and chgrp are two commands also related to permissions:

CODE
# chown

( Changes the owner of the file. )

CODE
# chown anna tessst.txt

( Changes the owner of the file tessst.txt from bruno to anna )



CODE
# chgrp

( Changes the group the file belongs to - if you did change the user and the user belongs to another group )



CODE
# chown -R anna:anna docs

( Changes the user and group ownership of the "docs" directory and all the files in it because of the -R argument ).

QUOTE chmod takes either the decimal representation of the permissions or a symbolic representation. The symbolic representation is [ugoa][+-][rwx]. This is one of the letters u (user=file owner), g (group), o(others), a(all=u and g and o) followed by + or - to add or remove permissions and then the symbolic representation of the permissions in the form of r(read) w(write) x(execute). To make the file "file.txt" writable for all you type: "chmod a+w file.txt"