Thursday, March 31, 2016

How to change file permission in Linux

There are several ways to change the permission of a file in Linux. But I feel following way is more clear and easy.

Let's Consider following file.

-rw-------. 1 udara udara 3066 Mar 25 10:07 settings.xml

After the initial dash,
First 3 places denoted permission for 'user' level
next 3 places denoted permission for 'group' level
last 3 places denoted permission for 'other' level

'r' indicates permission for read
'w' indicates permission for write
'x' indicates permission for execute

So, to change the permission for the file we can use following code syntax.
With the following command we are going to provide execute permission for above file only for 'user' level.

chmod u+x settings.xml  

'u' is for 'user', there can be 'g' (group), 'o' (other)
'+' is to indicate add a permission and '-' is to indicate remove a permission
'x' is for execution permission. There can be r,w,x characters.

-rwx------. 1 udara udara 3066 Mar 25 10:07 settings.xml