Table of Contents

Linux - chmod - How to set file permissions ?

About

chmod is a core utility that set file permissions.

Both the root user and the file's owner can set file permissions.

chmod has two modes:

The symbolic mode

The symbolic mode is pretty easy to remember. First, you decide if you set permissions for:

Then, you either:

Next, you decide if you set:

Last, you'll tell chmod which file's permissions you want to change.

Examples on the file testfile with the permission -rwxrwxrwx.

Wipe out all the permissions but add read permission for everybody:

$ chmod a=r testfile

After the command, the file's permissions would be -r–r–r–

Add execute permissions for group:

$ chmod g+x testfile

Now, the file's permissions would be -r–r-xr–

Add both write and execute permissions for the file's owner. Note how you can set more than one permission at the same time:

$ chmod u+wx testfile

After this, the file permissions will be -rwxr-xr–

Remove the execute permission from both the file's owner and group. Note, again, how you can set them both at once:

$ chmod ug-x testfile

Now, the permissions are -rw-r–r–

Multiple modification at once

chmod u-x,g+rw,o-r testfile

Recursive

chmod -R o+rw directory