Guides and tutorials

Hundreds of tutorials and step by step guides carefully written by our support team.

How to change the permissions of a file or directory in Linux

In this manual, we will learn to change the permissions of any file in a GNU/Linux operating system through the command line.

However, before mentioning any type of command, we must learn about the operation of the permissions system in GNU/Linux operating systems. We show it to you:

1. Types of permits

In particular there are three types of permissions that a file or directory in Linux can have assigned.

  • Read permission: allows the user to read the file or, in directories, list the content.
  • Write permission: allows the user to modify the file or, in directories, add files or modify the directory itself.
  • Execute permission: allows to execute files (for example BASH scripts) or, in directories, to have access to it (although it does not necessarily list the content if reading permission is not available).

2. Types of users

The three types of permissions listed below can be activated or deactivated in each file/directory for any of the three types of users mentioned below:

  • Owner: designated as the owner of the file/directory.
  • Group: user group to which the file/directory belongs.
  • Other: any other user of the system.

3. Combinations of permissions and users

As we have explained in the previous section, these three types of users and these three types of permits can be freely assigned.

For example, the owner of the file/directory can have read, write, and execute permissions while other users of the system can only have read permissions. Any combination of these three permits and three users is possible, providing a total of 512 possible combinations.

4. Change permissions of a file or directory

Finally, to assign these permissions we will use the "chmod" command.

Important: To be able to change the permissions of a file or directory you must be an owner or user with administrative privileges. Only the owner or users of type 'root' can change the permissions of a file/directory.

The chmod command has the following syntax: chmod [permission to assign or remove] nombredearchivo

The symbols used to describe a permission are the following:

Permissions: r: reading w: writing x: execution

Users: u: owner g: group or: others a: all of the above

Thus the abbreviation "u+w" would indicate that you want to assign write permission to the owner. Other examples and combinations:

  • or+x (assign the execution permission to "others")
  • a-x (deletes the execution permission to all users)
  • g-w (deletes the execution permission to the members of the group to which the file belongs)
  • u+r (grants read permissions to the owner)

Knowing these abbreviations, we can now use the "chmod" command as follows:

chmod u+x nombredearchivo

This command would grant execution permission to the file "nombredearchivo" to the owner of the file.

Multiple permissions can be granted to multiple users at the same time in this way:

chmod ug+wrx nombredearchivo

This command would grant read, write, and execute permissions (full permissions) to both the owner and the group members to the file " nombredearchivo ".

Finally, it is worth highlighting the usefulness of the "-R" option that applies these permissions recursively to any file that is inside a directory. For example:

chmod -R u+wx nombrededirectorio

This command applies the write and execute permissions for the owner to any file or directory contained within "nombrededirectorio", including files/directories contained in lower levels.

Note: the "chmod" command has a so-called "octal mod" that allows assigning permissions through the use of numbers. This information will be detailed in another user manual.

More than 2000 m² of own facilities and Data Centers in Spain
Your privacy is important for us
We use our own cookies for the proper functioning of the site. In addition, third-party cookies are used for analytical purposes only. This information is not associated with any person so that personal identifying data is not stored, but is only information that is collected to identify the session, with the aim of facilitating the analysis of the website. You can change your preferences at any time by entering this website again. For more information about our cookie policy you can visit our Cookies. You can press the "Accept and close" button to give us your consent or you can access more detailed information and manage cookies.
More than 2000 m² of own facilities and Data Centers in Spain
Your privacy is important for us
We use our own cookies for the proper functioning of the site. In addition, third-party cookies are used for analytical purposes only. This information is not associated with any person so that personal identifying data is not stored, but is only information that is collected to identify the session, with the aim of facilitating the analysis of the website. You can change your preferences at any time by entering this website again. For more information about our cookie policy you can visit our Cookies. You can press the "Accept and close" button to give us your consent or you can access more detailed information and manage cookies.