Friday, 2 November 2012

File Permissions

File Permissions

Working with files and directories in linux is difficult if you don't know about the file permissions of the linux system. In this post, we will learn about the file permissions and advanced file permissions.

There are three types of file permissions:


To see the, if the directory contains which of the items, we use the command:

# ls directory_name

also to see the file permissions, we use :

# ls -l directory_name

For example:

drwxrwxr-x 3 john john 4096 Oct 20 17:00 Music/

In this case, d stands for directory r stands for Read permission w stands for write permission and x stands for execute permission.

Here three rwx stands for three persons:

first for user, second for group and third for others.

User is one who is John in above example, group is also john, and the permission is applied on directory Music .

The main command for changing the file permissions in redhat is:

# chmod 777 filename

Here permission is 777 in which first 7 for user second 7 for group and last 7 for others.

Now what is the meaning of 7.

At the beginning of the post I write:


for read, 4 for write 2 , for execute 1

means if we want to give full permissions add all the three. 4+2+1=7

If don't want to give write permission then


Similarly different combinations can be made as.

# chmod 751 filename

In this way, we can customize the permissions.

Also, there is another useful permission known as FACL.


Using this tool we can assign special permission to a single user. We can allow or deny users for accessing particular items.

This tool can be used using command:

# getfacl filename

This command shows the special permissions on filename.

To apply permissions, we can use following command:

# setfacl -m u:username:rwx filename

#setfacl -m u:username:r-- filename

To remove these permissions use command:

# setfacl -x u:username:rwx filename

For more information, use mannuals using man command.

No comments:

Post a Comment