Sunday, January 20, 2013

File Permission and Ownership

To show file permission and ownership (owner, group), use

ls -l

For instance,

-rw--w-r-- 1  mzt mzt    37 2013-01-20 08:57 code.py
drwxrwxr-x 2  mzt root 4096 2013-01-20 08:57 foo

To change the owner to root

chown root code.py

To change the group to root

chgrp root code.py

File permissions are given as code r (read), w (write), x (execute), d marks it is a directory. There are three classes of codes per file/directory, respectively they are for owner, group, others.

To add execute permission for the owner,

chmod u+x code.py

To set exactly read permission for the others,

chmod o=r code.py

To add both write and execute permission for the group,

chmod g+wx code.py

To remove execute permission for everyone,

chmod a-x code.py

To recursively apply write permission for both the owner and the group on a folder,

chmod -R ug+w foo

Note that performing these modifications may also affect your right on these commands. A non-root user can't modify a file/directory which belongs to root.

No comments:

Post a Comment