Post navigation

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:

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:

1

2

3

4read(r)

2write(w)

1execute(x)

1

2

3

4

5

6

7

7=4+2+1(read/write/execute)

6=4+2(read/write)

5=4+1(read/execute)

4=4(read)

3=2+1(write/execute)

2=2(write)

1=1(execute)

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

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.

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.