chmod File Permission Unix

chmod File Permission Unix

Linux permission and ownership has inherited from Unix. To assign file permission it provides command chmod that let us set permission who can read, write or execute file.

There are three types of user in Linux:

  • Owner
  • Group
  • World (Everyone)

If you run command ls -l you will see show list of directories and files:

chmod File Permission Unix

The symbol – separate the permission into three types. First part is owner permission second part is group and third is for world (Everyone) and – before rw means its file which can contain any type of data and for directory you see d instead of dash. It can have following values:

  • – (regular file)
  • d (directory)
  • c (character device)
  • l (symlink)
  • p (named pipe)
  • s (socket)
  • b (block device)
  • D (door)

Below is summary of permission:

  • First part can have combination of rwx represents permission of the owner
  • Second part can have combination of rwx represents permission of the group
  • Third part can have combination of rwx represents permission of the world

Practical example: To see how permission works let’s create one sample file name JavaHonk.txt using below command and changes its permission:

$ echo ‘Hello ¬†world!’ >JavaHonk.txt

chmod File Permission Unix

  • As you see above file name: JavaHonk.txt got created with default permission -rw-rw-r– means owner has read/write, group has read/write and world has only read permission. Now change its permission to give owner all permission read/write/execute:

$ chmod 764 JavaHonk.txt : This will give read/write/execute to owner, read/write to group and read to the world.chmod File Permission Unix

Same way you could change permission of the file/directory as an example below:

  • 777 – Read/Write/Execute permission to all
  • 666 – Read/Write permission to all
  • 444 – Read permission to all
  • You could make multiple combination based on number values given above.

For more details please visit this link

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *