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
drwxrwxr-x 2  mzt root 4096 2013-01-20 08:57 foo

To change the owner to root

chown root

To change the group to root

chgrp root

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

To set exactly read permission for the others,

chmod o=r

To add both write and execute permission for the group,

chmod g+wx

To remove execute permission for everyone,

chmod a-x

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