Tag Archives: execute

To read about Linux file access permissions please refer our other article here. It will help you understand the Linux files/directories permissions structure.

If you have ownership of a file or directory then you can change access permission of that file for other users. The image given below is showing the permission structure used in Linu.

To change ownership of a file or directory in Linux you have to use chmod command followed by the following attributes.

  • The user for whom you want to change the permission.
  • The type of access permission to add, remove or assign.
  • The list of files and directories for whom you want to change the permissions separated by spaces.

You can change access permission for the users who are in the following categories:

  • the owner of the file (user, u)
  • the group that own the file (group, g)
  • the other users (others, o)

Access permissions refers to read(r),write(w) and execute(x).

As the root user, you can also change the ownership of a file or directory using the chown command.

For example

-rw-r----- 1 jaon users      0 2006-06-23 16:08 checklist.txt
-rw-r--r-- 1 jaon users 53279 2006-06-21 13:16 gnome_quick.xml
-rw-rw---- 1 jaon users 0 2006-06-23 16:08 index.htm
-rw-r--r-- 1 jaon users 70733 2006-06-21 09:35 kde-start.xml
drwxr-xr-x 2 tux users 48 2006-06-23 16:09 local

In the above example, user jaon is the owner of file kde-start.xml and has read, write access to the file but can’t execute it. The users group can read the file and can read this file but can’t write and execute it and the same permissions applied for other users in the next block.

How to modify access permissions for your files?
  • If you want to allow the users group write access to kde-start.xml then use following command:
      chmod g+w kde-start.xml
  • To allow the users group and other users write access to kde-start.xml use following command:
     chmod go+w kde-start.xml
  • To remove write access for all users use this command as follows:
     chmod -w kde-start.xml
  • If you don’t want to allow usersgroup and others to change into the local directory, use following command.
     chmod go-x local
  • To allow write access to other users to two files at same time, use following command:
      chmod o+w  kde_quick.xml gnome_quick.xml

Let’s see the commands used to change ownership of files and directories.

The Root user can change ownership for other user’s data. Login to the server using the root user and its password and run the below command to change the ownership.

chown kristy kde_quick.xml

In above example, we have changed ownership for file kde_quick.xml from user jaon to kristy.

To check if the ownership changed or not, lets list the file using ls -l

ls -l kde_quick.xml
-rw-r--r-- 1 kristy users 47896 2006-06-21 09:46 kde_quick.xml

It is done!