File permissions / access modes

For directories, read permission allows user to list the contents of the directory, write permission allows users to create or remove files / directories inside that directory, and execute permission allows users to change this directory using the cd command or use it as part of a path name.

Changing file permissions:

chmod is the command to change file permissions / directory permissions.

Syntax: $chmod [who] [+/-/=] [permissions] filename

in using, first specify which permissions you are changing, second specify how they should be changed, third specify the file permission type.

  • U for user / owner
  • g for group
  • O for others
  • + for to add permission
  • – for to subtract permission
  • = for to assign permission (i.e add specified permission and take away all other permissions, if present)
  • r for to read
  • w for write
  • x for to execute

example: add write permission to group members on k2schools file

  • $chmod g+w k2schools

example: add execute permission to others and owners on k2schools file

  • $chmod u+x, o+x k2schools (or) $chmod uo+x k2schools

example: assign read permission to others and remove write permission from group members on k2schools file

  • $chmod o+r, g-w k2schools

another form of the chmod command lets you set permissions directly, by using numeric (octal) code to specify them.

This code represents a file’s permissions by tree octal digits; one for owner, permissions, one for group permissions, and one for others. These three digits appear together as one three – digit numbers.

Permission weight
Read 4
Write 2
Execute 1
Read and Write 6
Write and Execute 3
Read and Execute 5
Read, Write and Execute 7
  • Example: $chmod 700 k2schools

The above command sets read, write and execute permissions for owner only and allows no one else to do anything with the file.

  • Example: $chmod 754 k2schools

The above command sets all permissions for user / owner, read and execute for group, and sets read permission for others.

Related Posts

You can leave a response, or trackback from your own site.

Leave a Reply

Powered by k2schools
%d bloggers like this: