Linux File Permissions Examples

By | February 10, 2011

This tutorial is meant for beginners. In my last post I wrote about linux file permissions and now its time to work with some examples. You can check this file permission tutorial to get a better idea. These commands work perfectly file if the user doesn’t use sudo. The results might vary based on the sudo usage.

Let’s start with a most basic and most widely used example if you are a programmer. Most programmers have to specify the executable permissions to any scripts they write. This can be done like this.
chmod u+x script.sh

The above command gives executable permissions to script.sh. You can do this if you wish to give permissions to the group along with you.
chmod ug+x script.sh

To give only read and executable permissions to the group, you can do this. This is most often used when you don’t want your users to edit your file.
chmod g+rx script.sh

Giving read and write permissions to every body (user, group and others). Do it as a root.
chmod ugo+rwx script.sh
or
chmod 777 script.sh

Giving only read permission to the group and others along with read, write and executable permissions to the user.
chmod 744 script.sh

To block the group users and others from reading, writing and executing you can do this…
chmod 700 script.sh

If you like this article, then please consider sharing it. Sharing really inspires us to do things much better!!

Leave a Reply

Your email address will not be published. Required fields are marked *