Chmod file permission using bits.

This is the other method of giving file permission using bits.

we are having 3 different roles of symbolic representation.The representation given below:

  • user,
  • group,
  • others.

And the file/directory permissions are :

  • read permission,
  • write permission,
  • execute permission.

Numeric values for the read, write and execute permissions:

  • read 4
  • write 2
  • execute 1

Octal representation for permissions:

  • First number is for user
  • Second number is for group
  • Third number is for others

$ chmod 765 filename

In this example 7 is for user , 6 for group and 5 for others.

For example, give read, write ( 4+2 = 6 ) to user and read ( 4 ) to group and others.

$ chmod 644 filename

The table will help us to understand more about giving permissions.

          4        2           1

Read Write Execute

0       –            –          –

1       –            –          1

2       –            1         –

3       –            1        1

4       1            –         –

5       1            –         1

6       1            1         –

7       1            1         1

Umask

The umask acts as a set of permissions that applications cannot set on files. It’s a file mode creation mask for processes and cannot be set for directories itself. Most applications would not create files with execute permissions set, so they would have a default of 666, which is then modified by the umask.

Default file permission: 666

Default directory permission: 777

So if our umask value is 022, then any new files will, by default, have the permissions 644 (666 – 022). Likewise, any new directories will, by default, be created with the permissions 755 (777 – 022).

You can change the umask value to appropriate value of what you need based upon the above calculation. For example,

$ umask 077

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s